diff --git a/scripts/autoload/grid_system.gd b/scripts/autoload/grid_system.gd index 5404b77..4e24701 100644 --- a/scripts/autoload/grid_system.gd +++ b/scripts/autoload/grid_system.gd @@ -163,13 +163,10 @@ func load_room_from_file(path: String) -> Error: return FileAccess.get_open_error() var text: String = f.get_as_text() f.close() - var json := JSON.new() - var err: Error = json.parse(text) - if err != OK: - return err - if not json.data is Dictionary: + var data: Variant = JSON.parse_string(text) + if not data is Dictionary: return ERR_INVALID_DATA - return load_room(json.data) + return load_room(data) ## ------------------------------------------------------------------ diff --git a/scripts/autoload/save_manager.gd b/scripts/autoload/save_manager.gd index 3c0da46..a048f38 100644 --- a/scripts/autoload/save_manager.gd +++ b/scripts/autoload/save_manager.gd @@ -128,19 +128,9 @@ func load_game() -> Dictionary: var raw_text: String = file.get_as_text() file.close() - var json: JSON = JSON.new() - var parse_error: Error = json.parse(raw_text) - if parse_error != OK: - var reason: String = ( - "JSON parse error at line %d: %s" % [json.get_error_line(), json.get_error_message()] - ) - push_error("[SaveManager] load_game: %s" % reason) - load_failed.emit(reason) - return {} - - var raw_data: Variant = json.get_data() + var raw_data: Variant = JSON.parse_string(raw_text) if typeof(raw_data) != TYPE_DICTIONARY: - var reason: String = "Parsed JSON is not a Dictionary." + var reason: String = "Parsed JSON is not a Dictionary or failed to parse." push_error("[SaveManager] load_game: %s" % reason) load_failed.emit(reason) return {} diff --git a/scripts/autoload/settings_manager.gd b/scripts/autoload/settings_manager.gd index 5a303af..4fe98bd 100644 --- a/scripts/autoload/settings_manager.gd +++ b/scripts/autoload/settings_manager.gd @@ -72,23 +72,13 @@ func load_settings() -> void: var json_string: String = file.get_as_text() file.close() - var json: JSON = JSON.new() - var error: Error = json.parse(json_string) - if error == OK: - var loaded_settings: Variant = json.data - if loaded_settings is Dictionary: - _merge_dict(settings, loaded_settings as Dictionary) - _apply_loaded_bindings() - _print_debug("Settings loaded successfully from JSON") - else: - _print_error("Settings JSON is not a dictionary") + var loaded_settings: Variant = JSON.parse_string(json_string) + if loaded_settings is Dictionary: + _merge_dict(settings, loaded_settings as Dictionary) + _apply_loaded_bindings() + _print_debug("Settings loaded successfully from JSON") else: - _print_error( - ( - "JSON Parse Error: %s at line %d" - % [json.get_error_message(), json.get_error_line()] - ) - ) + _print_error("Settings JSON is not a dictionary or failed to parse") else: _print_error("Failed to open settings file for reading: %s" % SAVE_PATH) diff --git a/scripts/combat/room_loader.gd b/scripts/combat/room_loader.gd index 802cdee..27a7abd 100644 --- a/scripts/combat/room_loader.gd +++ b/scripts/combat/room_loader.gd @@ -26,17 +26,12 @@ static func load_room_data(room_id: String) -> Dictionary: var text := f.get_as_text() f.close() - var json := JSON.new() - var err := json.parse(text) - if err != OK: - push_error("Failed to parse room JSON: " + path + " Error: " + json.get_error_message()) + var data: Variant = JSON.parse_string(text) + if data == null or not data is Dictionary: + push_error("Failed to parse room JSON or data is not a Dictionary: " + path) return {} - if not json.data is Dictionary: - push_error("Room JSON data is not a Dictionary: " + path) - return {} - - return json.data as Dictionary + return data as Dictionary ## Configure the GridSystem with room layout. diff --git a/scripts/core/encounter_system.gd b/scripts/core/encounter_system.gd index 0560975..3958bb1 100644 --- a/scripts/core/encounter_system.gd +++ b/scripts/core/encounter_system.gd @@ -52,12 +52,8 @@ static func _getConfig() -> Dictionary: var f: FileAccess = FileAccess.open(ENCOUNTERS_CONFIG_PATH, FileAccess.READ) if not f: return {} - var json := JSON.new() - var err: Error = json.parse(f.get_as_text()) + var data: Variant = JSON.parse_string(f.get_as_text()) f.close() - if err != OK: - return {} - var data: Variant = json.data if data is Dictionary: return data as Dictionary return {} diff --git a/scripts/core/loot_table.gd b/scripts/core/loot_table.gd index a271cd6..9ca4252 100644 --- a/scripts/core/loot_table.gd +++ b/scripts/core/loot_table.gd @@ -26,17 +26,12 @@ static func load_loot_table(table_id: String) -> LootTable: var text := f.get_as_text() f.close() - var json := JSON.new() - var err := json.parse(text) - if err != OK: - push_error("LootTable: JSON parse error in %s: %s" % [path, json.get_error_message()]) + var data_v: Variant = JSON.parse_string(text) + if data_v == null or not data_v is Dictionary: + push_error("LootTable: JSON parse error or not a Dictionary in " + path) return null - if not json.data is Dictionary: - push_error("LootTable: Expected Dictionary at root of " + path) - return null - - var data: Dictionary = json.data + var data: Dictionary = data_v as Dictionary var table := LootTable.new() table.min_rolls = int(data.get("min_rolls", 1)) table.max_rolls = int(data.get("max_rolls", 1)) diff --git a/scripts/core/room_generator.gd b/scripts/core/room_generator.gd index 4dbfb14..ccbd02b 100644 --- a/scripts/core/room_generator.gd +++ b/scripts/core/room_generator.gd @@ -83,12 +83,14 @@ static func _getBiomeParams(biomeId: String) -> Dictionary: var f := FileAccess.open(BIOMES_CONFIG_PATH, FileAccess.READ) if not f: return {} - var json := JSON.new() - var err := json.parse(f.get_as_text()) + var text := f.get_as_text() f.close() - if err != OK: + + var data_v: Variant = JSON.parse_string(text) + if not data_v is Dictionary: return {} - var data: Dictionary = json.data as Dictionary + + var data: Dictionary = data_v as Dictionary var biomes_data: Dictionary = data.get("biomes", {}) as Dictionary return biomes_data.get(biomeId, {}) as Dictionary diff --git a/scripts/entities/apparition_renderer.gd b/scripts/entities/apparition_renderer.gd index 6621253..1c72891 100644 --- a/scripts/entities/apparition_renderer.gd +++ b/scripts/entities/apparition_renderer.gd @@ -129,18 +129,12 @@ func _load_rig_config() -> void: var json_text: String = file.get_as_text() file.close() - var json: JSON = JSON.new() - var error: Error = json.parse(json_text) - if error == OK and json.data is Dictionary: - _rig_config = json.data as Dictionary + var data: Variant = JSON.parse_string(json_text) + if data is Dictionary: + _rig_config = data as Dictionary _apply_rig_config() else: - push_error( - ( - "ApparitionRenderer: failed to parse JSON config or config is not a Dictionary: %s" - % json.get_error_message() - ) - ) + push_error("ApparitionRenderer: failed to parse JSON config or config is not a Dictionary") func _apply_rig_config() -> void: