Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,33 @@ IncludeCategories:
Priority: 4
- Regex: ^<openvic-simulation/
Priority: 5
- Regex: ^"openvic-extension/
- Regex: ^<lexy-vdf/
Priority: 6
- Regex: .*
- Regex: ^<boost/
Priority: 7
- Regex: ^<dryad/
Priority: 8
- Regex: ^<fmt/
Priority: 9
- Regex: ^<foonathan
Priority: 10
- Regex: ^<function2/
Priority: 11
- Regex: ^<plf_colony.h>
Priority: 12
- Regex: ^<range
Priority: 13
- Regex: ^<spdlog/
Priority: 14
- Regex: ^<tsl/
Priority: 15
- Regex: ^<type_safe/
Priority: 16
- Regex: ^<XoshiroCpp.hpp>
Priority: 17
- Regex: ^<gli/
Priority: 18
- Regex: ^"openvic-extension/
Priority: 19
- Regex: .*
Priority: 20
27 changes: 13 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ exclude: |
)

repos:
# Waiting on Hop311 to approve clang-format
# - repo: https://github.com/pre-commit/mirrors-clang-format
# rev: v19.1.3
# hooks:
# - id: clang-format
# files: \.(c|h|cpp|hpp|inc)$
# types_or: [text]
# # exclude: |
# # (?x)^(
# # )
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v22.1.5
hooks:
- id: clang-format
files: \.(c|h|cpp|hpp|inc)$
types_or: [text]
exclude: |
(?x)^(
extension/src/gen/.*
)

- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
Expand All @@ -31,7 +31,7 @@ repos:
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.2
rev: v0.15.18
hooks:
- id: ruff-check
args: [--fix]
Expand All @@ -42,7 +42,7 @@ repos:
types_or: [text]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v2.1.0
hooks:
- id: mypy
files: \.py$
Expand All @@ -58,7 +58,6 @@ repos:
game/addons/.*
)


- repo: local
hooks:
- id: make-rst
Expand All @@ -75,4 +74,4 @@ repos:
entry: python extension/doc_tools/doc_status.py
args: [extension/doc_classes]
pass_filenames: false
files: ^(extension/doc_classes)/.*\.xml$
files: ^(extension/doc_classes)/.*\.xml$
38 changes: 15 additions & 23 deletions extension/src/openvic-extension/classes/GFXButtonStateTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ void GFXCorneredTileSupportingTexture::draw_rect_cornered(RID const& to_canvas_i
if (rendering_server != nullptr) {
const Size2 size = get_size();
rendering_server->canvas_item_add_nine_patch(
to_canvas_item, rect, { {}, size }, get_rid(),
cornered_tile_border_size, size - cornered_tile_border_size
to_canvas_item, rect, { {}, size }, get_rid(), cornered_tile_border_size, size - cornered_tile_border_size
);
}
} else {
Expand Down Expand Up @@ -69,8 +68,7 @@ Ref<GFXButtonStateTexture> GFXButtonStateTexture::make_gfx_button_state_texture(

void GFXButtonStateTexture::set_button_state(ButtonState new_button_state) {
ERR_FAIL_COND(
new_button_state != HOVER && new_button_state != PRESSED &&
new_button_state != DISABLED && new_button_state != SELECTED
new_button_state != HOVER && new_button_state != PRESSED && new_button_state != DISABLED && new_button_state != SELECTED
);
button_state = new_button_state;
}
Expand All @@ -82,9 +80,9 @@ Error GFXButtonStateTexture::generate_state_image(
const Rect2i source_image_rect { {}, source_image->get_size() };
ERR_FAIL_COND_V(!region.has_area() || !source_image_rect.encloses(region), FAILED);
/* Whether we've already set the ImageTexture to an image of the right dimensions and format,
* and so can update it without creating and setting a new image, or not. */
bool can_update = state_image.is_valid() && state_image->get_size() == region.get_size()
&& state_image->get_format() == source_image->get_format();
* and so can update it without creating and setting a new image, or not. */
bool can_update = state_image.is_valid() && state_image->get_size() == region.get_size() &&
state_image->get_format() == source_image->get_format();
if (!can_update) {
state_image = Image::create(region.size.width, region.size.height, false, source_image->get_format());
ERR_FAIL_NULL_V(state_image, FAILED);
Expand Down Expand Up @@ -114,11 +112,10 @@ Error GFXButtonStateTexture::generate_state_image(
return { std::max(colour.r - 0.3f, 0.0f), std::max(colour.g - 0.3f, 0.0f), std::max(colour.b - 0.3f, 0.0f), colour.a };
};

const auto colour_func =
button_state == HOVER ? hover_colour :
button_state == PRESSED ? pressed_colour :
button_state == DISABLED ? disabled_colour :
selected_colour;
const auto colour_func = button_state == HOVER ? hover_colour
: button_state == PRESSED ? pressed_colour
: button_state == DISABLED ? disabled_colour
: selected_colour;

for (Vector2i point { 0, 0 }; point.y < state_image->get_height(); ++point.y) {
for (point.x = 0; point.x < state_image->get_width(); ++point.x) {
Expand All @@ -141,16 +138,11 @@ StringName const& GFXButtonStateTexture::button_state_to_name(ButtonState button
static const StringName name_selected = "selected";
static const StringName name_error = "INVALID BUTTON STATE";
switch (button_state) {
case HOVER:
return name_hover;
case PRESSED:
return name_pressed;
case DISABLED:
return name_disabled;
case SELECTED:
return name_selected;
default:
return name_error;
case HOVER: return name_hover;
case PRESSED: return name_pressed;
case DISABLED: return name_disabled;
case SELECTED: return name_selected;
default: return name_error;
}
}

Expand Down Expand Up @@ -181,7 +173,7 @@ void GFXButtonStateHavingTexture::_clear_button_states() {

GFXButtonStateHavingTexture::GFXButtonStateHavingTexture() : button_state_textures {} {}

Ref<GFXButtonStateTexture> GFXButtonStateHavingTexture::get_button_state_texture(
Ref<GFXButtonStateTexture> GFXButtonStateHavingTexture::get_button_state_texture( //
GFXButtonStateTexture::ButtonState button_state
) {
const size_t button_state_index = button_state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace OpenVic {
GDCLASS(GFXButtonStateTexture, GFXCorneredTileSupportingTexture)

public:
enum ButtonState {
enum ButtonState { //
HOVER,
PRESSED,
DISABLED,
Expand Down
43 changes: 19 additions & 24 deletions extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "GFXMaskedFlagTexture.hpp"

#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/core/Convert.hpp"
#include "openvic-extension/singletons/AssetManager.hpp"
#include "openvic-extension/singletons/GameSingleton.hpp"
#include "openvic-extension/core/Bind.hpp"
#include "openvic-extension/utility/UITools.hpp"
#include "openvic-extension/utility/Utilities.hpp"

Expand All @@ -14,11 +14,11 @@ Error GFXMaskedFlagTexture::_generate_combined_image() {
ERR_FAIL_NULL_V(overlay_image, FAILED);
/* Whether we've already set the ImageTexture to an image of the right dimensions and format,
* and so can update it without creating and setting a new image, or not. */
bool can_update = button_image.is_valid() && button_image->get_size() == overlay_image->get_size()
&& button_image->get_format() == overlay_image->get_format();
bool can_update = button_image.is_valid() && button_image->get_size() == overlay_image->get_size() &&
button_image->get_format() == overlay_image->get_format();
if (!can_update) {
button_image = Image::create(
overlay_image->get_width(), overlay_image->get_height(), false, overlay_image->get_format()
overlay_image->get_width(), overlay_image->get_height(), false, overlay_image->get_format() //
);
ERR_FAIL_NULL_V(button_image, FAILED);
}
Expand All @@ -35,21 +35,18 @@ Error GFXMaskedFlagTexture::_generate_combined_image() {
const Vector2i centre_translation = (mask_image->get_size() - button_image->get_size()) / 2;

for (
Vector2i combined_image_point { 0, 0 };
combined_image_point.y < button_image->get_height();
++combined_image_point.y
Vector2i combined_image_point { 0, 0 }; combined_image_point.y < button_image->get_height();
++combined_image_point.y //
) {

for (combined_image_point.x = 0; combined_image_point.x < button_image->get_width(); ++combined_image_point.x) {

const Color overlay_image_colour = overlay_image->get_pixelv(combined_image_point);

// Translate to mask_image coordinates, keeping the centres of each image aligned.
const Vector2i mask_image_point = combined_image_point + centre_translation;

if (
0 <= mask_image_point.x && mask_image_point.x < mask_image->get_width() &&
0 <= mask_image_point.y && mask_image_point.y < mask_image->get_height()
0 <= mask_image_point.x && mask_image_point.x < mask_image->get_width() && 0 <= mask_image_point.y &&
mask_image_point.y < mask_image->get_height() //
) {
const Color mask_image_colour = mask_image->get_pixelv(mask_image_point);

Expand Down Expand Up @@ -153,9 +150,9 @@ Error GFXMaskedFlagTexture::set_gfx_masked_flag_name(String const& gfx_masked_fl

GFX::MaskedFlag const* new_masked_flag = sprite->cast_to<GFX::MaskedFlag>();
ERR_FAIL_NULL_V_MSG(
new_masked_flag, FAILED, Utilities::format(
"Invalid type for GFX sprite %s: %s (expected %s)", gfx_masked_flag_name,
convert_to<String>(sprite->get_type()),
new_masked_flag, FAILED,
Utilities::format(
"Invalid type for GFX sprite %s: %s (expected %s)", gfx_masked_flag_name, convert_to<String>(sprite->get_type()),
convert_to<String>(GFX::MaskedFlag::get_type_static())
)
);
Expand Down Expand Up @@ -204,11 +201,10 @@ Error GFXMaskedFlagTexture::set_flag_country_name_and_type(
GameSingleton const* game_singleton = GameSingleton::get_singleton();
ERR_FAIL_NULL_V(game_singleton, FAILED);

CountryDefinition const* new_flag_country = game_singleton->get_definition_manager()
.get_country_definition_manager()
.get_country_definition_by_identifier(
convert_to<std::string>(new_flag_country_name)
);
CountryDefinitionManager const& manager = game_singleton->get_definition_manager().get_country_definition_manager();
CountryDefinition const* new_flag_country = manager.get_country_definition_by_identifier( //
convert_to<std::string>(new_flag_country_name)
);
ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, Utilities::format("Country not found: %s", new_flag_country_name));

return set_flag_country_and_type(new_flag_country, new_flag_type);
Expand All @@ -221,7 +217,7 @@ Error GFXMaskedFlagTexture::set_flag_country(CountryInstance* new_flag_country)

GovernmentType const* government_type = new_flag_country->flag_government_type.get_untracked();

const StringName new_flag_type = government_type != nullptr
const StringName new_flag_type = government_type != nullptr //
? StringName { convert_to<String>(government_type->get_flag_type()) }
: StringName {};

Expand All @@ -239,10 +235,9 @@ Error GFXMaskedFlagTexture::set_flag_country_name(String const& new_flag_country
InstanceManager* instance_manager = game_singleton->get_instance_manager();
ERR_FAIL_NULL_V(instance_manager, FAILED);

CountryInstance* new_flag_country = instance_manager->get_country_instance_manager()
.get_country_instance_by_identifier(
convert_to<std::string>(new_flag_country_name)
);
CountryInstance* new_flag_country = instance_manager->get_country_instance_manager().get_country_instance_by_identifier(
convert_to<std::string>(new_flag_country_name)
);
ERR_FAIL_NULL_V_MSG(new_flag_country, FAILED, Utilities::format("Country not found: %s", new_flag_country_name));

return set_flag_country(new_flag_country);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ namespace OpenVic {

/* Set flag_country and flag_type and update the combined image to use that flag, or no flag if it doesn't exist. */
godot::Error set_flag_country_and_type(
CountryDefinition const* new_flag_country, godot::StringName const& new_flag_type
CountryDefinition const* new_flag_country, godot::StringName const& new_flag_type //
);

/* Look up the country with the specified identifier, then call set_flag_country_and_type with the country and
* specified flag_type as arguments. */
godot::Error set_flag_country_name_and_type(
godot::String const& new_flag_country_name, godot::StringName const& new_flag_type
godot::String const& new_flag_country_name, godot::StringName const& new_flag_type //
);

/* Look up the specified country's current flag type, then call set_flag_country_and_type
Expand Down
18 changes: 9 additions & 9 deletions extension/src/openvic-extension/classes/GFXPieChartTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ Error GFXPieChartTexture::_generate_pie_chart_image() {

/* Whether we've already set the ImageTexture to an image of the right dimensions,
* and so can update it without creating and setting a new image, or not. */
const bool can_update = pie_chart_image.is_valid() && pie_chart_image->get_width() == pie_chart_diameter
&& pie_chart_image->get_height() == pie_chart_diameter;
const bool can_update = pie_chart_image.is_valid() && pie_chart_image->get_width() == pie_chart_diameter &&
pie_chart_image->get_height() == pie_chart_diameter;

if (!can_update) {
pie_chart_image = Image::create(pie_chart_diameter, pie_chart_diameter, false, Image::FORMAT_RGBA8);
Expand Down Expand Up @@ -99,9 +99,7 @@ Error GFXPieChartTexture::_generate_pie_chart_image() {
}
}
} else {

pie_chart_image->fill(background_colour);

}

if (can_update) {
Expand All @@ -124,8 +122,10 @@ Error GFXPieChartTexture::set_slices_array(godot_pie_chart_data_t const& new_sli
Utilities::format("Invalid slice keys at index %d", i)
);
const slice_t slice {
slice_dict[_slice_identifier_key()], slice_dict[_slice_tooltip_key()], slice_dict[_slice_colour_key()],
slice_dict[_slice_weight_key()]
slice_dict[_slice_identifier_key()],
slice_dict[_slice_tooltip_key()], //
slice_dict[_slice_colour_key()], //
slice_dict[_slice_weight_key()] //
};
if (slice.weight > 0.0f) {
total_weight += slice.weight;
Expand Down Expand Up @@ -184,9 +184,9 @@ Error GFXPieChartTexture::set_gfx_pie_chart_name(String const& gfx_pie_chart_nam
ERR_FAIL_NULL_V(sprite, FAILED);
GFX::PieChart const* new_pie_chart = sprite->cast_to<GFX::PieChart>();
ERR_FAIL_NULL_V_MSG(
new_pie_chart, FAILED, Utilities::format(
"Invalid type for GFX sprite %s: %s (expected %s)", gfx_pie_chart_name,
convert_to<String>(sprite->get_type()),
new_pie_chart, FAILED,
Utilities::format(
"Invalid type for GFX sprite %s: %s (expected %s)", gfx_pie_chart_name, convert_to<String>(sprite->get_type()),
convert_to<String>(GFX::PieChart::get_type_static())
)
);
Expand Down
Loading
Loading