Skip to content

Commit

Permalink
Various changes
Browse files Browse the repository at this point in the history
Add conversion functions for Vector2 and Vector3
Prevent if_handler from dying
Remove fmt library, use std instead
Do some sophisticated brackets handling in text processors
  • Loading branch information
MunWolf committed Nov 24, 2023
1 parent d192e4c commit 947d22d
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 51 deletions.
35 changes: 18 additions & 17 deletions projects/Core/messages/message_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,18 @@ namespace core::messages {
cursor_position.y -= data.info.margins.x;
cursor_position.y -= data.info.padding.x;

auto target_position = cursor_position;

// When this message is queued, stall it on the pickup position
if (data.handle->state == MessageHandle::MessageState::Queued && data.info.pickup_position.has_value()) {
target_position = world_to_ui_position(data.info.pickup_position.value());
target_position = UnityEngine::Vector3::op_Subtraction(
target_position,
get_screen_position(m_screen_position.get().value_or(core::api::messages::ScreenPosition::TopCenter))
);
}

// Animate message box movement if the message is visible
if (data.handle->state == MessageHandle::MessageState::Visible) {
// When this message is queued, stall it on the pickup position
data.message->position().set(
modloader::math::lerp(
data.message->position().get(),
target_position,
delta_time * 15.f * std::min(1.f, data.handle->active_time * 2.0f + 0.1f)
)
modloader::math::lerp(
data.message->position().get(),
cursor_position,
delta_time * 15.f * std::min(1.f, data.handle->active_time * 2.0f + 0.1f)
)
);
} else {
data.message->position().set(target_position);
data.message->position().set(cursor_position);
}

// Add message box height and bottom padding/margin
Expand Down Expand Up @@ -241,6 +231,17 @@ namespace core::messages {
data.message->screen_position().set(m_screen_position.get());

update_message_position(data, total_lines, position, 0.f);
if (data.info.pickup_position.has_value()) {
const auto top_center = modloader::math::convert(api::messages::get_screen_position(api::messages::ScreenPosition::TopCenter));
const auto pickup_positon = data.info.pickup_position.value();
const auto message_position = data.message->position().get();
const auto pickup_ui_position = world_to_ui_position_2d(modloader::math::convert(pickup_positon)) - top_center;
//pickup_ui_position.y = -pickup_ui_position.y;
const auto distance_squared = modloader::math::distance2(pickup_ui_position, modloader::math::convert(message_position));
if (distance_squared < 25) {
data.message->position().set(modloader::math::convert(pickup_ui_position));
}
}

if (!data.info.text.get().empty()) {
data.message->show(false, data.info.play_sound);
Expand Down
8 changes: 8 additions & 0 deletions projects/Modloader/il2cpp_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,12 @@ namespace modloader::math {
inline float lerp(float a, float b, float weight) {
return a * (1 - weight) + b * weight;
}

inline app::Vector2 convert(app::Vector3 const& vec) {
return app::Vector2{ vec.x, vec.y };
}

inline app::Vector3 convert(app::Vector2 const& vec) {
return app::Vector3{ vec.x, vec.y, 0 };
}
} // namespace modloader::math
35 changes: 17 additions & 18 deletions projects/Randomizer/seed/legacy_parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <Modloader/modloader.h>
#include <seed/items/input.h>

#include <cmath>
#include <fstream>
#include <magic_enum.hpp>
#include <regex>
Expand Down Expand Up @@ -186,7 +185,7 @@ namespace randomizer::seed::legacy_parser {
currency = core::text::get_random_text_with_hash(*static_text_entry::Currency, slug_hash ^ location_hash);
}

const auto text = fmt::format("{} {}", spirit_light, currency);
const auto text = std::format("{} {}", spirit_light, currency);
const auto message = std::make_shared<items::Message>();
set_location(message.get(), location);
message->should_save_as_last = true;
Expand Down Expand Up @@ -304,8 +303,8 @@ namespace randomizer::seed::legacy_parser {
set_location(message.get(), location);
message->should_save_as_last = true;
const auto text = should_add
? fmt::format("[ability({0})]", ability_type_int)
: fmt::format("Removed [ability({0})]", ability_type_int);
? std::format("[ability({0})]", ability_type_int)
: std::format("Removed [ability({0})]", ability_type_int);
message->info.text = text;
data.add_item(message);
data.location_data.icons.emplace_back().assign(app::WorldMapIconType__Enum::AbilityPedestal);
Expand Down Expand Up @@ -339,8 +338,8 @@ namespace randomizer::seed::legacy_parser {
set_location(message.get(), location);
message->should_save_as_last = true;
const auto text = should_add
? fmt::format("[shard({0})]", shard_type_int)
: fmt::format("Removed [shard({0})]", shard_type_int);
? std::format("[shard({0})]", shard_type_int)
: std::format("Removed [shard({0})]", shard_type_int);
message->info.text = text;
data.add_item(message);
data.location_data.icons.emplace_back().assign(app::WorldMapIconType__Enum::AbilityPedestal);
Expand Down Expand Up @@ -870,9 +869,9 @@ namespace randomizer::seed::legacy_parser {
set_location(message.get(), location);
message->should_save_as_last = true;
const auto text = should_add
? fmt::format("{0} TP", teleporter_name)
: fmt::format("Removed {0} TP", teleporter_name);
message->info.text = fmt::format("#{0}#", text);
? std::format("{0} TP", teleporter_name)
: std::format("Removed {0} TP", teleporter_name);
message->info.text = std::format("#{0}#", text);
data.add_item(message);
data.location_data.icons.emplace_back().assign(app::WorldMapIconType__Enum::SavePedestal);
data.location_data.names.emplace_back().assign(text);
Expand Down Expand Up @@ -1064,13 +1063,13 @@ namespace randomizer::seed::legacy_parser {

auto quest_event = "Clean Water";
const auto text = should_add
? fmt::format("{0}", quest_event)
: fmt::format("Removed {0}", quest_event);
? std::format("{0}", quest_event)
: std::format("Removed {0}", quest_event);

const auto message = std::make_shared<items::Message>();
set_location(message.get(), location);
message->should_save_as_last = true;
message->info.text = fmt::format("*{0}*", text);
message->info.text = std::format("*{0}*", text);
data.add_item(message);

data.location_data.icons.emplace_back().assign(app::WorldMapIconType__Enum::QuestEnd);
Expand All @@ -1092,16 +1091,16 @@ namespace randomizer::seed::legacy_parser {
std::string bonus_item;
switch (bonus_type_int) {
case 30:
bonus_item = "#Health Regeneration#";
bonus_item = "Health Regeneration";
break;
case 31:
bonus_item = "#Energy Regeneration#";
bonus_item = "Energy Regeneration";
break;
case 35:
bonus_item = "#Extra Double Jump#";
bonus_item = "Extra Double Jump";
break;
case 36:
bonus_item = "#Extra Air Dash#";
bonus_item = "Extra Air Dash";
break;
default:
return false;
Expand All @@ -1119,7 +1118,7 @@ namespace randomizer::seed::legacy_parser {
const auto message = std::make_shared<items::Message>();
set_location(message.get(), location);
message->should_save_as_last = true;
message->info.text = fmt::format(R"(#{0}[if([state_int(4, {1})] > 1, x[state_int(4, {1})],)]#)", bonus_item, bonus_type_int);
message->info.text = std::format(R"(#{0}[if([state_int(4|{1})] > 1,<> x[state_int(4|{1})],)]#)", bonus_item, bonus_type_int);
data.add_item(message);

data.location_data.icons.emplace_back().assign(app::WorldMapIconType__Enum::Seed);
Expand Down Expand Up @@ -1316,7 +1315,7 @@ namespace randomizer::seed::legacy_parser {
case 2: {
const auto message = std::make_shared<items::Message>();
message->should_save_as_last = true;
message->info.text = std::string("[state_int(6, 2)]/[seed(pickup_count)]");
message->info.text = std::string("[state_int(6|2)]/[seed(pickup_count)]");
data.add_item(message);
data.location_data.names.emplace_back() = core::wrap_readonly<std::string>(message->info.text);
break;
Expand Down
8 changes: 7 additions & 1 deletion projects/Randomizer/text_processors/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
#include <text_processors/control.h>
#include <text_processors/helpers.h>

#include <array>

namespace randomizer::text_processors {
namespace {
std::optional<std::string> if_handler(core::text::ITextProcessor const& base_processor, std::string_view content) {
std::vector<std::string> parts;
split_str(content, parts, ',');
std::array brackets{ std::make_pair('[', ']') };
split_str(content, parts, brackets, ',');
if (parts.size() != 3) {
return std::nullopt;
}

auto condition = trim(parts[0]);
auto result = common::parse_operator(condition);
Expand Down
99 changes: 84 additions & 15 deletions projects/Randomizer/uber_states/uber_state_initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ namespace randomizer {
add_state<app::SerializedBooleanUberState>(UberStateGroup::GromShop, "openCavePlayCutscene", 16588, false),
add_state<app::SerializedBooleanUberState>(UberStateGroup::GromShop, "beautifyPlayCutscene", 15070, false),

add_state<app::SerializedBooleanUberState>(UberStateGroup::TuleyShop, "bashPlants", 47651, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::TuleyShop, "flowers", 16254, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::TuleyShop, "grapplePlants", 33011, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::TuleyShop, "grass", 64583, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::TuleyShop, "springPlants", 38393, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::TuleyShop, "tree", 40006, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::GladesProjects, "bashPlantsPlanted", 47651, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::GladesProjects, "flowersPlanted", 16254, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::GladesProjects, "grapplePlantsPlanted", 33011, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::GladesProjects, "grassPlanted", 64583, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::GladesProjects, "springPlantsPlanted", 38393, 0),
add_state<app::SerializedBooleanUberState>(UberStateGroup::GladesProjects, "treePlanted", 40006, 0),

add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "bashPlantsCost", 47652, 0),
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "flowersCost", 16255, 0),
Expand All @@ -217,6 +217,13 @@ namespace randomizer {
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "springPlantsCost", 38394, 0),
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "treeCost", 40007, 0),

add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "bashPlantsPlayCutscene", 47653, 0),
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "flowersPlayCutscene", 16256, 0),
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "grapplePlantsPlayCutscene", 33013, 0),
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "grassPlayCutscene", 64585, 0),
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "springPlantsPlayCutscene", 38395, 0),
add_state<app::SerializedIntUberState>(UberStateGroup::TuleyShop, "treePlayCutscene", 40008, 0),

add_state<app::SerializedFloatUberState>(UberStateGroup::RandoUpgrade, "hammerSpeedMultiplier", 0, 1),
add_state<app::SerializedFloatUberState>(UberStateGroup::RandoUpgrade, "swordSpeedMultiplier", 1, 1),
add_state<app::SerializedFloatUberState>(UberStateGroup::RandoUpgrade, "blazeCostMultiplier", 2, 1),
Expand Down Expand Up @@ -555,19 +562,19 @@ namespace randomizer {
const int game_modes_float_count = 5;
for (int i = 0; i < game_modes_int_count; ++i) {
states.push_back(
add_state<app::SerializedIntUberState>(UberStateGroup::RandoGameModes, fmt::format("{:04d}_int", i), game_modes_int_start + i, 0)
add_state<app::SerializedIntUberState>(UberStateGroup::RandoGameModes, std::format("{:04d}_int", i), game_modes_int_start + i, 0)
);
}

for (int i = 0; i < game_modes_bool_count; ++i) {
states.push_back(
add_state<app::SerializedBooleanUberState>(UberStateGroup::RandoGameModes, fmt::format("{:04d}_bool", i), game_modes_bool_start + i, false)
add_state<app::SerializedBooleanUberState>(UberStateGroup::RandoGameModes, std::format("{:04d}_bool", i), game_modes_bool_start + i, false)
);
}

for (int i = 0; i < game_modes_float_count; ++i) {
states.push_back(
add_state<app::SerializedFloatUberState>(UberStateGroup::RandoGameModes, fmt::format("{:04d}_float", i), game_modes_float_start + i, false)
add_state<app::SerializedFloatUberState>(UberStateGroup::RandoGameModes, std::format("{:04d}_float", i), game_modes_float_start + i, false)
);
}

Expand All @@ -580,19 +587,19 @@ namespace randomizer {
const int plando_float_count = 25;
for (int i = 0; i < plando_int_count; ++i) {
states.push_back(
add_state<app::SerializedIntUberState>(UberStateGroup::PlandoVars, fmt::format("{:04d}_int", plando_int_start + i), plando_int_start + i, 0)
add_state<app::SerializedIntUberState>(UberStateGroup::PlandoVars, std::format("{:04d}_int", plando_int_start + i), plando_int_start + i, 0)
);
}

for (int i = 0; i < plando_bool_count; ++i) {
states.push_back(
add_state<app::SerializedBooleanUberState>(UberStateGroup::PlandoVars, fmt::format("{:04d}_bool", plando_bool_start + i), plando_bool_start + i, false)
add_state<app::SerializedBooleanUberState>(UberStateGroup::PlandoVars, std::format("{:04d}_bool", plando_bool_start + i), plando_bool_start + i, false)
);
}

for (int i = 0; i < plando_float_count; ++i) {
states.push_back(
add_state<app::SerializedFloatUberState>(UberStateGroup::PlandoVars, fmt::format("{:04d}_float", plando_float_start + i), plando_float_start + i, false)
add_state<app::SerializedFloatUberState>(UberStateGroup::PlandoVars, std::format("{:04d}_float", plando_float_start + i), plando_float_start + i, false)
);
}

Expand All @@ -602,19 +609,19 @@ namespace randomizer {
const int appliers_group_count = 50;
for (int i = 0; i < appliers_group_count; ++i) {
states.push_back(
add_state<app::SerializedIntUberState>(UberStateGroup::Appliers, fmt::format("{:04d}_id", i * 2), i * 2, 0)
add_state<app::SerializedIntUberState>(UberStateGroup::Appliers, std::format("{:04d}_id", i * 2), i * 2, 0)
);

states.push_back(
add_state<app::SerializedIntUberState>(UberStateGroup::Appliers, fmt::format("{:04d}_value", i * 2 + 1), i * 2 + 1, 0)
add_state<app::SerializedIntUberState>(UberStateGroup::Appliers, std::format("{:04d}_value", i * 2 + 1), i * 2 + 1, 0)
);
}

dev::print_time(start_time, "Built custom state list");

for (int i = 0; i < 2000; ++i) {
states.push_back(
add_state<app::SerializedBooleanUberState>(UberStateGroup::MultiVars, fmt::format("{}_multi", i), i, false)
add_state<app::SerializedBooleanUberState>(UberStateGroup::MultiVars, std::format("{}_multi", i), i, false)
);
}

Expand Down Expand Up @@ -883,6 +890,68 @@ namespace randomizer {
})
);

// Tuley shop states
register_virtual_state(
std::make_pair(UberStateGroup::TuleyShop, 47651),
"bashPlantsPlanted",
core::DynamicValue<double>(core::set_get<double>{
[](double x) { UberState(42178, 15068).set(x > 0.5 ? 1 : 3); },
[]() -> double {
return UberState(42178, 15068).get<int>() >= 3 ? 1 : 0;
}
})
);
register_virtual_state(
std::make_pair(UberStateGroup::TuleyShop, 16254),
"flowersPlanted",
core::DynamicValue<double>(core::set_get<double>{
[](double x) { UberState(42178, 15068).set(x > 0.5 ? 1 : 3); },
[]() -> double {
return UberState(42178, 15068).get<int>() >= 3 ? 1 : 0;
}
})
);
register_virtual_state(
std::make_pair(UberStateGroup::TuleyShop, 33011),
"grapplePlantsPlanted",
core::DynamicValue<double>(core::set_get<double>{
[](double x) { UberState(42178, 15068).set(x > 0.5 ? 1 : 3); },
[]() -> double {
return UberState(42178, 15068).get<int>() >= 3 ? 1 : 0;
}
})
);
register_virtual_state(
std::make_pair(UberStateGroup::TuleyShop, 64583),
"grassPlanted",
core::DynamicValue<double>(core::set_get<double>{
[](double x) { UberState(42178, 15068).set(x > 0.5 ? 1 : 3); },
[]() -> double {
return UberState(42178, 15068).get<int>() >= 3 ? 1 : 0;
}
})
);
register_virtual_state(
std::make_pair(UberStateGroup::TuleyShop, 38393),
"springPlantsPlanted",
core::DynamicValue<double>(core::set_get<double>{
[](double x) { UberState(42178, 15068).set(x > 0.5 ? 1 : 3); },
[]() -> double {
return UberState(42178, 15068).get<int>() >= 3 ? 1 : 0;
}
})
);
register_virtual_state(
std::make_pair(UberStateGroup::TuleyShop, 40006),
"treePlanted",
core::DynamicValue<double>(core::set_get<double>{
[](double x) { UberState(42178, 15068).set(x > 0.5 ? 1 : 3); },
[]() -> double {
return UberState(42178, 15068).get<int>() >= 3 ? 1 : 0;
}
})
);

dev::print_time(start_time, "Virtual states initialized");

dev::print_time(start_time, "Uber states initialized");
Expand Down

0 comments on commit 947d22d

Please sign in to comment.