Skip to content

Commit 910fe7d

Browse files
committed
Fix some orphan StringNames caused by extension
1 parent 721871d commit 910fe7d

33 files changed

+430
-553
lines changed

extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#include <godot_cpp/classes/rendering_server.hpp>
44
#include <godot_cpp/variant/utility_functions.hpp>
55

6+
#include <openvic-simulation/utility/Typedefs.hpp>
7+
68
#include "openvic-extension/core/Bind.hpp"
9+
#include "openvic-extension/core/StaticString.hpp"
710

811
using namespace OpenVic;
912
using namespace godot;
@@ -135,22 +138,17 @@ Error GFXButtonStateTexture::generate_state_image(
135138
}
136139

137140
StringName const& GFXButtonStateTexture::button_state_to_name(ButtonState button_state) {
138-
static const StringName name_hover = "hover";
139-
static const StringName name_pressed = "pressed";
140-
static const StringName name_disabled = "disabled";
141-
static const StringName name_selected = "selected";
142-
static const StringName name_error = "INVALID BUTTON STATE";
143141
switch (button_state) {
144142
case HOVER:
145-
return name_hover;
143+
return OV_SNAME(hover);
146144
case PRESSED:
147-
return name_pressed;
145+
return OV_SNAME(pressed);
148146
case DISABLED:
149-
return name_disabled;
147+
return OV_SNAME(disabled);
150148
case SELECTED:
151-
return name_selected;
149+
return OV_SNAME(selected);
152150
default:
153-
return name_error;
151+
unreachable();
154152
}
155153
}
156154

extension/src/openvic-extension/classes/GFXPieChartTexture.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,24 @@
33
#include <numbers>
44

55
#include "openvic-extension/core/Bind.hpp"
6+
#include "openvic-extension/core/StaticString.hpp"
67
#include "openvic-extension/utility/UITools.hpp"
78

89
using namespace godot;
910
using namespace OpenVic;
1011
using namespace OpenVic::Utilities::literals;
1112

1213
StringName const& GFXPieChartTexture::_slice_identifier_key() {
13-
static const StringName slice_identifier_key = "identifier";
14-
return slice_identifier_key;
14+
return OV_SNAME(identifier);
1515
}
1616
StringName const& GFXPieChartTexture::_slice_tooltip_key() {
17-
static const StringName slice_tooltip_key = "tooltip";
18-
return slice_tooltip_key;
17+
return OV_SNAME(tooltip);
1918
}
2019
StringName const& GFXPieChartTexture::_slice_colour_key() {
21-
static const StringName slice_colour_key = "colour";
22-
return slice_colour_key;
20+
return OV_SNAME(colour);
2321
}
2422
StringName const& GFXPieChartTexture::_slice_weight_key() {
25-
static const StringName slice_weight_key = "weight";
26-
return slice_weight_key;
23+
return OV_SNAME(weight);
2724
}
2825

2926
GFXPieChartTexture::slice_t const* GFXPieChartTexture::get_slice(Vector2 const& position) const {

extension/src/openvic-extension/classes/GUIButton.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include "GUIButton.hpp"
22

3-
#include <array>
4-
53
#include <godot_cpp/variant/utility_functions.hpp>
64

5+
#include "openvic-extension/core/StaticString.hpp"
76
#include "openvic-extension/singletons/AssetManager.hpp"
87
#include "openvic-extension/utility/Utilities.hpp"
98

@@ -33,9 +32,7 @@ Error GUIButton::set_gfx_button_state_having_texture(Ref<GFXButtonStateHavingTex
3332
Ref<StyleBoxTexture> stylebox = AssetManager::make_stylebox_texture(texture);
3433

3534
if (stylebox.is_valid()) {
36-
static const StringName normal_theme = "normal";
37-
38-
add_theme_stylebox_override(normal_theme, stylebox);
35+
add_theme_stylebox_override(OV_SNAME(normal), stylebox);
3936
} else {
4037
UtilityFunctions::push_error("Failed to make StyleBoxTexture for GUIButton ", get_name());
4138

@@ -86,22 +83,24 @@ Error GUIButton::set_gfx_font(GFX::Font const* gfx_font) {
8683
const Ref<Font> font = asset_manager->get_font(font_file);
8784

8885
if (font.is_valid()) {
89-
static const StringName font_theme = "font";
90-
91-
add_theme_font_override(font_theme, font);
86+
add_theme_font_override(OV_SNAME(font), font);
9287
} else {
9388
UtilityFunctions::push_error("Failed to load font \"", font_file, "\" for GUIButton ", get_name());
9489

9590
err = FAILED;
9691
}
9792

98-
static const std::array<StringName, 5> button_font_themes {
99-
"font_color", "font_hover_color", "font_hover_pressed_color", "font_pressed_color", "font_disabled_color"
100-
};
101-
10293
const Color colour = Utilities::to_godot_color(gfx_font->get_colour());
10394

104-
for (StringName const& theme_name : button_font_themes) {
95+
for (StringName const& theme_name :
96+
{
97+
OV_SNAME(font_color), //
98+
OV_SNAME(font_hover_color), //
99+
OV_SNAME(font_hover_pressed_color), //
100+
OV_SNAME(font_pressed_color), //
101+
OV_SNAME(font_disabled_color) //
102+
} //
103+
) {
105104
add_theme_color_override(theme_name, colour);
106105
}
107106

extension/src/openvic-extension/classes/GUIListBox.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
#include <godot_cpp/variant/utility_functions.hpp>
55

66
#include "openvic-extension/core/Bind.hpp"
7+
#include "openvic-extension/core/StaticString.hpp"
78
#include "openvic-extension/utility/UITools.hpp"
89
#include "openvic-extension/utility/Utilities.hpp"
910

1011
using namespace OpenVic;
1112
using namespace godot;
1213
using namespace OpenVic::Utilities::literals;
1314

14-
/* StringNames cannot be constructed until Godot has called StringName::setup(),
15-
* so we must use wrapper functions to delay their initialisation. */
1615
StringName const& GUIListBox::_signal_scroll_index_changed() {
17-
static const StringName signal_scroll_index_changed = "scroll_index_changed";
18-
return signal_scroll_index_changed;
16+
return OV_SNAME(scroll_index_changed);
1917
}
2018

2119
Error GUIListBox::_calculate_max_scroll_index(bool signal) {
@@ -285,10 +283,8 @@ Error GUIListBox::set_gui_listbox(GUI::ListBox const* new_gui_listbox) {
285283
scrollbar->set_position(position);
286284
scrollbar->set_length_override(size.height);
287285

288-
static const StringName set_scroll_index_func_name = "set_scroll_index";
289-
290286
scrollbar->connect(
291-
GUIScrollbar::signal_value_changed(), Callable { this, set_scroll_index_func_name }, CONNECT_PERSIST
287+
GUIScrollbar::signal_value_changed(), Callable { this, OV_SNAME(set_scroll_index) }, CONNECT_PERSIST
292288
);
293289
} else {
294290
UtilityFunctions::push_error(

extension/src/openvic-extension/classes/GUINode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <godot_cpp/variant/vector2i.hpp>
3131

3232
#include "openvic-extension/core/Bind.hpp"
33+
#include "openvic-extension/core/StaticString.hpp"
3334
#include "openvic-extension/utility/UITools.hpp"
3435
#include "openvic-extension/utility/Utilities.hpp"
3536

@@ -160,21 +161,20 @@ Ref<Texture2D> GUINode::get_texture_from_node(Node* node) {
160161
ERR_FAIL_NULL_V_MSG(texture, nullptr, Utilities::format("Failed to get Texture2D from TextureRect %s", node->get_name()));
161162
return texture;
162163
} else if (GUIButton const* button = Object::cast_to<GUIButton>(node); button != nullptr) {
163-
static const StringName theme_name_normal = "normal";
164-
const Ref<StyleBox> stylebox = button->get_theme_stylebox(theme_name_normal);
164+
const Ref<StyleBox> stylebox = button->get_theme_stylebox(OV_SNAME(normal));
165165
ERR_FAIL_NULL_V_MSG(
166-
stylebox, nullptr, Utilities::format("Failed to get StyleBox %s from GUIButton %s", theme_name_normal, node->get_name())
166+
stylebox, nullptr, Utilities::format("Failed to get StyleBox %s from GUIButton %s", OV_SNAME(normal), node->get_name())
167167
);
168168
const Ref<StyleBoxTexture> stylebox_texture = stylebox;
169169
ERR_FAIL_NULL_V_MSG(
170170
stylebox_texture, nullptr, Utilities::format(
171-
"Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", theme_name_normal, node->get_name()
171+
"Failed to cast StyleBox %s from GUIButton %s to type StyleBoxTexture", OV_SNAME(normal), node->get_name()
172172
)
173173
);
174174
const Ref<Texture2D> result = stylebox_texture->get_texture();
175175
ERR_FAIL_NULL_V_MSG(
176176
result, nullptr,
177-
Utilities::format("Failed to get Texture2D from StyleBoxTexture %s from GUIButton %s", theme_name_normal, node->get_name())
177+
Utilities::format("Failed to get Texture2D from StyleBoxTexture %s from GUIButton %s", OV_SNAME(normal), node->get_name())
178178
);
179179
return result;
180180
}

extension/src/openvic-extension/classes/GUIOverlappingElementsBox.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <godot_cpp/variant/utility_functions.hpp>
44

55
#include "openvic-extension/core/Bind.hpp"
6+
#include "openvic-extension/core/StaticString.hpp"
67
#include "openvic-extension/utility/UITools.hpp"
78
#include "openvic-extension/utility/Utilities.hpp"
89
#include "openvic-simulation/types/TextFormat.hpp"
@@ -121,13 +122,9 @@ Error GUIOverlappingElementsBox::set_child_count(int32_t new_count) {
121122
)
122123
);
123124

124-
static const StringName set_z_index_func_name = "set_z_index";
125-
static const StringName mouse_entered_signal_name = "mouse_entered";
126-
static const StringName mouse_exited_signal_name = "mouse_exited";
127-
128125
/* Move the child element in front of its neighbours when moused-over. */
129-
child->connect(mouse_entered_signal_name, Callable { child, set_z_index_func_name }.bind(1), CONNECT_PERSIST);
130-
child->connect(mouse_exited_signal_name, Callable { child, set_z_index_func_name }.bind(0), CONNECT_PERSIST);
126+
child->connect(OV_SNAME(mouse_entered), Callable { child, OV_SNAME(set_z_index) }.bind(1), CONNECT_PERSIST);
127+
child->connect(OV_SNAME(mouse_exited), Callable { child, OV_SNAME(set_z_index) }.bind(0), CONNECT_PERSIST);
131128

132129
add_child(child);
133130
child_count++;

extension/src/openvic-extension/classes/GUIScrollbar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <openvic-simulation/utility/Logger.hpp>
1414

1515
#include "openvic-extension/core/Bind.hpp"
16+
#include "openvic-extension/core/StaticString.hpp"
1617
#include "openvic-extension/utility/UITools.hpp"
1718
#include "openvic-extension/utility/Utilities.hpp"
1819

@@ -22,8 +23,7 @@ using namespace godot;
2223
/* StringNames cannot be constructed until Godot has called StringName::setup(),
2324
* so we must use wrapper functions to delay their initialisation. */
2425
StringName const& GUIScrollbar::signal_value_changed() {
25-
static const StringName signal_value_changed = "value_changed";
26-
return signal_value_changed;
26+
return OV_SNAME(value_changed);
2727
}
2828

2929
GUI_TOOLTIP_IMPLEMENTATIONS(GUIScrollbar)

extension/src/openvic-extension/classes/resources/StyleBoxWithSound.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <godot_cpp/variant/utility_functions.hpp>
1212

1313
#include "openvic-extension/core/Bind.hpp"
14+
#include "openvic-extension/core/StaticString.hpp"
1415

1516
using namespace OpenVic;
1617
using namespace godot;
@@ -40,7 +41,7 @@ void StyleBoxWithSound::_bind_methods() {
4041
}
4142

4243
StyleBoxWithSound::StyleBoxWithSound() {
43-
audio_bus = "Master";
44+
audio_bus = OV_SNAME(Master);
4445
}
4546

4647
Ref<StyleBox> StyleBoxWithSound::get_style_box() const {

extension/src/openvic-extension/components/budget/AdministrationBudget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fixed_point_t AdministrationBudget::calculate_budget_and_update_custom(
5555
CountryInstance& country,
5656
const fixed_point_t scaled_value
5757
) {
58-
static const godot::StringName administrative_efficiency_template = "%s\n%s%s\n--------------\n%s%s%s%s";
58+
static const godot::String administrative_efficiency_template = "%s\n%s%s\n--------------\n%s%s%s%s";
5959

6060
const fixed_point_t administrative_efficiency_from_administrators = country.get_administrative_efficiency_from_administrators_untracked();
6161
administrative_efficiency_label.set_text(

extension/src/openvic-extension/components/budget/StrataTaxBudget.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "openvic-extension/classes/GUILabel.hpp"
1010
#include "openvic-extension/classes/GUINode.hpp"
1111
#include "openvic-extension/classes/GUIScrollbar.hpp"
12+
#include "openvic-extension/core/StaticString.hpp"
1213
#include "openvic-extension/singletons/PlayerSingleton.hpp"
1314
#include "openvic-extension/utility/Utilities.hpp"
1415

@@ -37,7 +38,7 @@ StrataTaxBudget::StrataTaxBudget(
3738
GUILabel::set_text_and_tooltip(
3839
parent,
3940
Utilities::format("./country_budget/tax_%d_desc", static_cast<uint64_t>(new_strata.get_index())),
40-
generate_slider_tooltip_localisation_key(new_strata),
41+
slider_tooltip_localisation_key,
4142
Utilities::format(
4243
"TAX_%s_DESC",
4344
Utilities::std_to_godot_string(strata.get_identifier()).to_upper()
@@ -82,22 +83,19 @@ void StrataTaxBudget::update_slider_tooltip(
8283
const fixed_point_t scaled_value
8384
) {
8485
//these use $VALUE$%
85-
static const godot::StringName tax_efficiency_localisation_key = "BUDGET_TAX_EFFICIENCY";
86-
static const godot::StringName effective_tax_rate_localisation_key = "BUDGET_TAX_EFFECT";
8786

8887
//this uses $VALUE$ only
89-
static const godot::StringName tax_efficiency_from_tech_localisation_key = "BUDGET_TECH_TAX";
9088

9189
const godot::String localised_strata_tax = slider.tr(slider_tooltip_localisation_key);
9290

9391
const fixed_point_t tax_efficiency = country.get_tax_efficiency_untracked();
94-
const godot::String tax_efficiency_text = slider.tr(tax_efficiency_localisation_key).replace(
92+
const godot::String tax_efficiency_text = slider.tr(OV_INAME("BUDGET_TAX_EFFICIENCY")).replace(
9593
Utilities::get_long_value_placeholder(),
9694
Utilities::float_to_string_dp(100 * static_cast<float>(tax_efficiency), 2)
9795
);
9896

9997
const fixed_point_t tax_efficiency_from_tech = country.get_modifier_effect_value(*modifier_effect_cache.get_tax_eff());
100-
const godot::String tax_efficiency_from_tech_text = slider.tr(tax_efficiency_from_tech_localisation_key).replace(
98+
const godot::String tax_efficiency_from_tech_text = slider.tr(OV_INAME("BUDGET_TECH_TAX")).replace(
10199
Utilities::get_short_value_placeholder(),
102100
Utilities::format(
103101
"%s%%",
@@ -109,7 +107,7 @@ void StrataTaxBudget::update_slider_tooltip(
109107
);
110108

111109
const fixed_point_t effective_tax_rate = tax_efficiency * scaled_value;
112-
const godot::String effective_tax_rate_text = slider.tr(effective_tax_rate_localisation_key).replace(
110+
const godot::String effective_tax_rate_text = slider.tr(OV_INAME("BUDGET_TAX_EFFECT")).replace(
113111
Utilities::get_long_value_placeholder(),
114112
Utilities::float_to_string_dp(100 * static_cast<float>(effective_tax_rate), 2)
115113
);

0 commit comments

Comments
 (0)