40 lines
1.1 KiB
GDScript
40 lines
1.1 KiB
GDScript
extends Object
|
|
class_name MiscellaneousData
|
|
|
|
const FILE_NAME = "miscellaneous.dat"
|
|
|
|
var dirty_flag = false
|
|
var big_interaction = 0 # Time stamp of last sent or filled out message.
|
|
var small_interaction = 0 # Time stamp of last key press
|
|
|
|
|
|
func load_data():
|
|
var file = File.new()
|
|
if not file.file_exists("user://" + FILE_NAME):
|
|
return
|
|
file.open("user://" + FILE_NAME, File.READ)
|
|
var json_string = file.get_as_text()
|
|
if validate_json(json_string):
|
|
printerr("\"" + FILE_NAME + "\" was found, but is corrupted.")
|
|
return
|
|
var data = parse_json(json_string)
|
|
if data.has("big_interaction"):
|
|
big_interaction = data["big_interaction"]
|
|
if data.has("small_interaction"):
|
|
small_interaction = data["small_interaction"]
|
|
|
|
|
|
func save_data():
|
|
if dirty_flag:
|
|
var data = {
|
|
"big_interaction" : big_interaction,
|
|
"small_interaction" : small_interaction,
|
|
}
|
|
var json_string = to_json(data)
|
|
var file = File.new()
|
|
file.open("user://" + FILE_NAME, File.WRITE)
|
|
file.store_string(json_string)
|
|
file.close()
|
|
# dirty_flag needs to be set to false after successful save!
|
|
dirty_flag = false
|