@@ -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- " \n Error at line " , json. get_error_line (), " : " , json. get_error_message ());
27+ " \n Error 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;
0 commit comments