Skip to content

Commit

Permalink
Queue reach checks when needed
Browse files Browse the repository at this point in the history
Fix wheel progress button not triggering message (inside rando actions)
  • Loading branch information
MunWolf committed Nov 22, 2023
1 parent b182a39 commit ecdf422
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion projects/Randomizer/features/wheel_initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace randomizer::features::wheel {
initialize_item(9000, 0, "Show last pickup", "Displays the message associated\nwith the last pickup.", "file:assets/icons/wheel/show_last_pickup.blue.png",
[](auto, auto, auto) { core::message_controller().requeue_last_saved(); });
initialize_item(9000, 1, "Show progress, with hints.", "Displays current goal mode progress and bought hints.", "file:assets/icons/wheel/progress_summary.blue.png",
[](auto, auto, auto) { });
[](auto, auto, auto) { game_seed().grant(core::api::uber_states::UberState(UberStateGroup::GameState, 8), 0); });
initialize_item(9000, 2, "Warp to credits", "Warp directly to the credits,\nonly works if you have finished the bingo.", "file:assets/icons/wheel/warp_to_credits.blue.png",
[](auto, auto, auto) {
if (core::api::uber_states::UberState().get<bool>()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Common/ext.h>
#include <randomizer.h>

#include <Core/api/uber_states/uber_state.h>

Expand Down Expand Up @@ -49,6 +50,7 @@ namespace {
auto it = tps_by_position.find(std::make_pair(static_cast<int>(position.x), static_cast<int>(position.y)));
if (it != tps_by_position.end()) {
it->second.set<bool>(true);
randomizer::queue_reach_check();
}
}

Expand Down
4 changes: 4 additions & 0 deletions projects/Randomizer/seed/seed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ namespace randomizer::seed {
break;
}
}

if (!to_grant.empty()) {
queue_reach_check();
}
}

void Seed::call_procedure(int id) {
Expand Down
19 changes: 12 additions & 7 deletions projects/Randomizer/uber_states/trigger_reach_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace randomizer::uber_states {

std::unordered_set<UberState> tracked_states;

auto on_after_respawn = core::api::game::event_bus().register_handler(
GameEvent::Respawn, EventTiming::After, [](auto, auto) { queue_reach_check(); });
auto on_after_checkpoint_loaded = core::api::game::event_bus().register_handler(
GameEvent::FinishedLoadingCheckpoint, EventTiming::After, [](auto, auto) { queue_reach_check(); });
auto on_after_save_loaded = core::api::game::event_bus().register_handler(
GameEvent::FinishedLoadingSave, EventTiming::After, [](auto, auto) { queue_reach_check(); });

auto on_uber_state = notification_bus().register_handler([](auto params) {
if (tracked_states.contains(params.state)) {
queue_reach_check();
Expand All @@ -21,22 +28,20 @@ namespace randomizer::uber_states {
auto on_game_ready = modloader::event_bus().register_handler(ModloaderEvent::GameReady, [](auto) {
std::ifstream state_data(modloader::base_path() / "state_data.csv");
std::string line;
std::getline(state_data, line);
while (std::getline(state_data, line)) {
std::vector<std::string> parts;
split_str(line, parts, ',');
for (auto& str : parts) {
trim(str);
}

auto& condition_part = parts[2];
if (parts.size() >= 4) {
condition_part += ">=";
condition_part += parts[3].empty() ? "0" : parts[3];
int group, state;
if (!string_convert(parts[1], group) || !string_convert(parts[2], state)) {
continue;
}

UberStateCondition condition;
core::api::uber_states::parse_condition(std::span<std::string>(parts.begin() + 1, parts.begin() + 3), condition);
tracked_states.emplace(condition.state);
tracked_states.emplace(UberState(group, state));
}
});
} // namespace
Expand Down

0 comments on commit ecdf422

Please sign in to comment.