diary/system/data/data_singleton.gd
2022-06-06 17:37:28 +02:00

46 lines
956 B
GDScript

extends Node
# This is not for configuration data. See settings_singleton.gd.
signal loaded()
var messages: MessageData
var topics: TopicData
var miscellaneous: MiscellaneousData
func _ready():
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)
func _notification(what):
if what == NOTIFICATION_WM_QUIT_REQUEST:
_save_data()
func setup():
messages = MessageData.new()
topics = TopicData.new()
miscellaneous = MiscellaneousData.new()
yield(get_tree(), "idle_frame")
_load_data()
PingSystem.reschedule_pings()
yield(get_tree(), "idle_frame")
PingSystem.reevaluate_unreceived_pings()
func _load_data():
messages.load_data()
topics.load_data()
miscellaneous.load_data()
emit_signal("loaded")
func _save_data():
messages.save_data()
topics.save_data()
miscellaneous.save_data()