Skip to content
Merged
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
9 changes: 3 additions & 6 deletions scripts/autoload/grid_system.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)


## ------------------------------------------------------------------
Expand Down
14 changes: 2 additions & 12 deletions scripts/autoload/save_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
22 changes: 6 additions & 16 deletions scripts/autoload/settings_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 4 additions & 9 deletions scripts/combat/room_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions scripts/core/encounter_system.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
13 changes: 4 additions & 9 deletions scripts/core/loot_table.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 6 additions & 4 deletions scripts/core/room_generator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 4 additions & 10 deletions scripts/entities/apparition_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading