mirror of
https://codeberg.org/Ikatono/TierMaker.git
synced 2025-10-28 20:45:35 -05:00
basically function but needs a lot of refinement
This commit is contained in:
@@ -1,35 +1,75 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public partial class settings_popup : Popup
|
||||
public partial class settings_popup : PopupPanel
|
||||
{
|
||||
[Signal]
|
||||
public delegate void BeforeOkEventHandler();
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
Transient = true;
|
||||
Exclusive = true;
|
||||
}
|
||||
|
||||
private readonly ConcurrentQueue<Action> ActionQueue = new();
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
// //perform 1 action every frame
|
||||
// if (ActionQueue.TryDequeue(out Action a))
|
||||
// {
|
||||
// GD.Print("Found action");
|
||||
// a?.Invoke();
|
||||
// }
|
||||
}
|
||||
public void _on_cancel_button_pressed()
|
||||
{
|
||||
GD.Print("Cancel pressed");
|
||||
Hide();
|
||||
}
|
||||
public void _on_ok_button_pressed()
|
||||
{
|
||||
GD.Print("OK pressed");
|
||||
var tcw = GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher");
|
||||
string chName = GetNode<LineEdit>("%ChannelNameEdit").Text;
|
||||
Task.Run(tcw.ConnectAsync).ContinueWith(t => tcw.Authenticate(null, null))
|
||||
.ContinueWith(t => tcw.RequestTags())
|
||||
.ContinueWith(t => tcw.JoinChannel(chName))
|
||||
.ContinueWith(FinishConnection);
|
||||
ProcessMode = ProcessModeEnum.Disabled;
|
||||
}
|
||||
private void FinishConnection(Task t)
|
||||
{
|
||||
GD.Print(t.Status);
|
||||
if (t.IsCompletedSuccessfully)
|
||||
{
|
||||
CallDeferred(nameof(SuccessfulConnection));
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr(t.Exception);
|
||||
ActionQueue.Enqueue(() => ProcessMode = ProcessModeEnum.Inherit);
|
||||
}
|
||||
}
|
||||
private void SuccessfulConnection()
|
||||
{
|
||||
GD.Print("Running completion task");
|
||||
var tcw = GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher");
|
||||
if (tcw.State != System.Net.WebSockets.WebSocketState.Open)
|
||||
throw new Exception("Websocket closed");
|
||||
var settings = GetNode<Settings>("/root/Settings");
|
||||
settings.AllowModerators = GetNode<CheckBox>("%CheckBoxModerator").ButtonPressed;
|
||||
settings.Command = GetNode<LineEdit>("%CommandEdit").Text;
|
||||
settings.SetUserLists(GetNode<TextEdit>("%WhiteListEdit").Text.Split('\n',
|
||||
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries),
|
||||
GetNode<TextEdit>("%BlackListEdit").Text.Split('\n',
|
||||
StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
|
||||
var tcw = GetNode<TwitchChatWatcher>("/root/TwitchChatWatcher");
|
||||
tcw.ConnectAsync().RunSynchronously();
|
||||
tcw.Authenticate().RunSynchronously();
|
||||
tcw.JoinChannel(GetNode<LineEdit>("%ChannelNameEdit").Text).RunSynchronously();
|
||||
ProcessMode = ProcessModeEnum.Inherit;
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user