Skip to content

Commit ba3e974

Browse files
authored
Merge pull request OpenVicProject#125 from OpenVicProject/import-fix
2 parents 0a1a50c + 9843807 commit ba3e974

File tree

68 files changed

+762
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+762
-125
lines changed

extension/src/LoadGameCompatibility.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ Error GameSingleton::_load_terrain_variants_compatibility_mode(String const& ter
8888
}
8989

9090
// Load the terrain texture sheet and prepare to slice it up
91-
Ref<Image> terrain_sheet;
92-
terrain_sheet.instantiate();
93-
if (terrain_sheet->load(terrain_texturesheet_path) != OK) {
91+
Ref<Image> terrain_sheet = load_godot_image(terrain_texturesheet_path);
92+
if (terrain_sheet.is_null()) {
9493
UtilityFunctions::push_error("Failed to load terrain texture sheet: ", terrain_texturesheet_path);
9594
return FAILED;
9695
}

extension/src/LoadGameOpenVic.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ static Error _load_json_file(String const& file_description, String const& file_
1919
return err == OK ? FAILED : err;
2020
}
2121
const String json_string = file->get_as_text();
22-
JSON json;
23-
err = json.parse(json_string);
22+
Ref<JSON> json;
23+
json.instantiate();
24+
err = json->parse(json_string);
2425
if (err != OK) {
2526
UtilityFunctions::push_error("Failed to parse ", file_description, " file as JSON: ", file_path,
26-
"\nError at line ", json.get_error_line(), ": ", json.get_error_message());
27+
"\nError at line ", json->get_error_line(), ": ", json->get_error_message());
2728
return err;
2829
}
29-
result = json.get_data();
30+
result = json->get_data();
3031
return err;
3132
}
3233

@@ -175,12 +176,10 @@ Error GameSingleton::_parse_terrain_entry(String const& identifier, Variant cons
175176
return FAILED;
176177
}
177178
const String terrain_path = terrain_texture_dir_path + identifier;
178-
Ref<Image> terrain_image;
179-
terrain_image.instantiate();
180-
const Error err = terrain_image->load(terrain_path);
181-
if (err != OK) {
179+
const Ref<Image> terrain_image = load_godot_image(terrain_path);
180+
if (terrain_image.is_null()) {
182181
UtilityFunctions::push_error("Failed to load terrain image: ", terrain_path);
183-
return err;
182+
return FAILED;
184183
}
185184
return ERR(terrain_variants.add_item({ godot_to_std_string(identifier), colour, terrain_image }));
186185
}
@@ -229,18 +228,15 @@ Error GameSingleton::_load_map_images(String const& province_image_path, String
229228
}
230229

231230
// Load images
232-
Ref<Image> province_image, terrain_image;
233-
province_image.instantiate();
234-
terrain_image.instantiate();
235-
Error err = province_image->load(province_image_path);
236-
if (err != OK) {
231+
Ref<Image> province_image = load_godot_image(province_image_path);
232+
if (province_image.is_null()) {
237233
UtilityFunctions::push_error("Failed to load province image: ", province_image_path);
238-
return err;
234+
return FAILED;
239235
}
240-
err = terrain_image->load(terrain_image_path);
241-
if (err != OK) {
236+
Ref<Image> terrain_image = load_godot_image(terrain_image_path);
237+
if (terrain_image.is_null()) {
242238
UtilityFunctions::push_error("Failed to load terrain image: ", terrain_image_path);
243-
return err;
239+
return FAILED;
244240
}
245241

246242
if (flip_vertical) {
@@ -249,6 +245,7 @@ Error GameSingleton::_load_map_images(String const& province_image_path, String
249245
}
250246

251247
// Validate dimensions and format
248+
Error err = OK;
252249
const Vector2i province_dims = province_image->get_size(), terrain_dims = terrain_image->get_size();
253250
if (province_dims.x < 1 || province_dims.y < 1) {
254251
UtilityFunctions::push_error("Invalid dimensions (", province_dims.x, "x", province_dims.y, ") for province image: ", province_image_path);
@@ -378,16 +375,14 @@ Error GameSingleton::_load_goods(String const& defines_path, String const& icons
378375
});
379376
game_manager.good_manager.lock_goods();
380377
for (Good const& good : game_manager.good_manager.get_goods()) {
381-
Ref<Image> image;
382-
image.instantiate();
383378
const String path = icons_dir_path + String { "/" } + std_to_godot_string(good.get_identifier()) + ".png";
384-
const Error good_err = image->load(path);
385-
if (good_err || image.is_null()) {
379+
const Ref<Image> image = load_godot_image(path);
380+
if (image.is_null()) {
386381
UtilityFunctions::push_error("Failed to load good icon image: ", path);
387382
err = FAILED;
388383
continue;
389384
}
390-
Ref<Texture> tex = ImageTexture::create_from_image(image);
385+
const Ref<Texture> tex = ImageTexture::create_from_image(image);
391386
if (tex.is_null()) {
392387
UtilityFunctions::push_error("Failed to generate good icon texture: ", path);
393388
err = FAILED;

extension/src/Utilities.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "Utilities.hpp"
2+
3+
#include <godot_cpp/classes/resource_loader.hpp>
4+
#include <godot_cpp/variant/utility_functions.hpp>
5+
6+
using namespace godot;
7+
using namespace OpenVic;
8+
9+
Ref<Image> OpenVic::load_godot_image(String const& path) {
10+
if (path.begins_with("res://")) {
11+
ResourceLoader* loader = ResourceLoader::get_singleton();
12+
return loader ? loader->load(path) : nullptr;
13+
} else {
14+
return Image::load_from_file(path);
15+
}
16+
}

extension/src/Utilities.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <godot_cpp/variant/string.hpp>
3+
#include <godot_cpp/classes/image.hpp>
44

55
#include "openvic/Types.hpp"
66

@@ -15,4 +15,6 @@ namespace OpenVic {
1515
inline godot::String std_to_godot_string(std::string const& str) {
1616
return str.c_str();
1717
}
18+
19+
godot::Ref<godot::Image> load_godot_image(godot::String const& path);
1820
}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
[remap]
22

3-
importer="keep"
3+
importer="image"
4+
type="Image"
5+
uid="uid://b1kuq7k8prdc5"
6+
path="res://.godot/imported/good_aeroplanes.png-7a57a10fe765bbdfb738ac1b788a0a02.image"
7+
8+
[deps]
9+
10+
source_file="res://art/economy/goods/good_aeroplanes.png"
11+
dest_files=["res://.godot/imported/good_aeroplanes.png-7a57a10fe765bbdfb738ac1b788a0a02.image"]
12+
13+
[params]
14+
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
[remap]
22

3-
importer="keep"
3+
importer="image"
4+
type="Image"
5+
uid="uid://mdsbfb1kx2yr"
6+
path="res://.godot/imported/good_ammunition.png-ab17c8b5b6f699fce3dd4d8842555fcc.image"
7+
8+
[deps]
9+
10+
source_file="res://art/economy/goods/good_ammunition.png"
11+
dest_files=["res://.godot/imported/good_ammunition.png-ab17c8b5b6f699fce3dd4d8842555fcc.image"]
12+
13+
[params]
14+
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
[remap]
22

3-
importer="keep"
3+
importer="image"
4+
type="Image"
5+
uid="uid://bao8gdl5pjr3l"
6+
path="res://.godot/imported/good_artillery.png-ccb7bdbd694b82b7887edc5e918f891c.image"
7+
8+
[deps]
9+
10+
source_file="res://art/economy/goods/good_artillery.png"
11+
dest_files=["res://.godot/imported/good_artillery.png-ccb7bdbd694b82b7887edc5e918f891c.image"]
12+
13+
[params]
14+
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
[remap]
22

3-
importer="keep"
3+
importer="image"
4+
type="Image"
5+
uid="uid://cbgodumv1urxc"
6+
path="res://.godot/imported/good_automobiles.png-e7135793fbe9163a9843b57ef1cc9b26.image"
7+
8+
[deps]
9+
10+
source_file="res://art/economy/goods/good_automobiles.png"
11+
dest_files=["res://.godot/imported/good_automobiles.png-e7135793fbe9163a9843b57ef1cc9b26.image"]
12+
13+
[params]
14+
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
[remap]
22

3-
importer="keep"
3+
importer="image"
4+
type="Image"
5+
uid="uid://1uru8eufge1w"
6+
path="res://.godot/imported/good_canned_food.png-c83bafca536c627868b367290d5be590.image"
7+
8+
[deps]
9+
10+
source_file="res://art/economy/goods/good_canned_food.png"
11+
dest_files=["res://.godot/imported/good_canned_food.png-c83bafca536c627868b367290d5be590.image"]
12+
13+
[params]
14+
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
[remap]
22

3-
importer="keep"
3+
importer="image"
4+
type="Image"
5+
uid="uid://gkjpiul6248l"
6+
path="res://.godot/imported/good_cattle.png-089bb1aba8f91888c577c6cb83992c61.image"
7+
8+
[deps]
9+
10+
source_file="res://art/economy/goods/good_cattle.png"
11+
dest_files=["res://.godot/imported/good_cattle.png-089bb1aba8f91888c577c6cb83992c61.image"]
12+
13+
[params]
14+

0 commit comments

Comments
 (0)