diary/system/data/data_singleton.gd

39 lines
654 B
GDScript3
Raw Normal View History

extends Node
var messages: MessageData
var topics: TopicData
func _ready():
messages = MessageData.new()
topics = TopicData.new()
var autosave_timer = Timer.new()
autosave_timer.wait_time = 600.0 # Every ten minutes.
autosave_timer.autostart = true
autosave_timer.connect("timeout", self, "_save_data")
add_child(autosave_timer)
yield(get_tree(), "idle_frame")
_load_data()
func _notification(what):
if what == NOTIFICATION_WM_QUIT_REQUEST:
_save_data()
func _exit_tree():
messages.free()
topics.free()
func _load_data():
messages.load_data()
topics.load_data()
func _save_data():
messages.save_data()
topics.save_data()