diff options
Diffstat (limited to 'scripts/Utils/MessageLogData.cs')
| -rw-r--r-- | scripts/Utils/MessageLogData.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/Utils/MessageLogData.cs b/scripts/Utils/MessageLogData.cs new file mode 100644 index 0000000..ed30062 --- /dev/null +++ b/scripts/Utils/MessageLogData.cs @@ -0,0 +1,48 @@ +using Godot; + +public partial class MessageLogData : Node +{ + public static MessageLogData Instance { get; private set; } + private Godot.Collections.Array<Message> messages = []; + public Godot.Collections.Array<Message> Messages {get => messages;} + +private Message LastMessage { + get { + if (messages.Count <= 0) { + return null; + } + return messages[^1]; + } + } + + public void ClearMessages() { + foreach (Message message in messages) { + message.QueueFree(); + } + } + + public override void _Ready() + { + base._Ready(); + Instance = this; + } + + public void AddMessage(string text) { + if (LastMessage != null && LastMessage.PlainText == text) { + LastMessage.Count++; + return; + } + + Message message = new(text); + messages.Add(message); + EmitSignal(SignalName.messageSent, message); + } + + /// <summary> + /// Acionado sempre que uma mensagem for adicionada para o log. + /// </summary> + /// <param name="text">Mensagem.</param> + [Signal] + public delegate void messageSentEventHandler(Message message); + +}
\ No newline at end of file |
