diff options
Diffstat (limited to 'scripts/Utils')
| -rw-r--r-- | scripts/Utils/MessageLogData.cs | 48 | ||||
| -rw-r--r-- | scripts/Utils/MessageLogData.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/Utils/SignalBus.cs | 6 |
3 files changed, 49 insertions, 6 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 diff --git a/scripts/Utils/MessageLogData.cs.uid b/scripts/Utils/MessageLogData.cs.uid new file mode 100644 index 0000000..0b8f55f --- /dev/null +++ b/scripts/Utils/MessageLogData.cs.uid @@ -0,0 +1 @@ +uid://dgb6vauj2v8sm diff --git a/scripts/Utils/SignalBus.cs b/scripts/Utils/SignalBus.cs index 7408db2..f5cb0d2 100644 --- a/scripts/Utils/SignalBus.cs +++ b/scripts/Utils/SignalBus.cs @@ -16,10 +16,4 @@ public partial class SignalBus : Node base._Ready(); Instance = this; } - /// <summary> - /// Acionado sempre que uma mensagem for adicionada para o log. - /// </summary> - /// <param name="text">Mensagem.</param> - [Signal] - public delegate void messageSentEventHandler(string text); } |
