40 lines
728 B
GDScript
40 lines
728 B
GDScript
extends Node
|
|
class_name TopicData
|
|
|
|
|
|
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)
|
|
dirty_flag = true
|
|
|
|
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:
|
|
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
|