diary/system/data/data_singleton.gd

46 lines
956 B
GDScript3
Raw Normal View History

extends Node
2022-06-06 17:37:28 +02:00
# This is not for configuration data. See settings_singleton.gd.
2022-06-04 13:33:00 +02:00
signal loaded()
var messages: MessageData
var topics: TopicData
2022-06-05 14:22:08 +02:00
var miscellaneous: MiscellaneousData
func _ready():
var autosave_timer = Timer.new()
2022-05-24 21:31:30 +02:00
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()
2022-06-04 13:33:00 +02:00
func setup():
messages = MessageData.new()
topics = TopicData.new()
2022-06-05 14:22:08 +02:00
miscellaneous = MiscellaneousData.new()
2022-06-04 13:33:00 +02:00
yield(get_tree(), "idle_frame")
_load_data()
2022-06-06 17:37:28 +02:00
PingSystem.reschedule_pings()
yield(get_tree(), "idle_frame")
PingSystem.reevaluate_unreceived_pings()
func _load_data():
messages.load_data()
topics.load_data()
2022-06-05 14:22:08 +02:00
miscellaneous.load_data()
2022-06-04 13:33:00 +02:00
emit_signal("loaded")
func _save_data():
messages.save_data()
topics.save_data()
2022-06-05 14:22:08 +02:00
miscellaneous.save_data()