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
33 changes: 21 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ default_language_version:
python: python3

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: v19.1.3
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 @@ -25,19 +25,28 @@ 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.7.3
rev: v0.11.13
hooks:
- id: ruff
args: [--fix]
files: (\.py|SConstruct|SCsub)$
exclude: |
(?x)^(
extension/doc_tools/make_rst.py|
extension/doc_tools/doc_status.py
)
types_or: [text]
- id: ruff-format
files: (\.py|SConstruct|SCsub)$
exclude: |
(?x)^(
extension/doc_tools/make_rst.py|
extension/doc_tools/doc_status.py
)
types_or: [text]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
files: \.py$
Expand Down
28 changes: 16 additions & 12 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python

import os
import platform
import sys

import SCons

Expand All @@ -21,7 +19,7 @@ env.FinalizeOptions()
OLD_ARGS = SCons.Script.ARGUMENTS.copy()
SCons.Script.ARGUMENTS["use_static_cpp"] = env["use_static_cpp"]
SCons.Script.ARGUMENTS["disable_exceptions"] = env["disable_exceptions"]
SCons.Script.ARGUMENTS["compiledb_file"] = 'godot-cpp/compile_commands.json'
SCons.Script.ARGUMENTS["compiledb_file"] = "godot-cpp/compile_commands.json"
godot_env = SConscript("godot-cpp/SConstruct")
SCons.Script.ARGUMENTS = OLD_ARGS

Expand All @@ -32,18 +30,21 @@ env.Prepend(LIBS=godot_env["LIBS"])

SConscript("extension/deps/SCsub", "env")


Default(
env.CommandNoCache(
"extension/src/gen/commit_info.gen.hpp",
env.Value(env.get_git_info()),
env.Run(env.git_builder), name_prefix="game"
env.Run(env.git_builder),
name_prefix="game",
)
)
Default(
env.CommandNoCache(
"extension/src/gen/license_info.gen.hpp",
["#COPYRIGHT", "#LICENSE.md"],
env.Run(env.license_builder), name_prefix="game"
env.Run(env.license_builder),
name_prefix="game",
)
)

Expand All @@ -69,13 +70,15 @@ if env["target"] in ["editor", "template_debug"]:
# Remove unassociated intermediate binary files if allowed, usually the result of a renamed or deleted source file
if env["intermediate_delete"]:
from glob import glob
def remove_extension(file : str):
if file.find(".") == -1: return file
return file[:file.rindex(".")]

def remove_extension(file: str):
if file.find(".") == -1:
return file
return file[: file.rindex(".")]

found_one = False
for path in paths:
for obj_file in [file[:-len(".os")] for file in glob(path + "*.os", recursive=True)]:
for obj_file in [file[: -len(".os")] for file in glob(path + "*.os", recursive=True)]:
found = False
for source_file in sources:
if remove_extension(str(source_file)) == obj_file:
Expand All @@ -85,12 +88,13 @@ if env["intermediate_delete"]:
if not found_one:
found_one = True
print("Unassociated intermediate files found...")
print("Removing "+obj_file+".os")
os.remove(obj_file+".os")
print("Removing " + obj_file + ".os")
os.remove(obj_file + ".os")

if env["platform"] == "macos":
library = env.SharedLibrary(
BINDIR + "/openvic/libopenvic.{}.{}.framework/libopenvic.{}.{}".format(
BINDIR
+ "/openvic/libopenvic.{}.{}.framework/libopenvic.{}.{}".format(
godot_env["platform"], godot_env["target"], godot_env["platform"], godot_env["target"]
),
source=sources,
Expand Down
3 changes: 3 additions & 0 deletions extension/deps/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

Import("env")


def build_openvic_simulation(env):
ovsim_env = SConscript("openvic-simulation/SConstruct")
env.Append(LIBPATH=ovsim_env.openvic_simulation["LIBPATH"])
env.Prepend(LIBS=ovsim_env.openvic_simulation["LIBS"])
env.Append(CPPPATH=ovsim_env.openvic_simulation["INCPATH"])
env.openvic_simulation = ovsim_env.openvic_simulation


def build_gli(env):
gli_includes = ["gli", "gli/external"]
env.gli_loader = {}
env.gli_loader["INCPATH"] = [env.Dir(p) for p in gli_includes]
env.Append(CPPPATH=env.gli_loader["INCPATH"])


build_openvic_simulation(env)
build_gli(env)
42 changes: 19 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. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep operators at the start of a line.
That's way easier to read than at the end of a line.
In the current version it's clearly a && b.
In your proposed version b is just floating there without context.

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,14 @@ 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 = [&]() -> Color (*const)(const Color&) {
switch (button_state) {
case HOVER: return hover_colour;
case PRESSED: return pressed_colour;
case DISABLED: return disabled_colour;
default: return 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 +142,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 +177,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 @@ -7,7 +7,7 @@

namespace OpenVic {
class GFXCorneredTileSupportingTexture : public godot::AtlasTexture {
GDCLASS(GFXCorneredTileSupportingTexture, godot::AtlasTexture)
GDCLASS(GFXCorneredTileSupportingTexture, godot::AtlasTexture);

protected:
godot::Vector2i PROPERTY_ACCESS(cornered_tile_border_size, protected);
Expand All @@ -25,10 +25,10 @@ namespace OpenVic {
};

class GFXButtonStateTexture : public GFXCorneredTileSupportingTexture {
GDCLASS(GFXButtonStateTexture, GFXCorneredTileSupportingTexture)
GDCLASS(GFXButtonStateTexture, GFXCorneredTileSupportingTexture);

public:
enum ButtonState {
enum ButtonState { //
HOVER,
PRESSED,
DISABLED,
Expand Down Expand Up @@ -68,7 +68,7 @@ namespace OpenVic {
};

class GFXButtonStateHavingTexture : public GFXCorneredTileSupportingTexture {
GDCLASS(GFXButtonStateHavingTexture, GFXCorneredTileSupportingTexture)
GDCLASS(GFXButtonStateHavingTexture, GFXCorneredTileSupportingTexture);

std::array<godot::Ref<GFXButtonStateTexture>, GFXButtonStateTexture::BUTTON_STATE_COUNT> button_state_textures;

Expand Down
25 changes: 11 additions & 14 deletions extension/src/openvic-extension/classes/GFXMaskedFlagTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,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()
);
button_image =
Image::create(overlay_image->get_width(), overlay_image->get_height(), false, overlay_image->get_format());
ERR_FAIL_NULL_V(button_image, FAILED);
}

Expand All @@ -33,10 +32,9 @@ Error GFXMaskedFlagTexture::_generate_combined_image() {
if (mask_image.is_valid() && flag_image.is_valid() && flag_image_rect.has_area()) {
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
for (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) {
Expand All @@ -46,10 +44,8 @@ Error GFXMaskedFlagTexture::_generate_combined_image() {
// 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()
) {
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()) {
const Color mask_image_colour = mask_image->get_pixelv(mask_image_point);

// Rescale from mask_image to flag_image coordinates.
Expand Down Expand Up @@ -152,7 +148,8 @@ 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, vformat(
new_masked_flag, FAILED,
vformat(
"Invalid type for GFX sprite %s: %s (expected %s)", gfx_masked_flag_name,
Utilities::std_to_godot_string(sprite->get_type()),
Utilities::std_to_godot_string(GFX::MaskedFlag::get_type_static())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenVic {
struct CountryInstance;

class GFXMaskedFlagTexture : public GFXButtonStateHavingTexture {
GDCLASS(GFXMaskedFlagTexture, GFXButtonStateHavingTexture)
GDCLASS(GFXMaskedFlagTexture, GFXButtonStateHavingTexture);

GFX::MaskedFlag const* PROPERTY(gfx_masked_flag, nullptr);
CountryDefinition const* PROPERTY(flag_country, nullptr);
Expand Down Expand Up @@ -44,13 +44,13 @@ namespace OpenVic {
godot::String get_gfx_masked_flag_name() const;

/* 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(
godot::Error set_flag_country_and_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::Error set_flag_country_name_and_type( //
godot::String const& new_flag_country_name, godot::StringName const& new_flag_type
);

Expand Down
13 changes: 6 additions & 7 deletions extension/src/openvic-extension/classes/GFXPieChartTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,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,7 +99,6 @@ Error GFXPieChartTexture::_generate_pie_chart_image() {
} else {

pie_chart_image->fill(background_colour);

}

if (can_update) {
Expand All @@ -123,7 +122,7 @@ Error GFXPieChartTexture::set_slices_array(godot_pie_chart_data_t const& new_sli
);
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_weight_key()] //
};
if (slice.weight > 0.0f) {
total_weight += slice.weight;
Expand Down Expand Up @@ -182,10 +181,10 @@ 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, vformat(
new_pie_chart, FAILED,
vformat(
"Invalid type for GFX sprite %s: %s (expected %s)", gfx_pie_chart_name,
Utilities::std_to_godot_string(sprite->get_type()),
Utilities::std_to_godot_string(GFX::PieChart::get_type_static())
Utilities::std_to_godot_string(sprite->get_type()), Utilities::std_to_godot_string(GFX::PieChart::get_type_static())
)
);
return set_gfx_pie_chart(new_pie_chart);
Expand Down
Loading
Loading