2020-10-15 17:23:55 +00:00
|
|
|
tool
|
2021-06-28 22:33:56 +00:00
|
|
|
class_name Data
|
|
|
|
extends Object
|
|
|
|
# Main creature class
|
|
|
|
|
|
|
|
#05. signals
|
|
|
|
#06. enums
|
|
|
|
#07. constants
|
|
|
|
#08. exported variables
|
|
|
|
#09. public variables
|
|
|
|
var datas = {}
|
|
|
|
|
|
|
|
#10. private variables
|
|
|
|
#11. onready variables
|
|
|
|
#12. optional built-in virtual _init method
|
|
|
|
#13. built-in virtual _ready method
|
|
|
|
#14. remaining built-in virtual methods
|
|
|
|
#15. public methods
|
|
|
|
|
|
|
|
func _init( p_name = null ):
|
|
|
|
set_data( "name", p_name )
|
|
|
|
|
|
|
|
func get_data( p_key, p_default_value = null ):
|
|
|
|
return datas.get( p_key, p_default_value )
|
|
|
|
|
|
|
|
func set_data( p_key, p_value ):
|
|
|
|
datas[ p_key ] = p_value
|
|
|
|
|
|
|
|
func save( filename ):
|
|
|
|
var file = File.new()
|
|
|
|
if file.file_exists( filename ):
|
|
|
|
file.open( filename, File.READ )
|
|
|
|
datas = JSON.parse(file.get_as_text()).get_result()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
func load( filename ):
|
|
|
|
var file = File.new()
|
|
|
|
if file.file_exists( filename ):
|
|
|
|
file.open( filename, File.READ )
|
|
|
|
datas = JSON.parse(file.get_as_text()).get_result()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
func from_dictionary( dictionary ):
|
|
|
|
datas = dictionary
|
|
|
|
|
|
|
|
#16. private methods
|