Skip to content

Commit

Permalink
feat: multiple maps on category
Browse files Browse the repository at this point in the history
there was a weird git issue with the PR, so i've just remade the commit
credit to @JaioCG 's computer, and @tricksurf
  • Loading branch information
ThisAMJ committed Nov 22, 2023
1 parent 00a7aba commit 91c2f96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/Features/Speedrun/Categories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ ON_EVENT(RENDER) {
for (std::string ruleName : g_categories[g_currentCategory].rules) {
auto rule = SpeedrunTimer::GetRule(ruleName);
if (!rule) continue;
if (rule->map != engine->GetCurrentMapName()) continue;
if (std::find(rule->maps.begin(), rule->maps.end(), engine->GetCurrentMapName()) == rule->maps.end()) continue;
if (std::holds_alternative<ZoneTriggerRule>(rule->rule)) {
std::get<ZoneTriggerRule>(rule->rule).DrawInWorld();
std::get<ZoneTriggerRule>(rule->rule).OverlayInfo(rule);
Expand Down Expand Up @@ -541,7 +541,17 @@ bool SpeedrunTimer::CreateRule(std::string name, std::string type, std::map<std:
}

rule->action = action;
rule->map = params["map"];

std::string mapToken, delimiter = "|";
if (params["map"].find(delimiter) != std::string::npos) {
size_t pos = 0;
while ((pos = params["map"].find(delimiter)) != std::string::npos) {
mapToken = params["map"].substr(0, pos);
rule->maps.push_back(mapToken);
params["map"].erase(0, pos + delimiter.length());
}
}
if (params["map"].length() > 0) rule->maps.push_back(params["map"]);

auto after = lookupMap(params, "after");
if (!after) {
Expand Down
9 changes: 7 additions & 2 deletions src/Features/Speedrun/Rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ bool SpeedrunRule::TestGeneral(std::optional<int> slot) {
auto prereq = SpeedrunTimer::GetRule(*this->onlyAfter);
if (!prereq || !prereq->fired) return false;
}
if (engine->GetCurrentMapName() != this->map) return false;
if (std::find(this->maps.begin(), this->maps.end(), engine->GetCurrentMapName()) == this->maps.end()) return false;
if (this->slot) {
if (this->slot != slot) return false;
}
Expand Down Expand Up @@ -311,7 +311,12 @@ static const char *printRuleAction(RuleAction action) {

std::string SpeedrunRule::Describe() {
std::string s = std::string("action=") + printRuleAction(this->action);
s += " map=" + this->map;
s += " maps=";
for (auto it = this->maps.begin(); it != this->maps.end(); ++it) {
if (it == this->maps.begin()) continue;
s += *it;
if (it + 1 != this->maps.end()) s += ",";
}
if (this->cycle) {
s += Utils::ssprintf(" cycle=%d,%d", this->cycle->first, this->cycle->second);
}
Expand Down
13 changes: 11 additions & 2 deletions src/Features/Speedrun/Rules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct SpeedrunRule {

RuleAction action;

std::string map;
std::vector<std::string> maps;
std::optional<std::string> onlyAfter;
std::optional<int> slot;
std::optional<std::pair<int, int>> cycle;
Expand All @@ -109,7 +109,16 @@ struct SpeedrunRule {

SpeedrunRule(RuleAction action, std::string map, _RuleTypes rule)
: action(action)
, map(map)
, maps({map})
, onlyAfter()
, slot()
, rule(rule)
, fired(false) {
}

SpeedrunRule(RuleAction action, std::vector<std::string> maps, _RuleTypes rule)
: action(action)
, maps(maps)
, onlyAfter()
, slot()
, rule(rule)
Expand Down

0 comments on commit 91c2f96

Please sign in to comment.