Fixed a bug in Data Manager
This commit is contained in:
parent
203e91cdab
commit
9235bac737
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
MIT License Copyright (c) 2021 Leon Rauschenberg
|
||||
MIT License Copyright (c) 2021 Leon Rauschenberg, Noah Steinberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -17,8 +17,8 @@ var global_data = {}
|
||||
|
||||
|
||||
func _ready():
|
||||
game_version = ProjectSettings.get_setting("application/config/version")
|
||||
load_from_file()
|
||||
game_version = ProjectSettings.get_setting("application/config/version")
|
||||
print(game_version)
|
||||
|
||||
|
||||
@ -46,8 +46,6 @@ func load_from_file():
|
||||
default_data()
|
||||
push_error("Can't parse JSON, Save File is corrupted")
|
||||
return
|
||||
else:
|
||||
return
|
||||
f.close()
|
||||
global_data = text.result
|
||||
|
||||
|
@ -5,40 +5,31 @@ extends RPGH_DataManager
|
||||
var value setget _set_value, _get_value
|
||||
|
||||
var _key = ""
|
||||
var _value = null
|
||||
var map_key = ""
|
||||
var event_key = ""
|
||||
var _initial_value = null
|
||||
|
||||
var data
|
||||
var _data
|
||||
|
||||
func _init(key: String, initial_value = null, map = null, event = null):
|
||||
data = RPGH.get_node("DataManager").global_data
|
||||
_data = RPGH.get_node("DataManager").global_data
|
||||
_initial_value = initial_value
|
||||
|
||||
var map_key = ""
|
||||
var event_key = ""
|
||||
if map != null:
|
||||
yield(map, "ready")
|
||||
map_key = map.name + "_"
|
||||
if event != null:
|
||||
event_key = event.name + "_"
|
||||
|
||||
_key = map_key + event_key + key
|
||||
_value = initial_value
|
||||
|
||||
if !data.has(_key):
|
||||
RPGH.get_node("DataManager").write_in_dictionary(_key, initial_value)
|
||||
return
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
func _set_value(new_value):
|
||||
_value = new_value
|
||||
if new_value == _initial_value:
|
||||
data.erase(_key)
|
||||
_data.erase(_key)
|
||||
else:
|
||||
RPGH.get_node("DataManager").write_in_dictionary(_key, _value)
|
||||
RPGH.get_node("DataManager").write_in_dictionary(_key, new_value)
|
||||
|
||||
|
||||
func _get_value():
|
||||
return _value
|
||||
if _key in _data:
|
||||
return _data[_key]
|
||||
else:
|
||||
return _initial_value
|
||||
|
Loading…
Reference in New Issue
Block a user