diary/system/data/message_data/message_data_singleton.gd

64 lines
1.5 KiB
GDScript3
Raw Normal View History

extends Node
class_name MessageData
signal message_added(message)
signal message_group_added(message_group)
var dirty_flag = false
var loaded_message_groups = []
func add_message(content, time_stamp, user):
var message_group: MessageGroup
if loaded_message_groups.empty():
message_group = _add_message_group(time_stamp, user)
else:
var latest_message_group = loaded_message_groups[-1]
if latest_message_group.associated_user != user:
message_group = _add_message_group(time_stamp, user)
else:
var latest_message = latest_message_group.messages[-1]
if time_stamp - latest_message.time_stamp >= 120:
message_group = _add_message_group(time_stamp, user)
else:
message_group = loaded_message_groups[-1]
var message = Message.new()
message.content = content
message.time_stamp = time_stamp
message_group.add(message)
emit_signal("message_added", message)
# var node = message.create_node()
# message_group.associated_container.add(node)
func load_data():
# TODO: load data.
pass
func save_data():
if dirty_flag:
# TODO: Save data.
pass
# dirty_flag needs to be set to false after successful save!
dirty_flag = false
func _add_message_group(time_stamp, user) -> MessageGroup:
var message_group = MessageGroup.new()
message_group.associated_user = user
message_group.time_stamp = time_stamp
loaded_message_groups.append(message_group)
emit_signal("message_group_added", message_group)
# var container = message_group.create_container()
# UI.message_feed_container.add_child(container)
return message_group