39 lines
1 KiB
C#
39 lines
1 KiB
C#
using Godot;
|
|
using SpacetimeDB;
|
|
using SpacetimeDB.Types;
|
|
|
|
public partial class ChatInput : LineEdit
|
|
{
|
|
public override void _EnterTree()
|
|
{
|
|
TextSubmitted += OnMessageInput;
|
|
}
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
DbConnection conn = Spacetime.Instance.Connection;
|
|
RegisterSubscriptions(conn);
|
|
}
|
|
|
|
void OnMessageInput(string text)
|
|
{
|
|
Spacetime.Instance.Connection.Reducers.SendMessage(text);
|
|
Text = "";
|
|
}
|
|
|
|
void RegisterSubscriptions(DbConnection conn)
|
|
{
|
|
conn.Reducers.OnSendMessage += Reducer_OnSendMessageEvent;
|
|
}
|
|
|
|
/// Our `OnSendMessageEvent` callback: print a warning if the reducer failed.
|
|
void Reducer_OnSendMessageEvent(ReducerEventContext ctx, string text)
|
|
{
|
|
var e = ctx.Event;
|
|
if (e.CallerIdentity == Spacetime.Instance.Identity && e.Status is Status.Failed(var error))
|
|
{
|
|
GD.PrintErr($"Failed to send message {text}: {error}");
|
|
}
|
|
}
|
|
}
|