Skip to content

Commit

Permalink
Added relic handling
Browse files Browse the repository at this point in the history
Message infos now take a DynamicValue for their text entry
Reposition the map message
Fix some issues with goal interpolation
Fix relic strings not being parsed and passed around correctly
  • Loading branch information
MunWolf committed Nov 22, 2023
1 parent 2d28fe6 commit 32ffd7e
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 139 deletions.
9 changes: 4 additions & 5 deletions projects/Core/dev/status_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ namespace core::dev {

void StatusDisplay::report(StatusType type, std::string const& message, float duration) {
// Need to hold all the sync handles so we can check what the worst condition is.
auto const& entry = m_config.entries[type];
messages::MessageInfo info{
.text = fmt::format(fmt::runtime(entry.format), message),
const auto& [format, size, play_sound] = m_config.entries[type];
const messages::MessageInfo info{
.text = fmt::format("<s_{:.3}>{}</>", size, fmt::format(fmt::runtime(format), message)),
.duration = duration,
.show_box = false,
.play_sound = entry.play_sound,
.play_sound = play_sound,
.margins = m_config.margins,
.padding = m_config.padding,
};

info.text = fmt::format("<s_{:.3}>{}</>", entry.size, info.text);
m_display.push(info);
}

Expand Down
2 changes: 1 addition & 1 deletion projects/Core/dynamic_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace core {
template <typename To, typename From, bool FromCanSet>
ReadonlyDynamicValue<To> wrap_readonly(dynamic_value::DynamicValue<From, FromCanSet, true> value) {
return ReadonlyDynamicValue<To>(typename ReadonlyDynamicValue<To>::value_type(
[&value]() { return static_cast<To>(value.get()); }
[value]() { return static_cast<To>(value.get()); }
));
}

Expand Down
2 changes: 1 addition & 1 deletion projects/Core/dynamic_value/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace core::dynamic_value {
[[nodiscard]] std::string get() const
requires(CanGet);

void set(std::string value)
void set(std::string v)
requires(CanSet);

value_type value;
Expand Down
2 changes: 1 addition & 1 deletion projects/Core/messages/message_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace core::messages {
m_central_display.push(m_saved_message.value());
} else {
m_central_display.push({
.text = "No pickups collected yet, good Luck!",
.text = std::string("No pickups collected yet, good Luck!"),
.duration = 5.f,
.prioritized = true,
});
Expand Down
16 changes: 9 additions & 7 deletions projects/Core/messages/message_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ namespace core::messages {
const auto max_line_count = m_max_line_count.get();
while (!m_messages.empty()) {
auto& data = m_messages.front();
const auto message_lines = static_cast<int>(std::count(data.info.text.begin(), data.info.text.end(), '\n') + 1);
const auto text = data.info.text.get();
const auto message_lines = static_cast<int>(std::ranges::count(text, '\n') + 1);
// Keep ourselves below the line count limit except if we are showing no messages.
// If we get a message that exceeds the line count we still show it.
if (max_line_count.has_value() && total_lines != 0 && total_lines + message_lines > max_line_count.value()) {
Expand Down Expand Up @@ -176,7 +177,8 @@ namespace core::messages {
}

void MessageDisplay::update_message_position(MessageData& data, int& total_lines, app::Vector3& cursor_position, float delta_time) {
const auto message_lines = static_cast<int>(std::count(data.info.text.begin(), data.info.text.end(), '\n') + 1);
const auto text = data.info.text.get();
const auto message_lines = static_cast<int>(std::ranges::count(text, '\n') + 1);
auto display_message_in_game_world = false;

if (data.info.use_world_space) {
Expand All @@ -193,7 +195,7 @@ namespace core::messages {
target_position = world_to_ui_position(data.info.pickup_position.value());
target_position = UnityEngine::Vector3::op_Subtraction(
target_position,
core::api::messages::get_screen_position(m_screen_position.get().value_or(core::api::messages::ScreenPosition::TopCenter))
get_screen_position(m_screen_position.get().value_or(core::api::messages::ScreenPosition::TopCenter))
);
}

Expand All @@ -211,8 +213,8 @@ namespace core::messages {
}

// Add message box height and bottom padding/margin
const auto bounds = data.message->text_bounds();
cursor_position.y += bounds.m_Height;
const auto [m_XMin, m_YMin, m_Width, m_Height] = data.message->text_bounds();
cursor_position.y += m_Height;
cursor_position.y -= data.info.margins.y;
cursor_position.y -= data.info.padding.z;

Expand All @@ -227,8 +229,8 @@ namespace core::messages {
) {
data.message = std::make_shared<api::messages::MessageBox>();
data.message->show_box(data.info.show_box);
data.message->text() = data.info.text;
data.message->text().text_processor(m_text_processor);
data.message->text().set(data.info.text);
data.message->top_padding().set(data.info.padding.x);
data.message->left_padding().set(data.info.padding.y);
data.message->bottom_padding().set(data.info.padding.z);
Expand All @@ -240,7 +242,7 @@ namespace core::messages {

update_message_position(data, total_lines, position, 0.f);

if (!data.info.text.empty()) {
if (!data.info.text.get().empty()) {
data.message->show(false, data.info.play_sound);
}

Expand Down
4 changes: 2 additions & 2 deletions projects/Core/messages/message_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace core::messages {
struct MessageInfo {
std::string text;
DynamicValue<std::string> text;
float duration = 3.f;
bool show_box = true;
bool instant_fade = false;
Expand Down Expand Up @@ -59,7 +59,7 @@ namespace core::messages {
void update_message_queue(int& total_lines, app::Vector3& cursor_position);
void update_message_position(MessageData& data, int& total_lines, app::Vector3& cursor_position, float delta_time);
bool handle_active_message(MessageData& data, int& total_lines, app::Vector3& cursor_position, float fade_out, float delta_time);
void show_message_box(MessageData& data, int& total_lines, app::Vector3& cursor_position);
void show_message_box(MessageData& data, int& total_lines, app::Vector3& position);

// TODO: Implement this.
const float m_max_length_from_position = 20.f;
Expand Down
2 changes: 2 additions & 0 deletions projects/Randomizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ set(
"seed/items/skip_state.cpp"
"seed/legacy_parser/parser.cpp"
"seed/reach_check.cpp"
"seed/relics.cpp"
"seed/seed.cpp"
"state_data/parser.cpp"
"shrek.cpp"
Expand Down Expand Up @@ -234,6 +235,7 @@ set(
"seed/legacy_parser/parser.h"
"seed/item_data.h"
"seed/reach_check.h"
"seed/relics.h"
"seed/seed.h"
"state_data/state.h"
"state_data/parser.h"
Expand Down
8 changes: 4 additions & 4 deletions projects/Randomizer/features/wheel_initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace randomizer::features::wheel {
features::credits::start();
} else {
core::message_controller().queue_central({
.text = "Credit warp not unlocked!",
.text = std::string("Credit warp not unlocked!"),
.prioritized = true,
});
}
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace randomizer::features::wheel {
[](auto, auto, auto) {
if (game_seed().info().race_mode) {
core::message_controller().queue_central({
.text = "Teleport anywhere is not available in race mode",
.text = std::string("Teleport anywhere is not available in race mode"),
.prioritized = true,
});
return;
Expand All @@ -136,15 +136,15 @@ namespace randomizer::features::wheel {
[](auto, auto, auto) {
if (game_seed().info().race_mode) {
core::message_controller().queue_central({
.text = "Unlock spoilers is not available in race mode",
.text = std::string("Unlock spoilers is not available in race mode"),
.prioritized = true,
});
return;
}

core::api::uber_states::UberState(34543, 11226).set(1);
core::message_controller().queue_central({
.text = "Spoilers unlocked",
.text = std::string("Spoilers unlocked"),
.prioritized = true,
});
});
Expand Down
8 changes: 4 additions & 4 deletions projects/Randomizer/input/action_registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace randomizer::input {
features::credits::start();
} else {
core::message_controller().queue_central({
.text = "Credit warp not unlocked!",
.text = std::string("Credit warp not unlocked!"),
.prioritized = true,
});
}
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace randomizer::input {
auto on_teleport_cheat_before = single_input_bus().register_handler(Action::TeleportCheat, EventTiming::Before, [](auto, auto) {
if (game_seed().info().race_mode) {
core::message_controller().queue_central({
.text = "Teleport anywhere is not available in race mode",
.text = std::string("Teleport anywhere is not available in race mode"),
.prioritized = true,
});
return;
Expand All @@ -114,15 +114,15 @@ namespace randomizer::input {
auto on_unlock_spoilers_before = single_input_bus().register_handler(Action::UnlockSpoilers, EventTiming::Before, [](auto, auto) {
if (game_seed().info().race_mode) {
core::message_controller().queue_central({
.text = "Unlock spoilers is not available in race mode",
.text = std::string("Unlock spoilers is not available in race mode"),
.prioritized = true,
});
return;
}

core::api::uber_states::UberState(34543, 11226).set(1);
core::message_controller().queue_central({
.text = "Spoilers unlocked",
.text = std::string("Spoilers unlocked"),
.prioritized = true,
});
});
Expand Down
22 changes: 22 additions & 0 deletions projects/Randomizer/location_data/location_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,33 @@ namespace randomizer::location_data {
{ "Void", GameArea::Void },
};

std::unordered_map<GameArea, std::string> area_to_short_name_map{
{ GameArea::Marsh, "Marsh" },
{ GameArea::Hollow, "Hollow" },
{ GameArea::Glades, "Glades" },
{ GameArea::Wellspring, "Wellspring" },
{ GameArea::Pools, "Pools" },
{ GameArea::Burrows, "Burrows" },
{ GameArea::Reach, "Reach" },
{ GameArea::Woods, "Woods" },
{ GameArea::Depths, "Depths" },
{ GameArea::Wastes, "Wastes" },
{ GameArea::Ruins, "Ruins" },
{ GameArea::Willow, "Willow" },
{ GameArea::Shop, "Shop" },
{ GameArea::Void, "Void" },
};

const std::string_view area_to_name(GameArea area) {
auto it = area_to_name_map.find(area);
return it != area_to_name_map.end() ? it->second : unknown_area;
}

const std::string_view area_to_short_name(GameArea area) {
auto it = area_to_short_name_map.find(area);
return it != area_to_short_name_map.end() ? it->second : unknown_area;
}

GameArea name_to_area(std::string const& name) {
auto it = name_to_area_map.find(name);
return it != name_to_area_map.end() ? it->second : GameArea::TOTAL;
Expand Down
1 change: 1 addition & 0 deletions projects/Randomizer/location_data/location_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace randomizer::location_data {
const std::string_view area_to_name(GameArea area);
const std::string_view area_to_short_name(GameArea area);
GameArea name_to_area(std::string const& name);

using location_data_emitter = std::function<void(Location location)>;
Expand Down
6 changes: 3 additions & 3 deletions projects/Randomizer/messages/map_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ namespace randomizer::messages {
if (box == nullptr) {
box = std::make_shared<core::api::messages::MessageBox>();
box->position() = app::Vector3{
0, -0.4, 0
0, 0.0, 0
};

box->screen_position() = core::api::messages::ScreenPosition::TopCenter;
box->screen_position() = core::api::messages::ScreenPosition::BottomCenter;
box->alignment() = app::AlignmentMode__Enum::Center;
box->horizontal_anchor() = app::HorizontalAnchorMode__Enum::Center;
box->vertical_anchor() = app::VerticalAnchorMode__Enum::Top;
box->vertical_anchor() = app::VerticalAnchorMode__Enum::Bottom;
box->use_world_coordinates() = false;
box->show_box(false);
box->text().text_processor(general_text_processor());
Expand Down
4 changes: 3 additions & 1 deletion projects/Randomizer/randomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Core/settings.h>

#include <Modloader/modloader.h>
#include <text_processors/seed.h>

#include <fstream>

Expand Down Expand Up @@ -114,7 +115,7 @@ namespace randomizer {
});

core::message_controller().queue_central({
.text = "*Good Luck! <3*",
.text = std::string("*Good Luck! <3*"),
.prioritized = true,
});
});
Expand Down Expand Up @@ -166,6 +167,7 @@ namespace randomizer {
text_processor->compose(std::make_shared<text_processors::ControlProcessor>());
text_processor->compose(std::make_shared<text_processors::AbilityProcessor>());
text_processor->compose(std::make_shared<text_processors::ShardProcessor>());
text_processor->compose(std::make_shared<text_processors::SeedProcessor>());
text_processor->compose(std::make_shared<text_processors::LegacyProcessor>());

core::message_controller().central_display().text_processor(text_processor);
Expand Down
Loading

0 comments on commit 32ffd7e

Please sign in to comment.