diary/system/data/topic_data/topic_data_singleton.gd

40 lines
728 B
GDScript3
Raw Normal View History

extends Node
class_name TopicData
2022-05-21 14:56:02 +02:00
signal topic_added(topic, position)
var dirty_flag = false
var loaded_topics = []
func add_topic(position: int):
var topic = Topic.new()
loaded_topics.append(topic)
2022-05-21 14:56:02 +02:00
dirty_flag = true
2022-05-21 14:56:02 +02:00
emit_signal("topic_added", topic, position)
func sort_topics():
loaded_topics.sort_custom(self, "_compare_topic_index")
func _compare_topic_index(a, b):
return a.associated_node.parent.get_index() < b.associated_node.parent.get_index()
func load_data():
# TODO: Load data.
pass
func save_data():
if dirty_flag:
2022-05-21 14:56:02 +02:00
sort_topics() # Important before saving, to remain the order.
# TODO: Save data.
pass
# dirty_flag needs to be set to false after successful save!
dirty_flag = false