diff --git a/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp b/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp index 616ca52e..4166589a 100644 --- a/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp @@ -3,7 +3,10 @@ #include #include +#include + #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" using namespace OpenVic; using namespace godot; @@ -135,22 +138,17 @@ Error GFXButtonStateTexture::generate_state_image( } StringName const& GFXButtonStateTexture::button_state_to_name(ButtonState button_state) { - static const StringName name_hover = "hover"; - static const StringName name_pressed = "pressed"; - static const StringName name_disabled = "disabled"; - static const StringName name_selected = "selected"; - static const StringName name_error = "INVALID BUTTON STATE"; switch (button_state) { case HOVER: - return name_hover; + return OV_SNAME(hover); case PRESSED: - return name_pressed; + return OV_SNAME(pressed); case DISABLED: - return name_disabled; + return OV_SNAME(disabled); case SELECTED: - return name_selected; + return OV_SNAME(selected); default: - return name_error; + unreachable(); } } diff --git a/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp b/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp index 03fc850b..a810e827 100644 --- a/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp +++ b/extension/src/openvic-extension/classes/GFXPieChartTexture.cpp @@ -3,6 +3,7 @@ #include #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/utility/UITools.hpp" using namespace godot; @@ -10,20 +11,16 @@ using namespace OpenVic; using namespace OpenVic::Utilities::literals; StringName const& GFXPieChartTexture::_slice_identifier_key() { - static const StringName slice_identifier_key = "identifier"; - return slice_identifier_key; + return OV_SNAME(identifier); } StringName const& GFXPieChartTexture::_slice_tooltip_key() { - static const StringName slice_tooltip_key = "tooltip"; - return slice_tooltip_key; + return OV_SNAME(tooltip); } StringName const& GFXPieChartTexture::_slice_colour_key() { - static const StringName slice_colour_key = "colour"; - return slice_colour_key; + return OV_SNAME(colour); } StringName const& GFXPieChartTexture::_slice_weight_key() { - static const StringName slice_weight_key = "weight"; - return slice_weight_key; + return OV_SNAME(weight); } GFXPieChartTexture::slice_t const* GFXPieChartTexture::get_slice(Vector2 const& position) const { diff --git a/extension/src/openvic-extension/classes/GUIButton.cpp b/extension/src/openvic-extension/classes/GUIButton.cpp index e674e286..a9230dea 100644 --- a/extension/src/openvic-extension/classes/GUIButton.cpp +++ b/extension/src/openvic-extension/classes/GUIButton.cpp @@ -1,9 +1,8 @@ #include "GUIButton.hpp" -#include - #include +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -33,9 +32,7 @@ Error GUIButton::set_gfx_button_state_having_texture(Ref stylebox = AssetManager::make_stylebox_texture(texture); if (stylebox.is_valid()) { - static const StringName normal_theme = "normal"; - - add_theme_stylebox_override(normal_theme, stylebox); + add_theme_stylebox_override(OV_SNAME(normal), stylebox); } else { UtilityFunctions::push_error("Failed to make StyleBoxTexture for GUIButton ", get_name()); @@ -86,22 +83,24 @@ Error GUIButton::set_gfx_font(GFX::Font const* gfx_font) { const Ref font = asset_manager->get_font(font_file); if (font.is_valid()) { - static const StringName font_theme = "font"; - - add_theme_font_override(font_theme, font); + add_theme_font_override(OV_SNAME(font), font); } else { UtilityFunctions::push_error("Failed to load font \"", font_file, "\" for GUIButton ", get_name()); err = FAILED; } - static const std::array button_font_themes { - "font_color", "font_hover_color", "font_hover_pressed_color", "font_pressed_color", "font_disabled_color" - }; - const Color colour = Utilities::to_godot_color(gfx_font->get_colour()); - for (StringName const& theme_name : button_font_themes) { + for (StringName const& theme_name : + { + OV_SNAME(font_color), // + OV_SNAME(font_hover_color), // + OV_SNAME(font_hover_pressed_color), // + OV_SNAME(font_pressed_color), // + OV_SNAME(font_disabled_color) // + } // + ) { add_theme_color_override(theme_name, colour); } diff --git a/extension/src/openvic-extension/classes/GUIListBox.cpp b/extension/src/openvic-extension/classes/GUIListBox.cpp index 25474804..b555414f 100644 --- a/extension/src/openvic-extension/classes/GUIListBox.cpp +++ b/extension/src/openvic-extension/classes/GUIListBox.cpp @@ -4,6 +4,7 @@ #include #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/utility/UITools.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -11,11 +12,8 @@ using namespace OpenVic; using namespace godot; using namespace OpenVic::Utilities::literals; -/* StringNames cannot be constructed until Godot has called StringName::setup(), - * so we must use wrapper functions to delay their initialisation. */ StringName const& GUIListBox::_signal_scroll_index_changed() { - static const StringName signal_scroll_index_changed = "scroll_index_changed"; - return signal_scroll_index_changed; + return OV_SNAME(scroll_index_changed); } Error GUIListBox::_calculate_max_scroll_index(bool signal) { @@ -285,10 +283,8 @@ Error GUIListBox::set_gui_listbox(GUI::ListBox const* new_gui_listbox) { scrollbar->set_position(position); scrollbar->set_length_override(size.height); - static const StringName set_scroll_index_func_name = "set_scroll_index"; - scrollbar->connect( - GUIScrollbar::signal_value_changed(), Callable { this, set_scroll_index_func_name }, CONNECT_PERSIST + GUIScrollbar::signal_value_changed(), Callable { this, OV_SNAME(set_scroll_index) }, CONNECT_PERSIST ); } else { UtilityFunctions::push_error( diff --git a/extension/src/openvic-extension/classes/GUINode.cpp b/extension/src/openvic-extension/classes/GUINode.cpp index e402c45d..5419779d 100644 --- a/extension/src/openvic-extension/classes/GUINode.cpp +++ b/extension/src/openvic-extension/classes/GUINode.cpp @@ -30,6 +30,7 @@ #include #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/utility/UITools.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -160,21 +161,20 @@ Ref GUINode::get_texture_from_node(Node* node) { ERR_FAIL_NULL_V_MSG(texture, nullptr, Utilities::format("Failed to get Texture2D from TextureRect %s", node->get_name())); return texture; } else if (GUIButton const* button = Object::cast_to(node); button != nullptr) { - static const StringName theme_name_normal = "normal"; - const Ref stylebox = button->get_theme_stylebox(theme_name_normal); + const Ref stylebox = button->get_theme_stylebox(OV_SNAME(normal)); ERR_FAIL_NULL_V_MSG( - stylebox, nullptr, Utilities::format("Failed to get StyleBox %s from GUIButton %s", theme_name_normal, node->get_name()) + stylebox, nullptr, Utilities::format("Failed to get StyleBox %s from GUIButton %s", OV_SNAME(normal), node->get_name()) ); const Ref stylebox_texture = stylebox; ERR_FAIL_NULL_V_MSG( stylebox_texture, nullptr, Utilities::format( - "Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", theme_name_normal, node->get_name() + "Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", OV_SNAME(normal), node->get_name() ) ); const Ref result = stylebox_texture->get_texture(); ERR_FAIL_NULL_V_MSG( result, nullptr, - Utilities::format("Failed to get Texture2D from StyleBoxTexture %s from GUIButton %s", theme_name_normal, node->get_name()) + Utilities::format("Failed to get Texture2D from StyleBoxTexture %s from GUIButton %s", OV_SNAME(normal), node->get_name()) ); return result; } diff --git a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp index df8dc797..dda0a81c 100644 --- a/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp +++ b/extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp @@ -3,6 +3,7 @@ #include #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/utility/UITools.hpp" #include "openvic-extension/utility/Utilities.hpp" #include "openvic-simulation/types/TextFormat.hpp" @@ -121,13 +122,9 @@ Error GUIOverlappingElementsBox::set_child_count(int32_t new_count) { ) ); - static const StringName set_z_index_func_name = "set_z_index"; - static const StringName mouse_entered_signal_name = "mouse_entered"; - static const StringName mouse_exited_signal_name = "mouse_exited"; - /* Move the child element in front of its neighbours when moused-over. */ - child->connect(mouse_entered_signal_name, Callable { child, set_z_index_func_name }.bind(1), CONNECT_PERSIST); - child->connect(mouse_exited_signal_name, Callable { child, set_z_index_func_name }.bind(0), CONNECT_PERSIST); + child->connect(OV_SNAME(mouse_entered), Callable { child, OV_SNAME(set_z_index) }.bind(1), CONNECT_PERSIST); + child->connect(OV_SNAME(mouse_exited), Callable { child, OV_SNAME(set_z_index) }.bind(0), CONNECT_PERSIST); add_child(child); child_count++; diff --git a/extension/src/openvic-extension/classes/GUIScrollbar.cpp b/extension/src/openvic-extension/classes/GUIScrollbar.cpp index 74e13504..6065d931 100644 --- a/extension/src/openvic-extension/classes/GUIScrollbar.cpp +++ b/extension/src/openvic-extension/classes/GUIScrollbar.cpp @@ -13,6 +13,7 @@ #include #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/utility/UITools.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -22,8 +23,7 @@ using namespace godot; /* StringNames cannot be constructed until Godot has called StringName::setup(), * so we must use wrapper functions to delay their initialisation. */ StringName const& GUIScrollbar::signal_value_changed() { - static const StringName signal_value_changed = "value_changed"; - return signal_value_changed; + return OV_SNAME(value_changed); } GUI_TOOLTIP_IMPLEMENTATIONS(GUIScrollbar) diff --git a/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.cpp b/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.cpp index 83f940b7..45ccb973 100644 --- a/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.cpp +++ b/extension/src/openvic-extension/classes/resources/StyleBoxWithSound.cpp @@ -11,6 +11,7 @@ #include #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" using namespace OpenVic; using namespace godot; @@ -40,7 +41,7 @@ void StyleBoxWithSound::_bind_methods() { } StyleBoxWithSound::StyleBoxWithSound() { - audio_bus = "Master"; + audio_bus = OV_SNAME(Master); } Ref StyleBoxWithSound::get_style_box() const { diff --git a/extension/src/openvic-extension/components/budget/AdministrationBudget.cpp b/extension/src/openvic-extension/components/budget/AdministrationBudget.cpp index b9a595ad..95d24879 100644 --- a/extension/src/openvic-extension/components/budget/AdministrationBudget.cpp +++ b/extension/src/openvic-extension/components/budget/AdministrationBudget.cpp @@ -55,7 +55,7 @@ fixed_point_t AdministrationBudget::calculate_budget_and_update_custom( CountryInstance& country, const fixed_point_t scaled_value ) { - static const godot::StringName administrative_efficiency_template = "%s\n%s%s\n--------------\n%s%s%s%s"; + static const godot::String administrative_efficiency_template = "%s\n%s%s\n--------------\n%s%s%s%s"; const fixed_point_t administrative_efficiency_from_administrators = country.get_administrative_efficiency_from_administrators_untracked(); administrative_efficiency_label.set_text( diff --git a/extension/src/openvic-extension/components/budget/StrataTaxBudget.cpp b/extension/src/openvic-extension/components/budget/StrataTaxBudget.cpp index 3b5a54aa..01ae4857 100644 --- a/extension/src/openvic-extension/components/budget/StrataTaxBudget.cpp +++ b/extension/src/openvic-extension/components/budget/StrataTaxBudget.cpp @@ -9,6 +9,7 @@ #include "openvic-extension/classes/GUILabel.hpp" #include "openvic-extension/classes/GUINode.hpp" #include "openvic-extension/classes/GUIScrollbar.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -37,7 +38,7 @@ StrataTaxBudget::StrataTaxBudget( GUILabel::set_text_and_tooltip( parent, Utilities::format("./country_budget/tax_%d_desc", static_cast(new_strata.get_index())), - generate_slider_tooltip_localisation_key(new_strata), + slider_tooltip_localisation_key, Utilities::format( "TAX_%s_DESC", Utilities::std_to_godot_string(strata.get_identifier()).to_upper() @@ -82,22 +83,19 @@ void StrataTaxBudget::update_slider_tooltip( const fixed_point_t scaled_value ) { //these use $VALUE$% - static const godot::StringName tax_efficiency_localisation_key = "BUDGET_TAX_EFFICIENCY"; - static const godot::StringName effective_tax_rate_localisation_key = "BUDGET_TAX_EFFECT"; //this uses $VALUE$ only - static const godot::StringName tax_efficiency_from_tech_localisation_key = "BUDGET_TECH_TAX"; const godot::String localised_strata_tax = slider.tr(slider_tooltip_localisation_key); const fixed_point_t tax_efficiency = country.get_tax_efficiency_untracked(); - const godot::String tax_efficiency_text = slider.tr(tax_efficiency_localisation_key).replace( + const godot::String tax_efficiency_text = slider.tr(OV_INAME("BUDGET_TAX_EFFICIENCY")).replace( Utilities::get_long_value_placeholder(), Utilities::float_to_string_dp(100 * static_cast(tax_efficiency), 2) ); const fixed_point_t tax_efficiency_from_tech = country.get_modifier_effect_value(*modifier_effect_cache.get_tax_eff()); - const godot::String tax_efficiency_from_tech_text = slider.tr(tax_efficiency_from_tech_localisation_key).replace( + const godot::String tax_efficiency_from_tech_text = slider.tr(OV_INAME("BUDGET_TECH_TAX")).replace( Utilities::get_short_value_placeholder(), Utilities::format( "%s%%", @@ -109,7 +107,7 @@ void StrataTaxBudget::update_slider_tooltip( ); const fixed_point_t effective_tax_rate = tax_efficiency * scaled_value; - const godot::String effective_tax_rate_text = slider.tr(effective_tax_rate_localisation_key).replace( + const godot::String effective_tax_rate_text = slider.tr(OV_INAME("BUDGET_TAX_EFFECT")).replace( Utilities::get_long_value_placeholder(), Utilities::float_to_string_dp(100 * static_cast(effective_tax_rate), 2) ); diff --git a/extension/src/openvic-extension/components/budget/TariffBudget.cpp b/extension/src/openvic-extension/components/budget/TariffBudget.cpp index 52c99889..1c707f46 100644 --- a/extension/src/openvic-extension/components/budget/TariffBudget.cpp +++ b/extension/src/openvic-extension/components/budget/TariffBudget.cpp @@ -79,13 +79,9 @@ void TariffBudget::update_slider_tooltip( CountryInstance& country, const fixed_point_t scaled_value ) { - static const godot::StringName tooltip_template = "%s\n%s\n--------------\n%s\n%s"; - static const godot::StringName green = "G"; - static const godot::StringName red = "R"; + static const godot::String tooltip_template = "%s\n%s\n--------------\n%s\n%s"; //Yes Victoria 2 overrides the colour specified in localisation... - godot::StringName const& prefix = scaled_value < 0 - ? red - : green; + godot::String prefix = scaled_value < 0 ? "R" : "G"; slider_tooltip_args[0] = slider.tr(slider_tooltip_localisation_key).replace( "Y"+Utilities::get_short_value_placeholder(), diff --git a/extension/src/openvic-extension/components/budget/abstract/BudgetIncomeComponent.cpp b/extension/src/openvic-extension/components/budget/abstract/BudgetIncomeComponent.cpp index dbcac5f8..af7ad4be 100644 --- a/extension/src/openvic-extension/components/budget/abstract/BudgetIncomeComponent.cpp +++ b/extension/src/openvic-extension/components/budget/abstract/BudgetIncomeComponent.cpp @@ -23,10 +23,9 @@ godot::String BudgetIncomeComponent::generate_income_summary_text( } godot::String BudgetIncomeComponent::generate_balance_income_summary_text(godot::Object const& translation_object) const { - static const godot::StringName green_plus = "G+"; const float income = static_cast(get_income()); //TODO use yesterdays value return translation_object.tr(income_summary_localisation_key).replace( "Y$VAL$", - green_plus + Utilities::float_to_string_dp(income, income_summary_decimal_places) + "G+" + Utilities::float_to_string_dp(income, income_summary_decimal_places) ); } \ No newline at end of file diff --git a/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.cpp b/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.cpp index 8c0d1038..2b5c240b 100644 --- a/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.cpp +++ b/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.cpp @@ -1,6 +1,7 @@ #include "SliderBudgetComponent.hpp" #include +#include #include @@ -14,7 +15,7 @@ using namespace OpenVic; SliderBudgetComponent::SliderBudgetComponent( GUINode const& parent, - godot::String&& new_slider_tooltip_localisation_key, + godot::StringName&& new_slider_tooltip_localisation_key, const BudgetType new_budget_type, godot::NodePath const& slider_path, godot::NodePath const& budget_label_path, diff --git a/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.hpp b/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.hpp index d9c3646d..88074fb5 100644 --- a/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.hpp +++ b/extension/src/openvic-extension/components/budget/abstract/SliderBudgetComponent.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "openvic-extension/components/budget/abstract/BudgetComponent.hpp" @@ -25,13 +26,13 @@ namespace OpenVic { void _on_slider_value_changed(); void update_labels(CountryInstance& country, const fixed_point_t scaled_value); protected: - const godot::String slider_tooltip_localisation_key; + const godot::StringName slider_tooltip_localisation_key; GUIScrollbar& slider; GUILabel* const budget_label; SliderBudgetComponent( GUINode const& parent, - godot::String&& new_slider_tooltip_localisation_key, + godot::StringName&& new_slider_tooltip_localisation_key, const BudgetType new_budget_type, godot::NodePath const& slider_path, godot::NodePath const& budget_label_path = {}, diff --git a/extension/src/openvic-extension/components/overview/ScoreOverview.cpp b/extension/src/openvic-extension/components/overview/ScoreOverview.cpp index 2ddd208a..1bad3b13 100644 --- a/extension/src/openvic-extension/components/overview/ScoreOverview.cpp +++ b/extension/src/openvic-extension/components/overview/ScoreOverview.cpp @@ -11,6 +11,7 @@ #include "openvic-extension/classes/GUILabel.hpp" #include "openvic-extension/classes/GUINode.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -287,9 +288,9 @@ void ScoreOverview::on_industrial_score_changed(const fixed_point_t new_industri godot::String ScoreOverview::generate_military_tooltip(CountryInstance& country) { godot::String military_power_tooltip; - static const godot::StringName military_power_from_land_key = "MIL_FROM_TROOPS"; - static const godot::StringName military_power_from_sea_key = "MIL_FROM_CAP_SHIPS"; - static const godot::StringName military_power_from_leaders_key = "MIL_FROM_LEADERS"; + const godot::StringName military_power_from_land_key = OV_INAME("MIL_FROM_TROOPS"); + const godot::StringName military_power_from_sea_key = OV_INAME("MIL_FROM_CAP_SHIPS"); + const godot::StringName military_power_from_leaders_key = OV_INAME("MIL_FROM_LEADERS"); for (auto const& [source, power] : { std::pair diff --git a/extension/src/openvic-extension/core/ArgumentParser.cpp b/extension/src/openvic-extension/core/ArgumentParser.cpp index d0b97469..adcbcfc2 100644 --- a/extension/src/openvic-extension/core/ArgumentParser.cpp +++ b/extension/src/openvic-extension/core/ArgumentParser.cpp @@ -42,6 +42,7 @@ #include #include "openvic-extension/core/Bind.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/utility/Utilities.hpp" #include "gen/commit_info.gen.hpp" @@ -250,8 +251,7 @@ ArgumentParser::ArgumentParser() { parse_arguments(OS::get_singleton()->get_cmdline_args(), false); parse_arguments(OS::get_singleton()->get_cmdline_user_args()); - static const StringName ARGS_PATH = "openvic/data/arguments"; - Dictionary arguments = Utilities::get_project_setting(ARGS_PATH, Dictionary()); + Dictionary arguments = Utilities::get_project_setting(OV_INAME("openvic/data/arguments"), Dictionary()); if (!arguments.is_empty()) { Array keys = arguments.keys(); for (size_t i = 0; i < arguments.size(); i++) { @@ -333,8 +333,8 @@ String ArgumentParser::get_help(bool p_is_rich) const { return _rich_help_string; } - static const StringName APP_NAME_PATH = "application/config/name"; - static const StringName APP_DESCRIPTION_PATH = "application/config/description"; + const StringName APP_NAME_PATH = OV_INAME("application/config/name"); + const StringName APP_DESCRIPTION_PATH = OV_INAME("application/config/description"); PackedStringArray option_help; option_help.resize(options.size()); diff --git a/extension/src/openvic-extension/core/StaticString.hpp b/extension/src/openvic-extension/core/StaticString.hpp new file mode 100644 index 00000000..8435ec20 --- /dev/null +++ b/extension/src/openvic-extension/core/StaticString.hpp @@ -0,0 +1,125 @@ +#pragma once + +#include + +#include "openvic-simulation/utility/Typedefs.hpp" + +// Inline Names, if the same string comes up multiple times, add it to StaticStrings and use OV_SNAME +#define OV_INAME(STR) \ + ([]() -> const godot::StringName& { \ + static godot::StringName sname = godot::StringName { STR, true }; \ + return sname; \ + })() + +namespace OpenVic { + class StaticStrings { + inline static StaticStrings* singleton = nullptr; + + public: + using StringName = godot::StringName; + + static void create() { + singleton = memnew(StaticStrings); + } + static void free() { + godot::memdelete(singleton); + singleton = nullptr; + } + + OV_ALWAYS_INLINE static StaticStrings* get_singleton() { + return singleton; + } + + const StringName name = "name"; + const StringName texture = "texture"; + const StringName scale = "scale"; + const StringName identifier = "identifier"; + const StringName position = "position"; + const StringName size = "size"; + const StringName changed = "changed"; + const StringName emit_changed = "emit_changed"; + const StringName hover = "hover"; + const StringName pressed = "pressed"; + const StringName disabled = "disabled"; + const StringName selected = "selected"; + const StringName change = "change"; + const StringName type = "type"; + const StringName tooltip = "tooltip"; + const StringName colour = "colour"; + const StringName weight = "weight"; + const StringName normal = "normal"; + const StringName font = "font"; + const StringName font_color = "font_color"; + const StringName font_hover_color = "font_hover_color"; + const StringName font_hover_pressed_color = "font_hover_pressed_color"; + const StringName font_pressed_color = "font_pressed_color"; + const StringName font_disabled_color = "font_disabled_color"; + const StringName scroll_index_changed = "scroll_index_changed"; + const StringName set_scroll_index = "set_scroll_index"; + const StringName set_z_index = "set_z_index"; + const StringName mouse_entered = "mouse_entered"; + const StringName mouse_exited = "mouse_exited"; + const StringName value_changed = "value_changed"; + const StringName gamestate_updated = "gamestate_updated"; + const StringName mapmode_changed = "mapmode_changed"; + const StringName rotation = "rotation"; + const StringName model = "model"; + const StringName culture = "culture"; + const StringName province_selected = "province_selected"; + const StringName REGION_NAME = "REGION_NAME"; + const StringName DAYS = "DAYS"; + const StringName KPH = "KPH"; + const StringName SFX_BUS = "SFX_BUS"; + const StringName caret_color = "caret_color"; + const StringName focus = "focus"; + const StringName panel = "panel"; + const StringName province = "province"; + const StringName state = "state"; + const StringName index = "index"; + const StringName primary_colour = "primary_colour"; + const StringName secondary_colour = "secondary_colour"; + const StringName tertiary_colour = "tertiary_colour"; + const StringName Master = "Master"; + const StringName is_mobilised = "is_mobilised"; + const StringName mobilisation_impact_tooltip = "mobilisation_impact_tooltip"; + const StringName population_menu_province_list_changed = "population_menu_province_list_changed"; + const StringName population_menu_province_list_selected_changed = "population_menu_province_list_selected_changed"; + const StringName population_menu_pops_changed = "population_menu_pops_changed"; + const StringName search_cache_changed = "search_cache_changed"; + const StringName update_tooltip = "update_tooltip"; + const StringName yes = "yes"; + const StringName no = "no"; + const StringName YES = "YES"; + const StringName NO = "NO"; + const StringName MOBILIZATION_IMPACT_LIMIT_DESC = "MOBILIZATION_IMPACT_LIMIT_DESC"; + const StringName MOBILIZATION_IMPACT_LIMIT_DESC2 = "MOBILIZATION_IMPACT_LIMIT_DESC2"; + const StringName level = "level"; + const StringName start_date = "start_date"; + const StringName end_date = "end_date"; + const StringName controller = "controller"; + const StringName PRODUCTION_FACTOR_OWNER = "PRODUCTION_FACTOR_OWNER"; + const StringName PRODUCTION_FACTOR_WORKER = "PRODUCTION_FACTOR_WORKER"; + const StringName leadership = "leadership"; + const StringName research = "research"; + const StringName research_tooltip = "research_tooltip"; + const StringName literacy = "literacy"; + const StringName country = "country"; + const StringName country_status = "country_status"; + const StringName total_rank = "total_rank"; + const StringName life_rating = "life_rating"; + const StringName rgo_employment_percentage = "rgo_employment_percentage"; + const StringName cores = "cores"; + const StringName buildings = "buildings"; + const StringName file = "file"; + const StringName idle = "idle"; + const StringName move = "move"; + const StringName attack = "attack"; + const StringName attachments = "attachments"; + const StringName node = "node"; + const StringName issues = "issues"; + const StringName time = "time"; + }; +} + +// Static Names, prefer if the same string comes up multiple times +#define OV_SNAME(STR) (::OpenVic::StaticStrings::get_singleton()->STR) diff --git a/extension/src/openvic-extension/core/register_core_types.cpp b/extension/src/openvic-extension/core/register_core_types.cpp index f055ee8d..3fa62e02 100644 --- a/extension/src/openvic-extension/core/register_core_types.cpp +++ b/extension/src/openvic-extension/core/register_core_types.cpp @@ -4,6 +4,7 @@ #include #include "openvic-extension/core/ArgumentParser.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/core/io/GameSettings.hpp" using namespace OpenVic; @@ -12,6 +13,8 @@ using namespace godot; static ArgumentParser* _argument_parser = nullptr; void OpenVic::register_core_types() { + StaticStrings::create(); + GDREGISTER_CLASS(ArgumentParser); GDREGISTER_CLASS(ArgumentOption); GDREGISTER_CLASS(GameSettings); @@ -23,4 +26,6 @@ void OpenVic::register_core_types() { void OpenVic::unregister_core_types() { Engine::get_singleton()->unregister_singleton("ArgumentParser"); memdelete(_argument_parser); + + StaticStrings::free(); } diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp index d9d016fd..bb9a66eb 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.cpp +++ b/extension/src/openvic-extension/singletons/AssetManager.cpp @@ -2,6 +2,7 @@ #include +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/core/Bind.hpp" #include "openvic-extension/utility/UITools.hpp" @@ -37,7 +38,7 @@ AssetManager::~AssetManager() { _singleton = nullptr; } -Ref AssetManager::_load_image(StringName const& path, bool flip_y) { +Ref AssetManager::_load_image(String const& path, bool flip_y) { GameSingleton* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, nullptr); @@ -122,9 +123,7 @@ Ref AssetManager::make_stylebox_texture(Ref const& t stylebox->set_texture(texture); - static const StringName changed_signal = "changed"; - static const StringName emit_changed_func = "emit_changed"; - texture->connect(changed_signal, Callable { *stylebox, emit_changed_func }, Object::CONNECT_PERSIST); + texture->connect(OV_SNAME(changed), Callable { *stylebox, OV_SNAME(emit_changed) }, Object::CONNECT_PERSIST); if (border != Vector2 {}) { stylebox->set_texture_margin(SIDE_LEFT, border.x); diff --git a/extension/src/openvic-extension/singletons/AssetManager.hpp b/extension/src/openvic-extension/singletons/AssetManager.hpp index 3728bb11..86192e7f 100644 --- a/extension/src/openvic-extension/singletons/AssetManager.hpp +++ b/extension/src/openvic-extension/singletons/AssetManager.hpp @@ -37,7 +37,7 @@ namespace OpenVic { image_asset_map_t image_assets; font_map_t fonts; - static godot::Ref _load_image(godot::StringName const& path, bool flip_y); + static godot::Ref _load_image(godot::String const& path, bool flip_y); protected: static void _bind_methods(); diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index 42df09a0..6be24521 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -11,6 +11,7 @@ #include #include +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/singletons/LoadLocalisation.hpp" #include "openvic-extension/singletons/MenuSingleton.hpp" @@ -29,15 +30,11 @@ using namespace OpenVic; /* Maximum width or height a GPU texture can have. */ static constexpr int32_t GPU_DIM_LIMIT = 0x3FFF; -/* StringNames cannot be constructed until Godot has called StringName::setup(), - * so we must use these wrapper functions to delay their initialisation. */ StringName const& GameSingleton::_signal_gamestate_updated() { - static const StringName signal_gamestate_updated = "gamestate_updated"; - return signal_gamestate_updated; + return OV_SNAME(gamestate_updated); } StringName const& GameSingleton::_signal_mapmode_changed() { - static const StringName signal_mapmode_changed = "mapmode_changed"; - return signal_mapmode_changed; + return OV_SNAME(mapmode_changed); } void GameSingleton::_bind_methods() { @@ -150,10 +147,6 @@ void GameSingleton::setup_logger() { } TypedArray GameSingleton::get_mod_info() const { - static const StringName identifier_key = "identifier"; - static const StringName dependencies_key = "dependencies"; - static const StringName is_loaded_key = "is_loaded"; - TypedArray results; ModManager const& mod_manager = game_manager.get_mod_manager(); @@ -162,9 +155,9 @@ TypedArray GameSingleton::get_mod_info() const { for (Mod const& mod : mod_manager.get_mods()) { Dictionary mod_info_dictionary; - mod_info_dictionary[identifier_key] = Utilities::std_to_godot_string(mod.get_identifier()); + mod_info_dictionary[OV_SNAME(identifier)] = Utilities::std_to_godot_string(mod.get_identifier()); - mod_info_dictionary[dependencies_key] = [&]() -> PackedStringArray { + mod_info_dictionary[OV_INAME("dependencies")] = [&]() -> PackedStringArray { PackedStringArray result; for (std::string_view dep_id : mod.get_dependencies()) { result.push_back(Utilities::std_to_godot_string(dep_id)); @@ -172,7 +165,7 @@ TypedArray GameSingleton::get_mod_info() const { return result; }(); - mod_info_dictionary[is_loaded_key] = ranges::contains(loaded_mods, &mod); + mod_info_dictionary[OV_INAME("is_loaded")] = ranges::contains(loaded_mods, &mod); results.push_back(std::move(mod_info_dictionary)); } @@ -181,9 +174,6 @@ TypedArray GameSingleton::get_mod_info() const { } TypedArray GameSingleton::get_bookmark_info() const { - static const StringName bookmark_info_name_key = "bookmark_name"; - static const StringName bookmark_info_date_key = "bookmark_date"; - TypedArray results; BookmarkManager const& bookmark_manager = @@ -192,8 +182,8 @@ TypedArray GameSingleton::get_bookmark_info() const { for (Bookmark const& bookmark : bookmark_manager.get_bookmarks()) { Dictionary bookmark_info; - bookmark_info[bookmark_info_name_key] = Utilities::std_to_godot_string(bookmark.get_name()); - bookmark_info[bookmark_info_date_key] = Utilities::date_to_formatted_string(bookmark.get_date(), false); + bookmark_info[OV_INAME("bookmark_name")] = Utilities::std_to_godot_string(bookmark.get_name()); + bookmark_info[OV_INAME("bookmark_date")] = Utilities::date_to_formatted_string(bookmark.get_date(), false); results.push_back(std::move(bookmark_info)); } @@ -397,11 +387,6 @@ Error GameSingleton::_update_colour_image() { } TypedArray GameSingleton::get_province_names() const { - static const StringName identifier_key = "identifier"; - static const StringName position_key = "position"; - static const StringName rotation_key = "rotation"; - static const StringName scale_key = "scale"; - MapDefinition const& map_definition = get_definition_manager().get_map_definition(); TypedArray ret; @@ -412,17 +397,17 @@ TypedArray GameSingleton::get_province_names() const { Dictionary province_dict; - province_dict[identifier_key] = Utilities::std_to_godot_string(province.get_identifier()); - province_dict[position_key] = normalise_map_position(province.get_text_position()); + province_dict[OV_SNAME(identifier)] = Utilities::std_to_godot_string(province.get_identifier()); + province_dict[OV_SNAME(position)] = normalise_map_position(province.get_text_position()); const float rotation = static_cast(province.get_text_rotation()); if (rotation != 0.0f) { - province_dict[rotation_key] = rotation; + province_dict[OV_SNAME(rotation)] = rotation; } const float scale = static_cast(province.get_text_scale()); if (scale != 1.0f) { - province_dict[scale_key] = scale; + province_dict[OV_SNAME(scale)] = scale; } ret[index] = std::move(province_dict); @@ -538,7 +523,7 @@ Error GameSingleton::_load_map_images() { Error GameSingleton::_load_terrain_variants() { ERR_FAIL_COND_V_MSG(terrain_texture.is_valid(), FAILED, "Terrain variants have already been loaded!"); - static const StringName terrain_texturesheet_path = "map/terrain/texturesheet.tga"; + const StringName terrain_texturesheet_path = OV_INAME("map/terrain/texturesheet.tga"); AssetManager* asset_manager = AssetManager::get_singleton(); ERR_FAIL_NULL_V(asset_manager, FAILED); diff --git a/extension/src/openvic-extension/singletons/MapItemSingleton.cpp b/extension/src/openvic-extension/singletons/MapItemSingleton.cpp index ceef7743..e724db97 100644 --- a/extension/src/openvic-extension/singletons/MapItemSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MapItemSingleton.cpp @@ -7,6 +7,7 @@ #include "godot_cpp/variant/packed_vector2_array.hpp" #include "godot_cpp/variant/typed_array.hpp" #include "godot_cpp/variant/vector2.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/core/Bind.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -55,18 +56,12 @@ MapItemSingleton::~MapItemSingleton() { // repackage the billboard object into a godot dictionary for the Billboard manager to work with void MapItemSingleton::add_billboard_dict(GFX::Billboard const& billboard, TypedArray& billboard_dict_array) const { - - static const StringName name_key = "name"; - static const StringName texture_key = "texture"; - static const StringName scale_key = "scale"; - static const StringName no_of_frames_key = "noFrames"; - Dictionary dict; - dict[name_key] = Utilities::std_to_godot_string(billboard.get_name()); - dict[texture_key] = Utilities::std_to_godot_string(billboard.get_texture_file()); - dict[scale_key] = static_cast(billboard.get_scale()); - dict[no_of_frames_key] = billboard.get_no_of_frames(); + dict[OV_SNAME(name)] = Utilities::std_to_godot_string(billboard.get_name()); + dict[OV_SNAME(texture)] = Utilities::std_to_godot_string(billboard.get_texture_file()); + dict[OV_SNAME(scale)] = static_cast(billboard.get_scale()); + dict[OV_INAME("noFrames")] = billboard.get_no_of_frames(); billboard_dict_array.push_back(dict); } @@ -89,23 +84,15 @@ TypedArray MapItemSingleton::get_billboards() const { } void MapItemSingleton::add_projection_dict(GFX::Projection const& projection, TypedArray& projection_dict_array) const { - static const StringName name_key = "name"; - static const StringName texture_key = "texture"; - static const StringName size_key = "size"; - static const StringName spin_key = "spin"; - static const StringName expanding_key = "expanding"; - static const StringName duration_key = "duration"; - static const StringName additative_key = "additative"; - Dictionary dict; - dict[name_key] = Utilities::std_to_godot_string(projection.get_name()); - dict[texture_key] = Utilities::std_to_godot_string(projection.get_texture_file()); - dict[size_key] = static_cast(projection.get_size()); - dict[spin_key] = static_cast(projection.get_spin()); - dict[expanding_key] = static_cast(projection.get_expanding()); - dict[duration_key] = static_cast(projection.get_duration()); - dict[additative_key] = projection.get_additative(); + dict[OV_SNAME(name)] = Utilities::std_to_godot_string(projection.get_name()); + dict[OV_SNAME(texture)] = Utilities::std_to_godot_string(projection.get_texture_file()); + dict[OV_SNAME(size)] = static_cast(projection.get_size()); + dict[OV_INAME("spin")] = static_cast(projection.get_spin()); + dict[OV_INAME("expanding")] = static_cast(projection.get_expanding()); + dict[OV_INAME("duration")] = static_cast(projection.get_duration()); + dict[OV_INAME("additative")] = projection.get_additative(); projection_dict_array.push_back(dict); } diff --git a/extension/src/openvic-extension/singletons/MenuSingleton.cpp b/extension/src/openvic-extension/singletons/MenuSingleton.cpp index f6efb69e..6bb68e55 100644 --- a/extension/src/openvic-extension/singletons/MenuSingleton.cpp +++ b/extension/src/openvic-extension/singletons/MenuSingleton.cpp @@ -15,6 +15,7 @@ #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUINode.hpp" #include "openvic-extension/components/budget/BudgetMenu.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/core/Bind.hpp" @@ -29,25 +30,19 @@ province_sort_cache { decltype(province_sort_cache)::create_empty() }, rebel_type_sort_cache { decltype(rebel_type_sort_cache)::create_empty() } {} StringName const& MenuSingleton::_signal_population_menu_province_list_changed() { - static const StringName signal_population_menu_province_list_changed = "population_menu_province_list_changed"; - return signal_population_menu_province_list_changed; + return OV_SNAME(population_menu_province_list_changed); } StringName const& MenuSingleton::_signal_population_menu_province_list_selected_changed() { - static const StringName signal_population_menu_province_list_selected_changed = - "population_menu_province_list_selected_changed"; - return signal_population_menu_province_list_selected_changed; + return OV_SNAME(population_menu_province_list_selected_changed); } StringName const& MenuSingleton::_signal_population_menu_pops_changed() { - static const StringName signal_population_menu_pops_changed = "population_menu_pops_changed"; - return signal_population_menu_pops_changed; + return OV_SNAME(population_menu_pops_changed); } StringName const& MenuSingleton::_signal_search_cache_changed() { - static const StringName signal_search_cache_changed = "search_cache_changed"; - return signal_search_cache_changed; + return OV_SNAME(search_cache_changed); } StringName const& MenuSingleton::_signal_update_tooltip() { - static const StringName signal_update_tooltip = "update_tooltip"; - return signal_update_tooltip; + return OV_SNAME(update_tooltip); } String MenuSingleton::_make_modifier_effect_value( @@ -136,14 +131,8 @@ String MenuSingleton::_make_rules_tooltip(RuleSet const& rules) const { return {}; } - static const StringName yes_key = "YES"; - static const StringName no_key = "NO"; - - static const String start_text = ": " + GUILabel::get_colour_marker(); - static const String end_text = GUILabel::get_colour_marker() + String { "!" }; - - const String enabled_text = start_text + String { "G" } + tr(yes_key) + end_text; - const String disabled_text = start_text + String { "R" } + tr(no_key) + end_text; + const String enabled_text = vformat(": %sG%s%s!", GUILabel::get_colour_marker(), tr(OV_SNAME(YES)), GUILabel::get_colour_marker()); + const String disabled_text = vformat(": %sR%s%s!", GUILabel::get_colour_marker(), tr(OV_SNAME(NO)), GUILabel::get_colour_marker()); String result; @@ -167,17 +156,13 @@ String MenuSingleton::_make_mobilisation_impact_tooltip() const { IssueManager const& issue_manager = GameSingleton::get_singleton()->get_definition_manager().get_politics_manager().get_issue_manager(); - static const StringName mobilisation_impact_tooltip_localisation_key = "MOBILIZATION_IMPACT_LIMIT_DESC"; static const String mobilisation_impact_tooltip_replace_impact_key = "$IMPACT$"; static const String mobilisation_impact_tooltip_replace_policy_key = "$POLICY$"; static const String mobilisation_impact_tooltip_replace_units_key = "$UNITS$"; - static const StringName mobilisation_impact_tooltip2_localisation_key = "MOBILIZATION_IMPACT_LIMIT_DESC2"; static const String mobilisation_impact_tooltip2_replace_curr_key = "$CURR$"; static const String mobilisation_impact_tooltip2_replace_impact_key = "$IMPACT$"; - static const StringName no_issue = "noIssue"; - PartyPolicyGroup const* war_policy_issue_group = issue_manager.get_party_policy_group_by_identifier("war_policy"); PartyPolicy const* war_policy_issue = war_policy_issue_group == nullptr ? nullptr @@ -186,20 +171,20 @@ String MenuSingleton::_make_mobilisation_impact_tooltip() const { const String impact_string = Utilities::fixed_point_to_string_dp(country->get_mobilisation_impact() * 100, 1) + "%"; return tr( - mobilisation_impact_tooltip_localisation_key + OV_SNAME(MOBILIZATION_IMPACT_LIMIT_DESC) ).replace( mobilisation_impact_tooltip_replace_impact_key, impact_string ).replace( mobilisation_impact_tooltip_replace_policy_key, tr( war_policy_issue != nullptr ? StringName { Utilities::std_to_godot_string(war_policy_issue->get_identifier()) } - : no_issue + : OV_INAME("noIssue") ) ).replace( mobilisation_impact_tooltip_replace_units_key, String::num_uint64(country->get_mobilisation_max_regiment_count()) ) + "\n" + tr( - mobilisation_impact_tooltip2_localisation_key + OV_SNAME(MOBILIZATION_IMPACT_LIMIT_DESC2) ).replace( mobilisation_impact_tooltip2_replace_curr_key, String::num_uint64(country->get_regiment_count()) ).replace( @@ -415,12 +400,6 @@ static TypedArray _make_buildings_dict_array( return {}; } - static const StringName building_info_level_key = "level"; - static const StringName building_info_expansion_state_key = "expansion_state"; - static const StringName building_info_start_date_key = "start_date"; - static const StringName building_info_end_date_key = "end_date"; - static const StringName building_info_expansion_progress_key = "expansion_progress"; - /* This system relies on the province buildings all being present in the right order. It will have to * be changed if we want to support variable combinations and permutations of province buildings. */ TypedArray buildings_array; @@ -430,11 +409,11 @@ static TypedArray _make_buildings_dict_array( BuildingInstance const& building = buildings[idx]; Dictionary building_dict; - building_dict[building_info_level_key] = static_cast(building.get_level()); - building_dict[building_info_expansion_state_key] = static_cast(building.get_expansion_state()); - building_dict[building_info_start_date_key] = Utilities::date_to_string(building.get_start_date()); - building_dict[building_info_end_date_key] = Utilities::date_to_string(building.get_end_date()); - building_dict[building_info_expansion_progress_key] = static_cast(building.get_expansion_progress()); + building_dict[OV_SNAME(level)] = static_cast(building.get_level()); + building_dict[OV_INAME("expansion_state")] = static_cast(building.get_expansion_state()); + building_dict[OV_SNAME(start_date)] = Utilities::date_to_string(building.get_start_date()); + building_dict[OV_SNAME(end_date)] = Utilities::date_to_string(building.get_end_date()); + building_dict[OV_INAME("expansion_progress")] = static_cast(building.get_expansion_progress()); buildings_array[idx] = std::move(building_dict); } @@ -454,80 +433,52 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) InstanceManager const* instance_manager = game_singleton->get_instance_manager(); ERR_FAIL_NULL_V(instance_manager, {}); - static const StringName province_info_province_key = "province"; - static const StringName province_info_state_key = "state"; - static const StringName province_info_slave_status_key = "slave_status"; - static const StringName province_info_colony_status_key = "colony_status"; - static const StringName province_info_terrain_type_key = "terrain_type"; - static const StringName province_info_terrain_type_tooltip_key = "terrain_type_tooltip"; - static const StringName province_info_life_rating_key = "life_rating"; - static const StringName province_info_controller_key = "controller"; - static const StringName province_info_controller_tooltip_key = "controller_tooltip"; - static const StringName province_info_rgo_icon_key = "rgo_icon"; - static const StringName province_info_rgo_production_tooltip_key = "rgo_production_tooltip"; - static const StringName province_info_rgo_total_employees_key = "rgo_total_employees"; - static const StringName province_info_rgo_employment_percentage_key = "rgo_employment_percentage"; - static const StringName province_info_rgo_employment_tooltip_key = "rgo_employment_tooltip"; - static const StringName province_info_rgo_output_quantity_yesterday_key = "rgo_output_quantity_yesterday"; - static const StringName province_info_rgo_revenue_yesterday_key = "rgo_revenue_yesterday"; - static const StringName province_info_crime_name_key = "crime_name"; - static const StringName province_info_crime_icon_key = "crime_icon"; - static const StringName province_info_total_population_key = "total_population"; - static const StringName province_info_pop_types_key = "pop_types"; - static const StringName province_info_pop_ideologies_key = "pop_ideologies"; - static const StringName province_info_pop_cultures_key = "pop_cultures"; - static const StringName province_info_cores_key = "cores"; - static const StringName province_info_buildings_key = "buildings"; - ProvinceInstance const* province = instance_manager->get_map_instance().get_province_instance_from_number(province_number); if (province == nullptr) { return {}; } Dictionary ret; - ret[province_info_province_key] = Utilities::std_to_godot_string(province->get_identifier()); + ret[OV_SNAME(province)] = Utilities::std_to_godot_string(province->get_identifier()); State const* state = province->get_state(); if (state != nullptr) { - ret[province_info_state_key] = Utilities::get_state_name(*this,*state); + ret[OV_SNAME(state)] = Utilities::get_state_name(*this,*state); } - ret[province_info_slave_status_key] = province->get_slave(); + ret[OV_INAME("slave_status")] = province->get_slave(); - ret[province_info_colony_status_key] = static_cast(province->get_colony_status()); + ret[OV_INAME("colony_status")] = static_cast(province->get_colony_status()); TerrainType const* terrain_type = province->get_terrain_type(); if (terrain_type != nullptr) { String terrain_type_string = Utilities::std_to_godot_string(terrain_type->get_identifier()); - static const StringName terrain_type_localisation_key = "PROVINCEVIEW_TERRAIN"; static const String terrain_type_replace_key = "$TERRAIN$"; - static const StringName movement_cost_localisation_key = "TERRAIN_MOVEMENT_COST"; static const String terrain_type_template_string = "%s" + get_tooltip_separator() + "%s" + GUILabel::get_colour_marker() + "Y%s" + GUILabel::get_colour_marker() + "!%s"; - ret[province_info_terrain_type_tooltip_key] = Utilities::format( + ret[OV_INAME("terrain_type_tooltip")] = Utilities::format( terrain_type_template_string, - tr(terrain_type_localisation_key).replace(terrain_type_replace_key, tr(terrain_type_string)), - tr(movement_cost_localisation_key), + tr(OV_INAME("PROVINCEVIEW_TERRAIN")).replace(terrain_type_replace_key, tr(terrain_type_string)), + tr(OV_INAME("TERRAIN_MOVEMENT_COST")), Utilities::fixed_point_to_string_dp(terrain_type->get_movement_cost(), 2), _make_modifier_effects_tooltip(*terrain_type) ); - ret[province_info_terrain_type_key] = std::move(terrain_type_string); + ret[OV_INAME("terrain_type")] = std::move(terrain_type_string); } - ret[province_info_life_rating_key] = province->get_life_rating(); + ret[OV_SNAME(life_rating)] = province->get_life_rating(); CountryInstance const* controller = province->get_controller(); if (controller != nullptr) { - ret[province_info_controller_key] = Utilities::std_to_godot_string(controller->get_identifier()); + ret[OV_SNAME(controller)] = Utilities::std_to_godot_string(controller->get_identifier()); - static const StringName controller_localisation_key = "PV_CONTROLLER"; static const String controller_template_string = "%s %s"; - ret[province_info_controller_tooltip_key] = Utilities::format( + ret[OV_INAME("controller_tooltip")] = Utilities::format( controller_template_string, - tr(controller_localisation_key), + tr(OV_INAME("PV_CONTROLLER")), Utilities::get_country_name(*this,*controller) ); } @@ -538,16 +489,16 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) ProductionType const& production_type = *rgo.get_production_type_nullable(); GoodDefinition const& rgo_good = *province->get_rgo_good(); - ret[province_info_rgo_icon_key] = static_cast(rgo_good.get_index()); + ret[OV_INAME("rgo_icon")] = static_cast(rgo_good.get_index()); - ret[province_info_rgo_output_quantity_yesterday_key] = static_cast(rgo.get_output_quantity_yesterday()); - ret[province_info_rgo_revenue_yesterday_key] = static_cast(rgo.get_revenue_yesterday()); - ret[province_info_rgo_total_employees_key] = rgo.get_total_employees_count_cache(); + ret[OV_INAME("rgo_output_quantity_yesterday")] = static_cast(rgo.get_output_quantity_yesterday()); + ret[OV_INAME("rgo_revenue_yesterday")] = static_cast(rgo.get_revenue_yesterday()); + ret[OV_INAME("rgo_total_employees")] = rgo.get_total_employees_count_cache(); const pop_size_t max_employee_count = rgo.get_max_employee_count_cache(); if (max_employee_count == 0) { - ret[province_info_rgo_employment_percentage_key] = 100.0f; + ret[OV_SNAME(rgo_employment_percentage)] = 100.0f; } else { - ret[province_info_rgo_employment_percentage_key] = + ret[OV_SNAME(rgo_employment_percentage)] = static_cast(rgo.get_total_employees_count_cache() * fixed_point_t::_100 / max_employee_count); } @@ -580,14 +531,12 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) effect_value /= state->get_total_population(); } - static const StringName owners_localisation_key = "PRODUCTION_FACTOR_OWNER"; - switch (owner_job->get_effect_type()) { case OUTPUT: output_multiplier += effect_value; output_string += Utilities::format( employee_effect_template_string, - tr(owners_localisation_key), + tr(OV_SNAME(PRODUCTION_FACTOR_OWNER)), tr(Utilities::std_to_godot_string(owner_pop_type.get_identifier())), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_output_country(), effect_value, true @@ -598,7 +547,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) throughput_multiplier += effect_value; throughput_string += Utilities::format( employee_effect_template_string, - tr(owners_localisation_key), + tr(OV_SNAME(PRODUCTION_FACTOR_OWNER)), tr(Utilities::std_to_godot_string(owner_pop_type.get_identifier())), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_throughput_country(), effect_value, true @@ -638,14 +587,12 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) ? relative_to_workforce : effect_multiplier * std::min(relative_to_workforce, job.get_amount()); - static const StringName workers_localisation_key = "PRODUCTION_FACTOR_WORKER"; - switch (job.get_effect_type()) { case OUTPUT: output_from_workers += effect_value; output_string += Utilities::format( employee_effect_template_string, - tr(workers_localisation_key), + tr(OV_SNAME(PRODUCTION_FACTOR_WORKER)), tr(Utilities::std_to_godot_string(pop_type.get_identifier())), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_output_country(), effect_value, true @@ -656,7 +603,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) throughput_from_workers += effect_value; throughput_string += Utilities::format( employee_effect_template_string, - tr(workers_localisation_key), + tr(OV_SNAME(PRODUCTION_FACTOR_WORKER)), tr(Utilities::std_to_godot_string(pop_type.get_identifier())), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_throughput_country(), effect_value, true @@ -738,11 +685,9 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) } if (size_from_province != fixed_point_t::_0) { - static const StringName rgo_size_localisation_key = "RGO_SIZE"; - size_string += Utilities::format( size_modifier_template_string, - tr(rgo_size_localisation_key), + tr(OV_INAME("RGO_SIZE")), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_farm_rgo_size_local(), size_from_province, false ) @@ -781,9 +726,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) } if (size_from_tech != fixed_point_t::_0) { - static const StringName from_technology_localisation_key = "employ_from_tech"; - - size_string += tr(from_technology_localisation_key) + _make_modifier_effect_value_coloured( + size_string += tr(OV_INAME("employ_from_tech")) + _make_modifier_effect_value_coloured( *modifier_effect_cache.get_farm_rgo_size_global(), size_from_tech, false ); } @@ -793,11 +736,9 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) if (output_from_tech != fixed_point_t::_0) { output_multiplier += output_from_tech; - static const StringName rgo_output_tech_localisation_key = "RGO_OUTPUT_TECH"; - output_string += Utilities::format( tech_modifier_template_string, - tr(rgo_output_tech_localisation_key), + tr(OV_INAME("RGO_OUTPUT_TECH")), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_output_tech(), output_from_tech, true ) @@ -807,11 +748,9 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) if (throughput_from_tech != fixed_point_t::_0) { throughput_multiplier += throughput_from_tech; - static const StringName rgo_throughput_tech_localisation_key = "RGO_THROUGHPUT_TECH"; - throughput_string += Utilities::format( tech_modifier_template_string, - tr(rgo_throughput_tech_localisation_key), + tr(OV_INAME("RGO_THROUGHPUT_TECH")), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_throughput_tech(), throughput_from_tech, true ) @@ -822,16 +761,9 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) throughput_string += throughput_modifiers; } - static const StringName rgo_production_localisation_key = "PROVINCEVIEW_GOODSINCOME"; static const String rgo_good_replace_key = "$GOODS$"; - static const StringName max_output_localisation_key = "PRODUCTION_OUTPUT_GOODS_TOOLTIP2"; static const String curr_replace_key = "$CURR$"; - static const StringName output_explanation_localisation_key = "PRODUCTION_OUTPUT_EXPLANATION"; - static const StringName base_output_localisation_key = "PRODUCTION_BASE_OUTPUT_GOODS_TOOLTIP"; static const String base_replace_key = "$BASE$"; - static const StringName output_efficiency_localisation_key = "PRODUCTION_OUTPUT_EFFICIENCY_TOOLTIP"; - static const StringName base_localisation_key = "PRODUCTION_BASE_OUTPUT"; - static const StringName throughput_efficiency_localisation_key = "PRODUCTION_THROUGHPUT_EFFICIENCY_TOOLTIP"; static const String rgo_production_template_string = "%s\n%s%s" + get_tooltip_separator() + "%s%s%s\n%s " + GUILabel::get_colour_marker() + "G100%%" + GUILabel::get_colour_marker() + "!%s\n\n%s%s%s"; @@ -840,61 +772,55 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) const fixed_point_t base_output = production_type.get_base_output_quantity(); const fixed_point_t max_output = base_output * throughput_efficiency * output_efficiency; - ret[province_info_rgo_production_tooltip_key] = Utilities::format( + ret[OV_INAME("rgo_production_tooltip")] = Utilities::format( rgo_production_template_string, - tr(rgo_production_localisation_key).replace( + tr(OV_INAME("PROVINCEVIEW_GOODSINCOME")).replace( rgo_good_replace_key, tr(Utilities::std_to_godot_string(rgo_good.get_identifier())) ).replace( Utilities::get_long_value_placeholder(), Utilities::fixed_point_to_string_dp(rgo.get_revenue_yesterday(), 3) ), - tr(max_output_localisation_key).replace(curr_replace_key, Utilities::fixed_point_to_string_dp(max_output, 2)), - tr(output_explanation_localisation_key), - tr(base_output_localisation_key).replace(base_replace_key, Utilities::fixed_point_to_string_dp(base_output, 2)), - tr(output_efficiency_localisation_key), + tr(OV_INAME("PRODUCTION_OUTPUT_GOODS_TOOLTIP2")).replace(curr_replace_key, Utilities::fixed_point_to_string_dp(max_output, 2)), + tr(OV_INAME("PRODUCTION_OUTPUT_EXPLANATION")), + tr(OV_INAME("PRODUCTION_BASE_OUTPUT_GOODS_TOOLTIP")).replace(base_replace_key, Utilities::fixed_point_to_string_dp(base_output, 2)), + tr(OV_INAME("PRODUCTION_OUTPUT_EFFICIENCY_TOOLTIP")), _make_modifier_effect_value_coloured(*modifier_effect_cache.get_rgo_output_country(), output_efficiency, false), - tr(base_localisation_key), + tr(OV_INAME("PRODUCTION_BASE_OUTPUT")), output_string, - tr(throughput_efficiency_localisation_key), + tr(OV_INAME("PRODUCTION_THROUGHPUT_EFFICIENCY_TOOLTIP")), _make_modifier_effect_value_coloured( *modifier_effect_cache.get_rgo_throughput_country(), throughput_efficiency, false ), throughput_string ); - static const StringName employment_localisation_key = "PROVINCEVIEW_EMPLOYMENT"; - static const StringName employee_count_localisation_key = "PRODUCTION_FACTORY_EMPLOYEECOUNT_TOOLTIP2"; - static const String employee_replace_key = "$EMPLOYEES$"; - static const String employee_max_replace_key = "$EMPLOYEE_MAX$"; - static const StringName rgo_workforce_localisation_key = "BASE_RGO_SIZE"; - static const StringName province_size_localisation_key = "FROM_PROV_SIZE"; static const String rgo_employment_template_string = "%s" + get_tooltip_separator() + "%s%s\n%s%d\n%s\n%s" + GUILabel::get_colour_marker() + "G%d"; - ret[province_info_rgo_employment_tooltip_key] = Utilities::format( + ret[OV_INAME("rgo_employment_tooltip")] = Utilities::format( rgo_employment_template_string, - tr(employment_localisation_key).replace(Utilities::get_long_value_placeholder(), {}), - tr(employee_count_localisation_key).replace( - employee_replace_key, String::num_int64(rgo.get_total_employees_count_cache()) + tr(OV_INAME("PROVINCEVIEW_EMPLOYMENT")).replace(Utilities::get_long_value_placeholder(), {}), + tr(OV_INAME("PRODUCTION_FACTORY_EMPLOYEECOUNT_TOOLTIP2")).replace( + OV_INAME("$EMPLOYEES$"), String::num_int64(rgo.get_total_employees_count_cache()) ).replace( - employee_max_replace_key, String::num_int64(rgo.get_max_employee_count_cache()) + OV_INAME("$EMPLOYEE_MAX$"), String::num_int64(rgo.get_max_employee_count_cache()) ), amount_of_employees_by_pop_type, - tr(rgo_workforce_localisation_key), + tr(OV_INAME("BASE_RGO_SIZE")), production_type.get_base_workforce_size(), size_string, - tr(province_size_localisation_key), + tr(OV_INAME("FROM_PROV_SIZE")), static_cast(rgo.get_size_multiplier()) // TODO - remove cast once variable is an int32_t ); } Crime const* crime = province->get_crime(); if (crime != nullptr) { - ret[province_info_crime_name_key] = Utilities::std_to_godot_string(crime->get_identifier()); - ret[province_info_crime_icon_key] = static_cast(crime->get_icon()); + ret[OV_INAME("crime_name")] = Utilities::std_to_godot_string(crime->get_identifier()); + ret[OV_INAME("crime_icon")] = static_cast(crime->get_icon()); } - ret[province_info_total_population_key] = province->get_total_population(); + ret[OV_INAME("total_population")] = province->get_total_population(); const auto make_pie_chart_tooltip = [this]( has_get_identifier_and_colour auto const* key, String const& identifier, float weight, float total_weight @@ -910,19 +836,19 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) GFXPieChartTexture::godot_pie_chart_data_t pop_types = GFXPieChartTexture::distribution_to_slices_array(province->get_population_by_type(), make_pie_chart_tooltip); if (!pop_types.is_empty()) { - ret[province_info_pop_types_key] = std::move(pop_types); + ret[OV_INAME("pop_types")] = std::move(pop_types); } GFXPieChartTexture::godot_pie_chart_data_t ideologies = GFXPieChartTexture::distribution_to_slices_array(province->get_supporter_equivalents_by_ideology(), make_pie_chart_tooltip); if (!ideologies.is_empty()) { - ret[province_info_pop_ideologies_key] = std::move(ideologies); + ret[OV_INAME("pop_ideologies")] = std::move(ideologies); } GFXPieChartTexture::godot_pie_chart_data_t cultures = GFXPieChartTexture::distribution_to_slices_array(province->get_population_by_culture(), make_pie_chart_tooltip); if (!cultures.is_empty()) { - ret[province_info_pop_cultures_key] = std::move(cultures); + ret[OV_INAME("pop_cultures")] = std::move(cultures); } ordered_set const& cores = province->get_cores(); @@ -932,7 +858,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) for (size_t idx = 0; idx < cores.size(); ++idx) { cores_array[idx] = Utilities::std_to_godot_string(cores.data()[idx]->get_identifier()); } - ret[province_info_cores_key] = std::move(cores_array); + ret[OV_SNAME(cores)] = std::move(cores_array); } else { UtilityFunctions::push_error( "Failed to resize cores array to the correct size (", static_cast(cores.size()), ") for province ", @@ -943,7 +869,7 @@ Dictionary MenuSingleton::get_province_info_from_number(int32_t province_number) TypedArray building_dict_array = _make_buildings_dict_array(province); if (!building_dict_array.is_empty()) { - ret[province_info_buildings_key] = std::move(building_dict_array); + ret[OV_SNAME(buildings)] = std::move(building_dict_array); } return ret; @@ -1011,13 +937,9 @@ Dictionary MenuSingleton::get_topbar_info() const { Dictionary ret; // Country / Ranking - static const StringName country_key = "country"; - static const StringName country_status_key = "country_status"; - static const StringName total_rank_key = "total_rank"; - - ret[country_key] = Utilities::std_to_godot_string(country->get_identifier()); - ret[country_status_key] = static_cast(country->get_country_status()); - ret[total_rank_key] = static_cast(country->get_total_rank()); + ret[OV_SNAME(country)] = Utilities::std_to_godot_string(country->get_identifier()); + ret[OV_SNAME(country_status)] = static_cast(country->get_country_status()); + ret[OV_SNAME(total_rank)] = static_cast(country->get_total_rank()); // Production @@ -1025,71 +947,52 @@ Dictionary MenuSingleton::get_topbar_info() const { // Technology { - static const StringName research_key = "research"; - static const StringName research_tooltip_key = "research_tooltip"; - static const StringName research_progress_key = "research_progress"; - static const StringName literacy_key = "literacy"; - static const StringName literacy_change_key = "literacy_change"; - static const StringName research_points_key = "research_points"; - static const StringName research_points_tooltip_key = "research_points_tooltip"; - Technology const* current_research = country->get_current_research_untracked(); if (current_research != nullptr) { - static const StringName research_localisation_key = "TECHNOLOGYVIEW_RESEARCH_TOOLTIP"; static const String tech_replace_key = "$TECH$"; static const String date_replace_key = "$DATE$"; - static const StringName research_invested_localisation_key = "TECHNOLOGYVIEW_RESEARCH_INVESTED_TOOLTIP"; static const String invested_replace_key = "$INVESTED$"; static const String cost_replace_key = "$COST$"; String current_tech_localised = tr(Utilities::std_to_godot_string(current_research->get_identifier())); - ret[research_tooltip_key] = tr(research_localisation_key).replace( + ret[OV_SNAME(research_tooltip)] = tr(OV_INAME("TECHNOLOGYVIEW_RESEARCH_TOOLTIP")).replace( tech_replace_key, current_tech_localised ).replace( date_replace_key, Utilities::date_to_formatted_string(country->get_expected_research_completion_date_untracked(), false) - ) + "\n" + tr(research_invested_localisation_key).replace( + ) + "\n" + tr(OV_INAME("TECHNOLOGYVIEW_RESEARCH_INVESTED_TOOLTIP")).replace( invested_replace_key, String::num_uint64(country->get_invested_research_points_untracked().truncate()) ).replace(cost_replace_key, String::num_uint64(country->get_current_research_cost_untracked().truncate())); - ret[research_key] = std::move(current_tech_localised); + ret[OV_SNAME(research)] = std::move(current_tech_localised); - ret[research_progress_key] = static_cast(country->research_progress.get_untracked()); + ret[OV_INAME("research_progress")] = static_cast(country->research_progress.get_untracked()); } else if (country->is_civilised()) { - static const StringName civilised_no_research_localisation_key = "TB_TECH_NO_CURRENT"; - static const StringName civilised_no_research_tooltip_localisation_key = "TECHNOLOGYVIEW_NO_RESEARCH_TOOLTIP"; - - ret[research_key] = tr(civilised_no_research_localisation_key); - ret[research_tooltip_key] = tr(civilised_no_research_tooltip_localisation_key); + ret[OV_SNAME(research)] = tr(OV_INAME("TB_TECH_NO_CURRENT")); + ret[OV_SNAME(research_tooltip)] = tr(OV_INAME("TECHNOLOGYVIEW_NO_RESEARCH_TOOLTIP")); } else { - static const String red_prefix_text = GUILabel::get_colour_marker() + String { "R" }; - static const StringName uncivilised_no_research_localisation_key = "unciv_nation"; - static const StringName uncivilised_no_research_tooltip_localisation_key = - "TECHNOLOGYVIEW_NO_RESEARCH_UNCIV_TOOLTIP"; - - ret[research_key] = red_prefix_text + tr(uncivilised_no_research_localisation_key); - ret[research_tooltip_key] = tr(uncivilised_no_research_tooltip_localisation_key); + ret[OV_SNAME(research)] = vformat("%sR%s", GUILabel::get_colour_marker(), tr(OV_INAME("unciv_nation"))); + ret[OV_SNAME(research_tooltip)] = tr(OV_INAME("TECHNOLOGYVIEW_NO_RESEARCH_UNCIV_TOOLTIP")); } - ret[literacy_key] = static_cast(country->get_average_literacy()); + ret[OV_SNAME(literacy)] = static_cast(country->get_average_literacy()); // TODO - set monthly literacy change (test for precision issues) - ret[literacy_change_key] = 0.0f; + ret[OV_INAME("literacy_change")] = 0.0f; - ret[research_points_key] = static_cast(country->get_daily_research_points_untracked()); + ret[OV_INAME("research_points")] = static_cast(country->get_daily_research_points_untracked()); String research_points_tooltip; fixed_point_t daily_base_research_points; for (auto const& [pop_type, research_points] : country->get_research_points_from_pop_types()) { - static const StringName pop_type_research_localisation_key = "TECH_DAILY_RESEARCHPOINTS_TOOLTIP"; static const String pop_type_replace_key = "$POPTYPE$"; static const String fraction_replace_key = "$FRACTION$"; static const String optimal_replace_key = "$OPTIMAL$"; daily_base_research_points += research_points; - research_points_tooltip += tr(pop_type_research_localisation_key).replace( + research_points_tooltip += tr(OV_INAME("TECH_DAILY_RESEARCHPOINTS_TOOLTIP")).replace( pop_type_replace_key, tr(Utilities::std_to_godot_string(pop_type->get_identifier())) ).replace( Utilities::get_long_value_placeholder(), @@ -1112,8 +1015,7 @@ Dictionary MenuSingleton::get_topbar_info() const { // The daily base research points line is guaranteed to be present, but those directly above and below it aren't, // so this line has no newline characters of its own. Instead, potential lines above finish with newlines and // potential (and some guaranteed) lines below start with them. - static const StringName daily_base_research_points_localisation_key = "TECH_DAILY_RESEARCHPOINTS_BASE_TOOLTIP"; - research_points_tooltip += tr(daily_base_research_points_localisation_key).replace( + research_points_tooltip += tr(OV_INAME("TECH_DAILY_RESEARCHPOINTS_BASE_TOOLTIP")).replace( Utilities::get_long_value_placeholder(), Utilities::fixed_point_to_string_dp(daily_base_research_points, 2) ); @@ -1125,15 +1027,13 @@ Dictionary MenuSingleton::get_topbar_info() const { const fixed_point_t research_points_modifier_from_tech = country->get_modifier_effect_value(*modifier_effect_cache.get_increase_research()); if (research_points_modifier_from_tech != fixed_point_t::_0) { - static const StringName from_technology_localisation_key = "FROM_TECHNOLOGY"; - research_points_tooltip += "\n" + tr(from_technology_localisation_key) + ": " + + research_points_tooltip += "\n" + tr(OV_INAME("FROM_TECHNOLOGY")) + ": " + _make_modifier_effect_value_coloured( *modifier_effect_cache.get_increase_research(), research_points_modifier_from_tech, true ); } - static const StringName daily_research_points_localisation_key = "TECH_DAILY_RESEARCHPOINTS_TOTAL_TOOLTIP"; - research_points_tooltip += "\n" + tr(daily_research_points_localisation_key).replace( + research_points_tooltip += "\n" + tr(OV_INAME("TECH_DAILY_RESEARCHPOINTS_TOTAL_TOOLTIP")).replace( Utilities::get_long_value_placeholder(), Utilities::fixed_point_to_string_dp(country->get_daily_research_points_untracked(), 2) ); @@ -1141,13 +1041,12 @@ Dictionary MenuSingleton::get_topbar_info() const { // In the base game this section is only shown when no research is set, but it's useful to show it always research_points_tooltip += "\n" + get_tooltip_separator(); - static const StringName accumulated_research_points_localisation_key = "RP_ACCUMULATED"; - research_points_tooltip += tr(accumulated_research_points_localisation_key).replace( + research_points_tooltip += tr(OV_INAME("RP_ACCUMULATED")).replace( Utilities::get_short_value_placeholder(), Utilities::fixed_point_to_string_dp(country->get_research_point_stockpile_untracked(), 1) ); - ret[research_points_tooltip_key] = std::move(research_points_tooltip); + ret[OV_INAME("research_points_tooltip")] = std::move(research_points_tooltip); } // Politics @@ -1159,42 +1058,31 @@ Dictionary MenuSingleton::get_topbar_info() const { // Diplomacy // Military - static const StringName regiment_count_key = "regiment_count"; - static const StringName max_supported_regiments_key = "max_supported_regiments"; - - ret[regiment_count_key] = static_cast(country->get_regiment_count()); - ret[max_supported_regiments_key] = static_cast(country->get_max_supported_regiment_count()); - - static const StringName is_mobilised_key = "is_mobilised"; - static const StringName mobilisation_regiments_key = "mobilisation_regiments"; - static const StringName mobilisation_impact_tooltip_key = "mobilisation_impact_tooltip"; + ret[OV_INAME("regiment_count")] = static_cast(country->get_regiment_count()); + ret[OV_INAME("max_supported_regiments")] = static_cast(country->get_max_supported_regiment_count()); if (country->is_mobilised()) { - ret[is_mobilised_key] = true; + ret[OV_SNAME(is_mobilised)] = true; } else { - ret[mobilisation_regiments_key] = static_cast(country->get_mobilisation_potential_regiment_count()); - ret[mobilisation_impact_tooltip_key] = _make_mobilisation_impact_tooltip(); + ret[OV_INAME("mobilisation_regiments")] = static_cast(country->get_mobilisation_potential_regiment_count()); + ret[OV_SNAME(mobilisation_impact_tooltip)] = _make_mobilisation_impact_tooltip(); } { - static const StringName leadership_key = "leadership"; - static const StringName leadership_tooltip_key = "leadership_tooltip"; - - ret[leadership_key] = country->get_leadership_point_stockpile().truncate(); + ret[OV_SNAME(leadership)] = country->get_leadership_point_stockpile().truncate(); String leadership_tooltip; fixed_point_t monthly_base_leadership_points; for (auto const& [pop_type, leadership_points] : country->get_leadership_points_from_pop_types()) { - static const StringName pop_type_leadership_localisation_key = "TECH_DAILY_LEADERSHIP_TOOLTIP"; static const String pop_type_replace_key = "$POPTYPE$"; static const String fraction_replace_key = "$FRACTION$"; static const String optimal_replace_key = "$OPTIMAL$"; monthly_base_leadership_points += leadership_points; - leadership_tooltip += tr(pop_type_leadership_localisation_key).replace( + leadership_tooltip += tr(OV_INAME("TECH_DAILY_LEADERSHIP_TOOLTIP")).replace( pop_type_replace_key, tr(Utilities::std_to_godot_string(pop_type->get_identifier())) ).replace( Utilities::get_long_value_placeholder(), @@ -1217,8 +1105,7 @@ Dictionary MenuSingleton::get_topbar_info() const { // The monthly base leadership points line is guaranteed to be present, but those directly above and below it aren't, // so this line has no newline characters of its own. Instead, potential lines above finish with newlines and // potential (and some guaranteed) lines below start with them. - static const StringName monthly_base_leadership_localisation_key = "TECH_DAILY_LEADERSHIP_BASE_TOOLTIP"; - leadership_tooltip += tr(monthly_base_leadership_localisation_key).replace( + leadership_tooltip += tr(OV_INAME("TECH_DAILY_LEADERSHIP_BASE_TOOLTIP")).replace( Utilities::get_long_value_placeholder(), Utilities::fixed_point_to_string_dp(monthly_base_leadership_points, 2) ); @@ -1227,8 +1114,7 @@ Dictionary MenuSingleton::get_topbar_info() const { *country, *modifier_effect_cache.get_leadership_modifier() ); - static const StringName monthly_leadership_points_localisation_key = "TECH_DAILY_LEADERSHIP_TOTAL_TOOLTIP"; - leadership_tooltip += "\n" + tr(monthly_leadership_points_localisation_key).replace( + leadership_tooltip += "\n" + tr(OV_INAME("TECH_DAILY_LEADERSHIP_TOTAL_TOOLTIP")).replace( Utilities::get_long_value_placeholder(), Utilities::fixed_point_to_string_dp(country->get_monthly_leadership_points(), 2) ); @@ -1238,14 +1124,13 @@ Dictionary MenuSingleton::get_topbar_info() const { if (country->get_leadership_point_stockpile() >= max_leadership_point_stockpile) { leadership_tooltip += "\n" + get_tooltip_separator() + "\n"; - static const StringName max_leadership_points_localisation_key = "TOPBAR_LEADERSHIP_MAX"; static const String max_replace_key = "$MAX$"; - leadership_tooltip += tr(max_leadership_points_localisation_key).trim_suffix("\n").replace( + leadership_tooltip += tr(OV_INAME("TOPBAR_LEADERSHIP_MAX")).trim_suffix("\n").replace( max_replace_key, Utilities::fixed_point_to_string_dp(max_leadership_point_stockpile, 1) ); } - ret[leadership_tooltip_key] = std::move(leadership_tooltip); + ret[OV_INAME("leadership_tooltip")] = std::move(leadership_tooltip); } return ret; diff --git a/extension/src/openvic-extension/singletons/MilitaryMenu.cpp b/extension/src/openvic-extension/singletons/MilitaryMenu.cpp index a6870450..f5aba93a 100644 --- a/extension/src/openvic-extension/singletons/MilitaryMenu.cpp +++ b/extension/src/openvic-extension/singletons/MilitaryMenu.cpp @@ -6,6 +6,7 @@ #include #include "openvic-extension/classes/GUINode.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/singletons/PlayerSingleton.hpp" @@ -38,10 +39,8 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { } static const StringName military_info_leader_id_key = "leader_id"; - static const StringName military_info_leader_branch_key = "leader_branch"; static const StringName military_info_leader_name_key = "leader_name"; static const StringName military_info_leader_picture_key = "leader_picture"; - static const StringName military_info_leader_prestige_key = "leader_prestige"; static const StringName military_info_leader_prestige_tooltip_key = "leader_prestige_tooltip"; static const StringName military_info_leader_background_key = "leader_background"; static const StringName military_info_leader_personality_key = "leader_personality"; @@ -60,13 +59,13 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { { // Generic data leader_dict[military_info_leader_id_key] = leader.get_unique_id(); - leader_dict[military_info_leader_branch_key] = static_cast(leader.get_branch()); + leader_dict[OV_INAME("leader_branch")] = static_cast(leader.get_branch()); leader_dict[military_info_leader_can_be_used_key] = leader.get_can_be_used(); UnitInstanceGroup const* group = leader.get_unit_instance_group(); if (group != nullptr) { - leader_dict[military_info_leader_assignment_key] = Utilities::std_to_godot_string(group->get_name()); + leader_dict[OV_INAME("leader_assignment")] = Utilities::std_to_godot_string(group->get_name()); ProvinceInstance const* location = group->get_position(); if (location != nullptr) { @@ -144,7 +143,7 @@ Dictionary MenuSingleton::make_leader_dict(LeaderInstance const& leader) { _make_modifier_effect_value_coloured(organisation_effect, modifier_value.get_effect(organisation_effect), true) ); - leader_dict[military_info_leader_prestige_key] = static_cast(prestige); + leader_dict[OV_INAME("leader_prestige")] = static_cast(prestige); leader_dict[military_info_leader_prestige_tooltip_key] = std::move(prestige_tooltip); } @@ -213,13 +212,10 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched static const StringName military_info_unit_group_leader_tooltip_key = "unit_group_leader_tooltip"; static const StringName military_info_unit_group_name_key = "unit_group_name"; static const StringName military_info_unit_group_location_key = "unit_group_location"; - static const StringName military_info_unit_group_unit_count_key = "unit_group_unit_count"; static const StringName military_info_unit_group_men_count_key = "unit_group_men_count"; // armies only static const StringName military_info_unit_group_max_men_count_key = "unit_group_max_men_count"; // armies only static const StringName military_info_unit_group_organisation_key = "unit_group_organisation"; - static const StringName military_info_unit_group_strength_key = "unit_group_strength"; static const StringName military_info_unit_group_moving_tooltip_key = "unit_group_moving_tooltip"; - static const StringName military_info_unit_group_dig_in_tooltip_key = "unit_group_dig_in_tooltip"; // armies only static const StringName military_info_unit_group_combat_key = "unit_group_combat"; using enum unit_branch_t; @@ -243,10 +239,10 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched unit_group_dict[military_info_unit_group_location_key] = Utilities::std_to_godot_string(unit_group.get_position()->get_identifier()); } - unit_group_dict[military_info_unit_group_unit_count_key] = static_cast(unit_group.get_unit_count()); + unit_group_dict[OV_INAME("unit_group_unit_count")] = static_cast(unit_group.get_unit_count()); unit_group_dict[military_info_unit_group_organisation_key] = static_cast(unit_group.get_organisation_proportion()); - unit_group_dict[military_info_unit_group_strength_key] = static_cast(unit_group.get_strength_proportion()); + unit_group_dict[OV_INAME("unit_group_strength")] = static_cast(unit_group.get_strength_proportion()); if (unit_group.is_moving()) { static const StringName moving_localisation_key = "MILITARY_MOVING_TOOLTIP"; @@ -271,10 +267,9 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched const ArmyInstance::dig_in_level_t dig_in_level = unit_group.get_dig_in_level(); if (dig_in_level > 0) { - static const StringName dig_in_localisation_key = "MILITARY_DIGIN_TOOLTIP"; static const String moving_days_replace_key = "$DAYS$"; - unit_group_dict[military_info_unit_group_dig_in_tooltip_key] = tr(dig_in_localisation_key).replace( + unit_group_dict[OV_INAME("unit_group_dig_in_tooltip")] = tr(OV_INAME("MILITARY_DIGIN_TOOLTIP")).replace( moving_days_replace_key, String::num_uint64(dig_in_level) ); } @@ -291,10 +286,8 @@ Dictionary MenuSingleton::make_unit_group_dict(UnitInstanceGroupBranched Dictionary MenuSingleton::make_in_progress_unit_dict() const { static const StringName military_info_unit_progress_key = "unit_progress"; static const StringName military_info_unit_icon_key = "unit_icon"; - static const StringName military_info_unit_name_key = "unit_name"; static const StringName military_info_unit_location_key = "unit_location"; static const StringName military_info_unit_eta_key = "unit_eta"; - static const StringName military_info_unit_tooltip_key = "unit_tooltip"; DefinitionManager const& definition_manager = GameSingleton::get_singleton()->get_definition_manager(); GoodDefinitionManager const& good_definition_manager = @@ -325,7 +318,7 @@ Dictionary MenuSingleton::make_in_progress_unit_dict() const { in_progress_unit_dict[military_info_unit_progress_key] = static_cast(progress); in_progress_unit_dict[military_info_unit_icon_key] = unit_type->get_icon(); - in_progress_unit_dict[military_info_unit_name_key] = Utilities::std_to_godot_string(unit_type->get_identifier()); + in_progress_unit_dict[OV_INAME("unit_name")] = Utilities::std_to_godot_string(unit_type->get_identifier()); if (location != nullptr) { in_progress_unit_dict[military_info_unit_location_key] = Utilities::std_to_godot_string(location->get_identifier()); } @@ -343,7 +336,7 @@ Dictionary MenuSingleton::make_in_progress_unit_dict() const { if (!tooltip.is_empty()) { static const StringName gathering_goods_localisation_key = "GOODS_PROJECT_LACK_GOODS"; - in_progress_unit_dict[military_info_unit_tooltip_key] = tr(gathering_goods_localisation_key) + tooltip; + in_progress_unit_dict[OV_INAME("unit_tooltip")] = tr(gathering_goods_localisation_key) + tooltip; } return in_progress_unit_dict; @@ -374,7 +367,6 @@ Dictionary MenuSingleton::get_military_menu_info() { static const StringName military_info_supply_consumption_tooltip_key = "supply_consumption_tooltip"; static const StringName military_info_organisation_regain_key = "organisation_regain"; static const StringName military_info_organisation_regain_tooltip_key = "organisation_regain_tooltip"; - static const StringName military_info_land_organisation_key = "land_organisation"; static const StringName military_info_land_organisation_tooltip_key = "land_organisation_tooltip"; static const StringName military_info_naval_organisation_key = "naval_organisation"; static const StringName military_info_naval_organisation_tooltip_key = "naval_organisation_tooltip"; @@ -441,7 +433,7 @@ Dictionary MenuSingleton::get_military_menu_info() { ret[military_info_organisation_regain_tooltip_key] = std::move(organisation_regain_tooltip); } - ret[military_info_land_organisation_key] = static_cast(country->get_land_organisation()); + ret[OV_INAME("land_organisation")] = static_cast(country->get_land_organisation()); ret[military_info_land_organisation_tooltip_key] = base_value_percent_tooltip + _make_modifier_effect_contributions_tooltip(*country, *modifier_effect_cache.get_land_organisation()); @@ -503,18 +495,10 @@ Dictionary MenuSingleton::get_military_menu_info() { ret[military_info_military_tactics_key] = static_cast(country->get_military_tactics()); // Mobilisation - static const StringName military_info_is_mobilised_key = "is_mobilised"; - static const StringName military_info_mobilisation_progress_key = "mobilisation_progress"; - static const StringName military_info_mobilisation_size_key = "mobilisation_size"; - static const StringName military_info_mobilisation_size_tooltip_key = "mobilisation_size_tooltip"; - static const StringName military_info_mobilisation_impact_tooltip_key = "mobilisation_impact_tooltip"; - static const StringName military_info_mobilisation_economy_impact_key = "mobilisation_economy_impact"; - static const StringName military_info_mobilisation_economy_impact_tooltip_key = "mobilisation_economy_impact_tooltip"; - - ret[military_info_is_mobilised_key] = country->is_mobilised(); + ret[OV_SNAME(is_mobilised)] = country->is_mobilised(); // TODO - get mobilisation progress from SIM - // ret[military_info_mobilisation_progress_key] = static_cast(country->get_mobilisation_progress()); - ret[military_info_mobilisation_size_key] = static_cast(country->get_mobilisation_potential_regiment_count()); + // ret[OV_INAME("mobilisation_progress")] = static_cast(country->get_mobilisation_progress()); + ret[OV_INAME("mobilisation_size")] = static_cast(country->get_mobilisation_potential_regiment_count()); { static const StringName mobilisation_size_tooltip_localisation_key = "MOB_SIZE_IRO"; @@ -547,14 +531,14 @@ Dictionary MenuSingleton::get_military_menu_info() { *country, *modifier_effect_cache.get_mobilisation_size_country() ); - ret[military_info_mobilisation_size_tooltip_key] = std::move(military_info_mobilisation_size_tooltip); + ret[OV_INAME("mobilisation_size_tooltip")] = std::move(military_info_mobilisation_size_tooltip); } if (!country->is_mobilised()) { - ret[military_info_mobilisation_impact_tooltip_key] = _make_mobilisation_impact_tooltip(); + ret[OV_SNAME(mobilisation_impact_tooltip)] = _make_mobilisation_impact_tooltip(); } - ret[military_info_mobilisation_economy_impact_key] = static_cast(country->get_mobilisation_economy_impact()); + ret[OV_INAME("mobilisation_economy_impact")] = static_cast(country->get_mobilisation_economy_impact()); { String mobilisation_economy_impact_tooltip = _make_modifier_effect_contributions_tooltip( @@ -584,7 +568,7 @@ Dictionary MenuSingleton::get_military_menu_info() { mobilisation_economy_impact_tooltip = mobilisation_economy_impact_tooltip.substr(1); } - ret[military_info_mobilisation_economy_impact_tooltip_key] = mobilisation_economy_impact_tooltip; + ret[OV_INAME("mobilisation_economy_impact_tooltip")] = mobilisation_economy_impact_tooltip; } // Leaders diff --git a/extension/src/openvic-extension/singletons/ModelSingleton.cpp b/extension/src/openvic-extension/singletons/ModelSingleton.cpp index e942e619..abc67fe1 100644 --- a/extension/src/openvic-extension/singletons/ModelSingleton.cpp +++ b/extension/src/openvic-extension/singletons/ModelSingleton.cpp @@ -8,6 +8,7 @@ #include #include +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/core/Bind.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -102,13 +103,10 @@ Dictionary ModelSingleton::get_animation_dict(GFX::Actor::Animation const& anima return it->second; } - static const StringName file_key = "file"; - static const StringName time_key = "time"; - Dictionary dict; - dict[file_key] = Utilities::std_to_godot_string(animation.get_file()); - dict[time_key] = static_cast(animation.get_scroll_time()); + dict[OV_SNAME(file)] = Utilities::std_to_godot_string(animation.get_file()); + dict[OV_SNAME(time)] = static_cast(animation.get_scroll_time()); animation_cache.emplace(&animation, dict); @@ -121,17 +119,10 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) { return it->second; } - static const StringName file_key = "file"; - static const StringName scale_key = "scale"; - static const StringName idle_key = "idle"; - static const StringName move_key = "move"; - static const StringName attack_key = "attack"; - static const StringName attachments_key = "attachments"; - Dictionary dict; - dict[file_key] = Utilities::std_to_godot_string(actor.get_model_file()); - dict[scale_key] = static_cast(actor.get_scale()); + dict[OV_SNAME(file)] = Utilities::std_to_godot_string(actor.get_model_file()); + dict[OV_SNAME(scale)] = static_cast(actor.get_scale()); const auto set_animation = [this, &dict](StringName const& key, std::optional const& animation) { if (animation.has_value()) { @@ -139,16 +130,13 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) { } }; - set_animation(idle_key, actor.get_idle_animation()); - set_animation(move_key, actor.get_move_animation()); - set_animation(attack_key, actor.get_attack_animation()); + set_animation(OV_SNAME(idle), actor.get_idle_animation()); + set_animation(OV_SNAME(move), actor.get_move_animation()); + set_animation(OV_SNAME(attack), actor.get_attack_animation()); std::span attachments = actor.get_attachments(); if (!attachments.empty()) { - static const StringName attachment_node_key = "node"; - static const StringName attachment_model_key = "model"; - TypedArray attachments_array; if (attachments_array.resize(attachments.size()) == OK) { @@ -169,15 +157,15 @@ Dictionary ModelSingleton::get_model_dict(GFX::Actor const& actor) { Dictionary attachment_dict; - attachment_dict[attachment_node_key] = Utilities::std_to_godot_string(attachment.get_attach_node()); - attachment_dict[attachment_model_key] = get_model_dict(*attachment_actor); + attachment_dict[OV_SNAME(node)] = Utilities::std_to_godot_string(attachment.get_attach_node()); + attachment_dict[OV_SNAME(model)] = get_model_dict(*attachment_actor); attachments_array[idx] = std::move(attachment_dict); } if (!attachments_array.is_empty()) { - dict[attachments_key] = std::move(attachments_array); + dict[OV_SNAME(attachments)] = std::move(attachments_array); } } else { @@ -204,18 +192,6 @@ bool ModelSingleton::add_unit_dict( GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, false); - static const StringName culture_key = "culture"; - static const StringName model_key = "model"; - static const StringName mount_model_key = "mount_model"; - static const StringName mount_attach_node_key = "mount_attach_node"; - static const StringName flag_index_key = "flag_index"; - static const StringName flag_floating_key = "flag_floating"; - static const StringName position_key = "position"; - static const StringName rotation_key = "rotation"; - static const StringName primary_colour_key = "primary_colour"; - static const StringName secondary_colour_key = "secondary_colour"; - static const StringName tertiary_colour_key = "tertiary_colour"; - if (units.empty()) { return true; } @@ -279,16 +255,16 @@ bool ModelSingleton::add_unit_dict( Dictionary dict; - dict[culture_key] = Utilities::std_to_godot_string(graphical_culture_type.get_identifier()); + dict[OV_SNAME(culture)] = Utilities::std_to_godot_string(graphical_culture_type.get_identifier()); - dict[model_key] = get_model_dict(*actor); + dict[OV_SNAME(model)] = get_model_dict(*actor); if (!mount_actor_name.empty() && !mount_attach_node_name.empty()) { GFX::Actor const* mount_actor = get_actor(mount_actor_name); if (mount_actor != nullptr) { - dict[mount_model_key] = get_model_dict(*mount_actor); - dict[mount_attach_node_key] = Utilities::std_to_godot_string(mount_attach_node_name); + dict[OV_INAME("mount_model")] = get_model_dict(*mount_actor); + dict[OV_INAME("mount_attach_node")] = Utilities::std_to_godot_string(mount_attach_node_name); } else { UtilityFunctions::push_error(Utilities::format( "Failed to find \"%s\" mount actor of graphical culture type \"%s\" for unit \"%s\"", @@ -301,22 +277,22 @@ bool ModelSingleton::add_unit_dict( } // TODO - government type based flag type - dict[flag_index_key] = game_singleton->get_flag_sheet_index(country_definition.get_index(), {}); + dict[OV_INAME("flag_index")] = game_singleton->get_flag_sheet_index(country_definition.get_index(), {}); if (display_unit_type->has_floating_flag()) { - dict[flag_floating_key] = true; + dict[OV_INAME("flag_floating")] = true; } - dict[position_key] = + dict[OV_SNAME(position)] = game_singleton->normalise_map_position(unit.get_position()->get_province_definition().get_unit_position()); if (display_unit_type->get_unit_category() != UnitType::unit_category_t::INFANTRY) { - dict[rotation_key] = -0.25f * std::numbers::pi_v; + dict[OV_SNAME(rotation)] = -0.25f * std::numbers::pi_v; } - dict[primary_colour_key] = Utilities::to_godot_color(country_definition.get_primary_unit_colour()); - dict[secondary_colour_key] = Utilities::to_godot_color(country_definition.get_secondary_unit_colour()); - dict[tertiary_colour_key] = Utilities::to_godot_color(country_definition.get_tertiary_unit_colour()); + dict[OV_SNAME(primary_colour)] = Utilities::to_godot_color(country_definition.get_primary_unit_colour()); + dict[OV_SNAME(secondary_colour)] = Utilities::to_godot_color(country_definition.get_secondary_unit_colour()); + dict[OV_SNAME(tertiary_colour)] = Utilities::to_godot_color(country_definition.get_tertiary_unit_colour()); // TODO - move dict into unit_array ? unit_array.push_back(dict); @@ -392,10 +368,6 @@ bool ModelSingleton::add_building_dict( GameSingleton const* game_singleton = GameSingleton::get_singleton(); ERR_FAIL_NULL_V(game_singleton, false); - static const StringName model_key = "model"; - static const StringName position_key = "position"; - static const StringName rotation_key = "rotation"; - std::string suffix; if ( @@ -444,14 +416,14 @@ bool ModelSingleton::add_building_dict( Dictionary dict; - dict[model_key] = get_model_dict(*actor); + dict[OV_SNAME(model)] = get_model_dict(*actor); - dict[position_key] = game_singleton->normalise_map_position( + dict[OV_SNAME(position)] = game_singleton->normalise_map_position( position_ptr != nullptr ? *position_ptr : province_definition.get_centre() ); if (rotation != 0.0f) { - dict[rotation_key] = rotation; + dict[OV_SNAME(rotation)] = rotation; } // TODO - move dict into unit_array ? diff --git a/extension/src/openvic-extension/singletons/PlayerSingleton.cpp b/extension/src/openvic-extension/singletons/PlayerSingleton.cpp index a0e32c8b..5b96880b 100644 --- a/extension/src/openvic-extension/singletons/PlayerSingleton.cpp +++ b/extension/src/openvic-extension/singletons/PlayerSingleton.cpp @@ -4,6 +4,7 @@ #include #include "openvic-extension/classes/GUIScrollbar.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/singletons/MenuSingleton.hpp" #include "openvic-extension/core/Bind.hpp" @@ -15,8 +16,7 @@ using namespace godot; /* StringNames cannot be constructed until Godot has called StringName::setup(), * so we must use these wrapper functions to delay their initialisation. */ StringName const& PlayerSingleton::_signal_province_selected() { - static const StringName signal_province_selected = "province_selected"; - return signal_province_selected; + return OV_SNAME(province_selected); } void PlayerSingleton::_bind_methods() { diff --git a/extension/src/openvic-extension/singletons/PopulationMenu.cpp b/extension/src/openvic-extension/singletons/PopulationMenu.cpp index 761b5edc..c88fc908 100644 --- a/extension/src/openvic-extension/singletons/PopulationMenu.cpp +++ b/extension/src/openvic-extension/singletons/PopulationMenu.cpp @@ -14,6 +14,7 @@ #include "openvic-extension/classes/GFXPieChartTexture.hpp" #include "openvic-extension/classes/GUINode.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/utility/MapHelpers.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -81,15 +82,6 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int ); ERR_FAIL_COND_V_MSG(count <= 0, {}, Utilities::format("Invalid count for population menu province list rows: %d", count)); - static const StringName type_key = "type"; - static const StringName index_key = "index"; - static const StringName name_key = "name"; - static const StringName size_key = "size"; - static const StringName change_key = "change"; - static const StringName selected_key = "selected"; - /* State-only keys */ - static const StringName expanded_key = "expanded"; - static const StringName colonial_status_key = "colony"; // TODO - national focus struct entry_visitor_t { @@ -113,12 +105,12 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int if (start_counter-- <= 0) { Dictionary country_dict; - country_dict[type_key] = LIST_ENTRY_COUNTRY; - country_dict[index_key] = index; - country_dict[name_key] = Utilities::get_country_name(menu_singleton, country_entry.country); - country_dict[size_key] = country_entry.country.get_total_population(); - country_dict[change_key] = 0; - country_dict[selected_key] = country_entry.selected; + country_dict[OV_SNAME(type)] = LIST_ENTRY_COUNTRY; + country_dict[OV_SNAME(index)] = index; + country_dict[OV_SNAME(name)] = Utilities::get_country_name(menu_singleton, country_entry.country); + country_dict[OV_SNAME(size)] = country_entry.country.get_total_population(); + country_dict[OV_SNAME(change)] = 0; + country_dict[OV_SNAME(selected)] = country_entry.selected; array.push_back(country_dict); @@ -134,14 +126,14 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int if (start_counter-- <= 0) { Dictionary state_dict; - state_dict[type_key] = LIST_ENTRY_STATE; - state_dict[index_key] = index; - state_dict[name_key] = Utilities::get_state_name(menu_singleton, state_entry.state); - state_dict[size_key] = state_entry.state.get_total_population(); - state_dict[change_key] = 0; - state_dict[selected_key] = state_entry.selected; - state_dict[expanded_key] = state_entry.expanded; - state_dict[colonial_status_key] = false; + state_dict[OV_SNAME(type)] = LIST_ENTRY_STATE; + state_dict[OV_SNAME(index)] = index; + state_dict[OV_SNAME(name)] = Utilities::get_state_name(menu_singleton, state_entry.state); + state_dict[OV_SNAME(size)] = state_entry.state.get_total_population(); + state_dict[OV_SNAME(change)] = 0; + state_dict[OV_SNAME(selected)] = state_entry.selected; + state_dict[OV_INAME("expanded")] = state_entry.expanded; + state_dict[OV_INAME("colony")] = false; array.push_back(state_dict); @@ -155,12 +147,12 @@ TypedArray MenuSingleton::get_population_menu_province_list_rows(int if (is_expanded && start_counter-- <= 0) { Dictionary province_dict; - province_dict[type_key] = LIST_ENTRY_PROVINCE; - province_dict[index_key] = index; - province_dict[name_key] = Utilities::std_to_godot_string(province_entry.province.get_identifier()); - province_dict[size_key] = province_entry.province.get_total_population(); - province_dict[change_key] = 0; - province_dict[selected_key] = province_entry.selected; + province_dict[OV_SNAME(type)] = LIST_ENTRY_PROVINCE; + province_dict[OV_SNAME(index)] = index; + province_dict[OV_SNAME(name)] = Utilities::std_to_godot_string(province_entry.province.get_identifier()); + province_dict[OV_SNAME(size)] = province_entry.province.get_total_population(); + province_dict[OV_SNAME(change)] = 0; + province_dict[OV_SNAME(selected)] = province_entry.selected; array.push_back(province_dict); @@ -738,55 +730,33 @@ TypedArray MenuSingleton::get_population_menu_pop_rows(int32_t start count = population_menu.filtered_pops.size() - start; } - static const StringName pop_size_key = "size"; - - static const StringName pop_type_icon_key = "pop_type_icon"; // TODO - pop type name // TODO - promotions (target pop type and count) // TODO - demotions (target pop type and count) // TODO - good being produced (artisans, farmers, labourers, slaves) // TODO - military unit and army (soldiers) - static const StringName pop_culture_key = "culture"; // TODO - cultural assimilation (primary/accepted, or number, target culture, and conditional weights breakdown) - static const StringName pop_religion_icon_key = "religion_icon"; // TODO - religion name // TODO - religious conversion (accepted, or number, target religion, and conditional weights breakdown) - static const StringName pop_location_key = "location"; // TODO - internal, external and colonial migration - static const StringName pop_militancy_key = "militancy"; // TODO - monthly militancy change and modifier breakdown - static const StringName pop_consciousness_key = "consciousness"; // TODO - monthly consciousness change and modifier breakdown - static const StringName pop_ideology_key = "ideology"; - - static const StringName pop_issues_key = "issues"; - - static const StringName pop_unemployment_key = "unemployment"; - - static const StringName pop_cash_key = "cash"; - static const StringName pop_daily_money_key = "daily_money"; // TODO - daily income, needs, salary and savings - static const StringName pop_life_needs_key = "life_needs"; - static const StringName pop_everyday_needs_key = "everyday_needs"; - static const StringName pop_luxury_needs_key = "luxury_needs"; // TODO - goods not available on market or goods not affordale + price (for all 3 needs types) - static const StringName pop_rebel_icon_key = "rebel_icon"; // TODO - rebel faction name/description // TODO - icons for social/political reform movements // TODO - flags for country-related rebels - static const StringName pop_size_change_key = "size_change"; // TODO - size change breakdown - static const StringName pop_literacy_key = "literacy"; // TODO - monthly change TypedArray array; @@ -796,30 +766,30 @@ TypedArray MenuSingleton::get_population_menu_pop_rows(int32_t start Pop const* pop = population_menu.filtered_pops[start + idx]; Dictionary pop_dict; - pop_dict[pop_size_key] = pop->get_size(); - pop_dict[pop_type_icon_key] = pop->get_type()->get_sprite(); - pop_dict[pop_culture_key] = Utilities::std_to_godot_string(pop->get_culture().get_identifier()); - pop_dict[pop_religion_icon_key] = pop->get_religion().get_icon(); + pop_dict[OV_SNAME(size)] = pop->get_size(); + pop_dict[OV_INAME("pop_type_icon")] = pop->get_type()->get_sprite(); + pop_dict[OV_SNAME(culture)] = Utilities::std_to_godot_string(pop->get_culture().get_identifier()); + pop_dict[OV_INAME("religion_icon")] = pop->get_religion().get_icon(); if (pop->get_location() != nullptr) { - pop_dict[pop_location_key] = Utilities::std_to_godot_string(pop->get_location()->get_identifier()); + pop_dict[OV_INAME("location")] = Utilities::std_to_godot_string(pop->get_location()->get_identifier()); } - pop_dict[pop_militancy_key] = static_cast(pop->get_militancy()); - pop_dict[pop_consciousness_key] = static_cast(pop->get_consciousness()); - pop_dict[pop_ideology_key] = generate_population_menu_pop_row_pie_chart_data(pop->get_supporter_equivalents_by_ideology()); - pop_dict[pop_issues_key] = generate_population_menu_pop_row_pie_chart_data( + pop_dict[OV_INAME("militancy")] = static_cast(pop->get_militancy()); + pop_dict[OV_INAME("consciousness")] = static_cast(pop->get_consciousness()); + pop_dict[OV_INAME("ideology")] = generate_population_menu_pop_row_pie_chart_data(pop->get_supporter_equivalents_by_ideology()); + pop_dict[OV_SNAME(issues)] = generate_population_menu_pop_row_pie_chart_data( pop->get_supporter_equivalents_by_issue(), get_issue_identifier_suffix() ); - pop_dict[pop_unemployment_key] = static_cast(pop->get_unemployment_fraction()); - pop_dict[pop_cash_key] = static_cast(pop->get_cash().get_copy_of_value()); - pop_dict[pop_daily_money_key] = static_cast(pop->get_income()); - pop_dict[pop_life_needs_key] = static_cast(pop->get_life_needs_fulfilled()); - pop_dict[pop_everyday_needs_key] = static_cast(pop->get_everyday_needs_fulfilled()); - pop_dict[pop_luxury_needs_key] = static_cast(pop->get_luxury_needs_fulfilled()); + pop_dict[OV_INAME("unemployment")] = static_cast(pop->get_unemployment_fraction()); + pop_dict[OV_INAME("cash")] = static_cast(pop->get_cash().get_copy_of_value()); + pop_dict[OV_INAME("daily_money")] = static_cast(pop->get_income()); + pop_dict[OV_INAME("life_needs")] = static_cast(pop->get_life_needs_fulfilled()); + pop_dict[OV_INAME("everyday_needs")] = static_cast(pop->get_everyday_needs_fulfilled()); + pop_dict[OV_INAME("luxury_needs")] = static_cast(pop->get_luxury_needs_fulfilled()); if (pop->get_rebel_type() != nullptr) { - pop_dict[pop_rebel_icon_key] = pop->get_rebel_type()->get_icon(); + pop_dict[OV_INAME("rebel_icon")] = pop->get_rebel_type()->get_icon(); } - pop_dict[pop_size_change_key] = pop->get_total_change(); - pop_dict[pop_literacy_key] = static_cast(pop->get_literacy()); + pop_dict[OV_INAME("size_change")] = pop->get_total_change(); + pop_dict[OV_SNAME(literacy)] = static_cast(pop->get_literacy()); array[idx] = std::move(pop_dict); } @@ -861,7 +831,6 @@ PackedInt32Array MenuSingleton::get_population_menu_pop_filter_setup_info() { TypedArray MenuSingleton::get_population_menu_pop_filter_info() const { static const StringName pop_filter_count_key = "count"; - static const StringName pop_filter_change_key = "change"; static const StringName pop_filter_selected_key = "selected"; TypedArray array; @@ -873,7 +842,7 @@ TypedArray MenuSingleton::get_population_menu_pop_filter_info() cons Dictionary filter_dict; filter_dict[pop_filter_count_key] = filter.count; - filter_dict[pop_filter_change_key] = filter.promotion_demotion_change; + filter_dict[OV_SNAME(change)] = filter.promotion_demotion_change; filter_dict[pop_filter_selected_key] = filter.selected; array[idx] = std::move(filter_dict); diff --git a/extension/src/openvic-extension/singletons/TradeMenu.cpp b/extension/src/openvic-extension/singletons/TradeMenu.cpp index 50e602e6..2f60d589 100644 --- a/extension/src/openvic-extension/singletons/TradeMenu.cpp +++ b/extension/src/openvic-extension/singletons/TradeMenu.cpp @@ -4,6 +4,7 @@ #include "openvic-extension/classes/GUILabel.hpp" #include "openvic-extension/classes/GUIScrollbar.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/singletons/PlayerSingleton.hpp" #include "openvic-extension/utility/Utilities.hpp" @@ -117,7 +118,6 @@ Dictionary MenuSingleton::get_trade_menu_trade_details_info( static const StringName trade_detail_slider_amount_key = "trade_detail_slider_amount"; // exponential good amount static const StringName trade_detail_government_needs_key = "trade_detail_government_needs"; static const StringName trade_detail_army_needs_key = "trade_detail_army_needs"; - static const StringName trade_detail_navy_needs_key = "trade_detail_navy_needs"; static const StringName trade_detail_overseas_needs_key = "trade_detail_overseas_needs"; static const StringName trade_detail_factory_needs_key = "trade_detail_factory_needs"; static const StringName trade_detail_pop_needs_key = "trade_detail_pop_needs"; @@ -174,7 +174,7 @@ Dictionary MenuSingleton::get_trade_menu_trade_details_info( ret[trade_detail_slider_amount_key] = static_cast(good_data.stockpile_cutoff); ret[trade_detail_government_needs_key] = static_cast(good_data.government_needs); ret[trade_detail_army_needs_key] = static_cast(good_data.army_needs); - ret[trade_detail_navy_needs_key] = static_cast(good_data.navy_needs); + ret[OV_INAME("trade_detail_navy_needs")] = static_cast(good_data.navy_needs); ret[trade_detail_overseas_needs_key] = static_cast(good_data.overseas_maintenance); ret[trade_detail_factory_needs_key] = static_cast(good_data.factory_demand); ret[trade_detail_pop_needs_key] = static_cast(good_data.pop_demand); diff --git a/extension/src/openvic-extension/utility/UITools.cpp b/extension/src/openvic-extension/utility/UITools.cpp index 428715c6..c2bc35c1 100644 --- a/extension/src/openvic-extension/utility/UITools.cpp +++ b/extension/src/openvic-extension/utility/UITools.cpp @@ -40,6 +40,7 @@ #include "openvic-extension/classes/GUIPieChart.hpp" #include "openvic-extension/classes/GUIProgressBar.hpp" #include "openvic-extension/classes/GUIScrollbar.hpp" +#include "openvic-extension/core/StaticString.hpp" #include "openvic-extension/singletons/AssetManager.hpp" #include "openvic-extension/singletons/GameSingleton.hpp" #include "openvic-extension/singletons/SoundSingleton.hpp" @@ -431,7 +432,6 @@ static bool generate_button(generate_gui_args_t&& args) { gui_button->set_shortcut_in_tooltip(false); if (clicksound && !clicksound->get_file().empty()) { - static const StringName sfx_bus = "SFX_BUS"; static auto gui_pressed = [](GUIButton* button, String const& file, float volume) { static auto on_audio_finished = [](AudioStreamPlayer* stream) { stream->queue_free(); @@ -441,8 +441,8 @@ static bool generate_button(generate_gui_args_t&& args) { if (audio_stream.is_valid()) { AudioStreamPlayer* asp = memnew(AudioStreamPlayer); asp->connect("finished", callable_mp_static(+on_audio_finished).bind(asp)); - if (AudioServer::get_singleton()->get_bus_index(sfx_bus) != -1) { - asp->set_bus(sfx_bus); + if (AudioServer::get_singleton()->get_bus_index(OV_SNAME(SFX_BUS)) != -1) { + asp->set_bus(OV_SNAME(SFX_BUS)); } asp->set_stream(audio_stream); asp->set_volume_db(volume); @@ -604,23 +604,20 @@ static bool generate_texteditbox(generate_gui_args_t&& args) { godot_line_edit->set_position(godot_line_edit->get_position() + border_size + default_position_padding); godot_line_edit->set_custom_minimum_size(max_size - border_size - default_size_padding); - static const StringName caret_color_theme = "caret_color"; static const Color caret_colour { 1.0_real, 0.0_real, 0.0_real }; - godot_line_edit->add_theme_color_override(caret_color_theme, caret_colour); + godot_line_edit->add_theme_color_override(OV_SNAME(caret_color), caret_colour); if (text_edit_box.get_font() != nullptr) { const StringName font_file = Utilities::std_to_godot_string(text_edit_box.get_font()->get_fontname()); const Ref font = args.asset_manager.get_font(font_file); if (font.is_valid()) { - static const StringName font_theme = "font"; - godot_line_edit->add_theme_font_override(font_theme, font); + godot_line_edit->add_theme_font_override(OV_SNAME(font), font); } else { UtilityFunctions::push_error("Failed to load font \"", font_file, "\" for GUI text edit box", text_edit_box_name); ret = false; } const Color colour = Utilities::to_godot_color(text_edit_box.get_font()->get_colour()); - static const StringName font_color_theme = "font_color"; - godot_line_edit->add_theme_color_override(font_color_theme, colour); + godot_line_edit->add_theme_color_override(OV_SNAME(font_color), colour); } const StringName texture_file = Utilities::std_to_godot_string(text_edit_box.get_texture_file()); @@ -630,8 +627,7 @@ static bool generate_texteditbox(generate_gui_args_t&& args) { if (texture.is_valid()) { Ref stylebox = AssetManager::make_stylebox_texture(texture, border_size); if (stylebox.is_valid()) { - static const StringName normal_theme = "normal"; - godot_line_edit->add_theme_stylebox_override(normal_theme, stylebox); + godot_line_edit->add_theme_stylebox_override(OV_SNAME(normal), stylebox); } else { UtilityFunctions::push_error("Failed to make StyleBoxTexture for GUI button ", text_edit_box_name); ret = false; @@ -647,8 +643,7 @@ static bool generate_texteditbox(generate_gui_args_t&& args) { Ref stylebox_empty; stylebox_empty.instantiate(); if (stylebox_empty.is_valid()) { - static const StringName focus_theme = "focus"; - godot_line_edit->add_theme_stylebox_override(focus_theme, stylebox_empty); + godot_line_edit->add_theme_stylebox_override(OV_SNAME(focus), stylebox_empty); } else { UtilityFunctions::push_error("Failed to create empty style box for focus of GUI text edit box ", text_edit_box_name); ret = false; @@ -700,8 +695,7 @@ static bool generate_window(generate_gui_args_t&& args) { Ref stylebox_empty; stylebox_empty.instantiate(); if (stylebox_empty.is_valid()) { - static const StringName panel_theme = "panel"; - godot_panel->add_theme_stylebox_override(panel_theme, stylebox_empty); + godot_panel->add_theme_stylebox_override(OV_SNAME(panel), stylebox_empty); } else { UtilityFunctions::push_error("Failed to create empty style box for background of GUI window ", window_name); ret = false; diff --git a/extension/src/openvic-extension/utility/Utilities.cpp b/extension/src/openvic-extension/utility/Utilities.cpp index b5a14fed..a96e32f3 100644 --- a/extension/src/openvic-extension/utility/Utilities.cpp +++ b/extension/src/openvic-extension/utility/Utilities.cpp @@ -17,32 +17,22 @@ #include #include "openvic-extension/classes/GUINode.hpp" +#include "openvic-extension/core/StaticString.hpp" using namespace godot; using namespace OpenVic; -godot::StringName const& Utilities::get_short_value_placeholder() { - static const godot::StringName value_placeholder = "$VAL$"; - return value_placeholder; +godot::String Utilities::get_short_value_placeholder() { + return "$VAL$"; } -godot::StringName const& Utilities::get_long_value_placeholder() { - static const godot::StringName value_placeholder = "$VALUE$"; - return value_placeholder; +godot::String Utilities::get_long_value_placeholder() { + return "$VALUE$"; } -godot::StringName const& Utilities::get_percentage_value_placeholder() { - static const godot::StringName value_placeholder = "$PERC$"; - return value_placeholder; +godot::String Utilities::get_percentage_value_placeholder() { + return "$PERC$"; } -godot::StringName const& Utilities::get_colour_and_sign(const fixed_point_t value) { - static const godot::StringName green_plus = "G+"; - static const godot::StringName red = "R"; - static const godot::StringName yellow = "Y"; - - return value > 0 - ? green_plus - : value < 0 - ? red - : yellow; +godot::String Utilities::get_colour_and_sign(const fixed_point_t value) { + return value > 0 ? "G+" : value < 0 ? "R" : "Y"; } /* Int to 2 decimal place string in terms of the largest suffix less than or equal to it, @@ -291,7 +281,7 @@ godot::String Utilities::get_state_name(godot::Object const& translation_object, name = translation_object.tr(GUINode::format_province_name(Utilities::std_to_godot_string(state.get_capital()->get_identifier()))); if (!owned) { - static const StringName region_key = "REGION_NAME"; + const StringName region_key = OV_SNAME(REGION_NAME); static const String name_key = "$NAME$"; String region = translation_object.tr(region_key); @@ -393,14 +383,12 @@ godot::String Utilities::make_modifier_effect_value( // DAYS AND SPEED MUST BE DEFAULT COLOUR! case DAYS: { - static const StringName days_localisation_key = "DAYS"; - result += special_suffix_text + translation_object.tr(days_localisation_key); + result += special_suffix_text + translation_object.tr(OV_SNAME(DAYS)); break; } case SPEED: { - static const StringName speed_localisation_key = "KPH"; - result += special_suffix_text + translation_object.tr(speed_localisation_key); + result += special_suffix_text + translation_object.tr(OV_SNAME(KPH)); break; } diff --git a/extension/src/openvic-extension/utility/Utilities.hpp b/extension/src/openvic-extension/utility/Utilities.hpp index abad13c0..16d7b8d3 100644 --- a/extension/src/openvic-extension/utility/Utilities.hpp +++ b/extension/src/openvic-extension/utility/Utilities.hpp @@ -36,10 +36,10 @@ namespace OpenVic::Utilities { return file->get_buffer(size).get_string_from_ascii(); } - godot::StringName const& get_short_value_placeholder(); - godot::StringName const& get_long_value_placeholder(); - godot::StringName const& get_percentage_value_placeholder(); - godot::StringName const& get_colour_and_sign(const fixed_point_t value); + godot::String get_short_value_placeholder(); + godot::String get_long_value_placeholder(); + godot::String get_percentage_value_placeholder(); + godot::String get_colour_and_sign(const fixed_point_t value); godot::String int_to_string_suffixed(int64_t val); diff --git a/game/src/Autoload/MusicManager/MusicManager.gd b/game/src/Autoload/MusicManager/MusicManager.gd index 281f704d..4939ff9c 100644 --- a/game/src/Autoload/MusicManager/MusicManager.gd +++ b/game/src/Autoload/MusicManager/MusicManager.gd @@ -171,7 +171,7 @@ func _ready() -> void: for key : String in settings.get_section_keys("audio"): if not key.ends_with("_BUS"): continue var bus_name := key - if key == "MASTER_BUS": bus_name = "Master" + if key == "MASTER_BUS": bus_name = &"Master" var bus_index := AudioServer.get_bus_index(bus_name) if bus_index == -1: push_error("Could not find bus '%s'.", bus_name) diff --git a/game/src/UI/GameMenu/OptionMenu/VolumeGrid.gd b/game/src/UI/GameMenu/OptionMenu/VolumeGrid.gd index 47ced387..47b41ba6 100644 --- a/game/src/UI/GameMenu/OptionMenu/VolumeGrid.gd +++ b/game/src/UI/GameMenu/OptionMenu/VolumeGrid.gd @@ -16,7 +16,7 @@ func get_volume_value_as_db(value : float) -> float: func add_volume_row(bus_name : String, bus_index : int) -> HSlider: var volume_label := Label.new() - if bus_name == "Master": + if bus_name == &"Master": volume_label.text = "MASTER_BUS" else: volume_label.text = bus_name