Skip to content

Commit

Permalink
added color overriding (close #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinsplash committed Feb 3, 2024
1 parent 81fbbe5 commit cd39805
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ These are the settings that exist:
* **must**: A criteria which is strictly required. Multiple can be defined. All **must** criteria need to be met for an entity to be allowed, even after accounting for **allow** and **disallow**.
* **avoid**: A criteria that cannot be allowed in any circumstance. Multiple can be defined. All **avoid** criteria need to *not* be met for an entity to be allowed, even after accounting for **allow** and **disallow**.
* **min_x**, **max_x**, **min_y**, **max_y**, **min_z**, **max_z**: Coordinate boundaries that an entity's origin must be within. You can find the player's coordinates with `cl_showpos 1`. Not all 6 need to be defined, only the ones you want.
* **color**: If an entity matches this criterion, it will be drawn with the specified color. Ex. `"color" "classname trigger_hurt 255 0 0"` If an entity doesn't have a color defined for it, its color will be based off its position.

Allow and disallow criteria work as follows: A property to select by, and then potentially something that the value of the property must match. A * can be used to limit the filtering to only the characters up until that point in a value's string.

Expand Down
113 changes: 73 additions & 40 deletions planepoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct Settings
std::vector<std::string> disallows;
std::vector<std::string> musts;
std::vector<std::string> avoids;
std::vector<std::string> clrOverrides;
int duration = 60;
bool drawTriggerOutlines = true;
bool drawEntCubes = false;
Expand Down Expand Up @@ -860,49 +861,35 @@ int ReadSettings(std::ifstream& ReadFile, Settings& settings)
}
}
else if (key == "duration")
{
settings.duration = stoi(value);
}

else if (key == "allow" && !settings.defaultAllow)
{
settings.allows.push_back(value);
}

else if (key == "disallow" && settings.defaultAllow)
{
settings.disallows.push_back(value);
}

else if (key == "must")
{
settings.musts.push_back(value);
}

else if (key == "avoid")
{
settings.avoids.push_back(value);
}

else if (key == "color")
settings.clrOverrides.push_back(value);

else if (key == "min_x")
{
settings.min_x = stof(value);
}
else if (key == "max_x")
{
settings.max_x = stof(value);
}
else if (key == "min_y")
{
settings.min_y = stof(value);
}
else if (key == "max_y")
{
settings.max_y = stof(value);
}
else if (key == "min_z")
{
settings.min_z = stof(value);
}
else if (key == "max_z")
{
settings.max_z = stof(value);
}
}
return 1;
}
Expand All @@ -929,17 +916,8 @@ bool StringMatch(std::string strEnt, std::string strSetting)
return false;
}

bool CriteriaMet(std::string& line, Entity& ent)
bool CriteriaMet(std::string& key, std::string& value, Entity& ent)
{
size_t keyStart = line.find('"');
size_t keyEnd = line.find(' ', keyStart + 1);
size_t valueEnd = line.find('"', keyEnd + 1);

keyStart++;
std::string key = line.substr(keyStart, keyEnd - keyStart);
keyEnd++;
std::string value = line.substr(keyEnd, valueEnd - keyEnd);

if (key == "classname")
return StringMatch(ent.classname, value);
else if (key == "editorclass")
Expand Down Expand Up @@ -974,6 +952,23 @@ bool FilterXYZ(Settings& settings, Vector3 origin)
return true;
}

//monstrosity
void ParsePair(std::string& line, std::string& key, std::string& value, char c1, char c2, char c3, std::string* rest = NULL)
{
size_t keyStart = line.find(c1);
size_t keyEnd = line.find(c2, keyStart + 1);
size_t valueEnd = line.find(c3, keyEnd + 1);

keyStart++;
key = line.substr(keyStart, keyEnd - keyStart);

keyEnd++;
value = line.substr(keyEnd, valueEnd - keyEnd);

if (rest != NULL)
*rest = line.substr(valueEnd);
}

bool PassesFilters(Settings& settings, Entity& ent)
{
//filtering
Expand All @@ -985,7 +980,10 @@ bool PassesFilters(Settings& settings, Entity& ent)
{
for (std::string& line : settings.allows)
{
allowed = CriteriaMet(line, ent);
std::string key;
std::string value;
ParsePair(line, key, value, '"', ' ', '"');
allowed = CriteriaMet(key, value, ent);
if (allowed)
break;//found something that allows us, even one thing
}
Expand All @@ -996,7 +994,10 @@ bool PassesFilters(Settings& settings, Entity& ent)
//disallow for whitelist
for (std::string& line : settings.disallows)
{
disallowed = CriteriaMet(line, ent);
std::string key;
std::string value;
ParsePair(line, key, value, '"', ' ', '"');
disallowed = CriteriaMet(key, value, ent);
if (disallowed)
break;
}
Expand All @@ -1006,7 +1007,10 @@ bool PassesFilters(Settings& settings, Entity& ent)
{
for (std::string& line : settings.allows)
{
allowed = CriteriaMet(line, ent);
std::string key;
std::string value;
ParsePair(line, key, value, '"', ' ', '"');
allowed = CriteriaMet(key, value, ent);
if (allowed)
break;
}
Expand All @@ -1026,7 +1030,10 @@ bool PassesFilters(Settings& settings, Entity& ent)
bool goodMusts = true;
for (std::string& line : settings.musts)
{
goodMusts = CriteriaMet(line, ent);
std::string key;
std::string value;
ParsePair(line, key, value, '"', ' ', '"');
goodMusts = CriteriaMet(key, value, ent);
if (!goodMusts)
break;
}
Expand All @@ -1037,7 +1044,10 @@ bool PassesFilters(Settings& settings, Entity& ent)
bool badAvoids = false;
for (std::string& line : settings.avoids)
{
badAvoids = CriteriaMet(line, ent);
std::string key;
std::string value;
ParsePair(line, key, value, '"', ' ', '"');
badAvoids = CriteriaMet(key, value, ent);
if (badAvoids)
break;
}
Expand All @@ -1051,6 +1061,26 @@ bool PassesFilters(Settings& settings, Entity& ent)
return true;
}

bool ColorOverride(Settings& settings, Entity& ent, int* color)
{
for (std::string& line : settings.clrOverrides)
{
std::string key;
std::string value;
std::string rest;
ParsePair(line, key, value, '"', ' ', ' ', &rest);
if (CriteriaMet(key, value, ent))
{
Vector3 vecClr = ParseVector(rest);
color[0] = vecClr.x;
color[1] = vecClr.y;
color[2] = vecClr.z;
return true;
}
}
return false;
}

int main(int argc, char* argv[])
{
bool debug = argc == 1;
Expand Down Expand Up @@ -1097,9 +1127,12 @@ int main(int argc, char* argv[])
continue;

int color[3];
color[0] = BaseColorOffCoord(ent.origin.x);
color[1] = BaseColorOffCoord(ent.origin.y);
color[2] = BaseColorOffCoord(ent.origin.z);
if (!ColorOverride(settings, ent, color))
{
color[0] = BaseColorOffCoord(ent.origin.x);
color[1] = BaseColorOffCoord(ent.origin.y);
color[2] = BaseColorOffCoord(ent.origin.z);
}
if (!ent.spawnclass.empty()) writingFile << "//Spawn Class: " << ent.spawnclass << "\n";
if (!ent.editorclass.empty()) writingFile << "//Editor Class: " << ent.editorclass << "\n";
if (!ent.classname.empty()) writingFile << "//Class Name: " << ent.classname << "\n";
Expand Down
12 changes: 11 additions & 1 deletion settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@
"allow" "classname trigger*"
"allow" "classname func*"
"avoid" "classname trigger_soundscape"
"avoid" "classname trigger_indoor_area"
"avoid" "classname trigger_indoor_area"
"color" "classname trigger_hurt 200 0 0"
"color" "classname trigger_out_of_bounds 200 128 0"
"color" "editorclass trigger_death_fall 200 0 0"
"color" "editorclass trigger_quickdeath 200 0 0"
"color" "editorclass trigger_deadly_fog 200 128 0"
"color" "editorclass trigger_checkpoint 0 0 200"
"color" "editorclass trigger_checkpoint_forced 0 0 200"
"color" "editorclass trigger_checkpoint_safe 0 0 200"
"color" "editorclass trigger_checkpoint_silent 0 0 200"
"color" "editorclass trigger_checkpoint_to_safe_spots 0 0 200"

0 comments on commit cd39805

Please sign in to comment.