This repository has been archived on 2023-11-16. You can view files and clone it, but cannot push or open issues or pull requests.
GOA/godot/Playbutton.cs
2023-09-24 12:10:42 +02:00

57 lines
3.3 KiB
C#

using Godot;
using System;
using System.Net.Cache;
public partial class Playbutton : Button
{
private LLMApiRequests llmApiRequests;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
SetProcess(false);
llmApiRequests = GetNode<LLMApiRequests>("/root/LLMApiRequests");
}
public override void _Pressed()
{
nuint Strength = (nuint) GetTree().Root.GetNode<SpinBox>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Strength/SpinBox").Value;
nuint Perception = (nuint) GetTree().Root.GetNode<SpinBox>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Perception/SpinBox").Value;
nuint Endurance = (nuint) GetTree().Root.GetNode<SpinBox>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Endurance/SpinBox").Value;
nuint Charisma = (nuint) GetTree().Root.GetNode<SpinBox>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Charisma/SpinBox").Value;
nuint Intelligence = (nuint) GetTree().Root.GetNode<SpinBox>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Intelligence/SpinBox").Value;
nuint Agility = (nuint) GetTree().Root.GetNode<SpinBox>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Agility/SpinBox").Value;
nuint Luck = (nuint) GetTree().Root.GetNode<SpinBox>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Luck/SpinBox").Value;
string Name = GetTree().Root.GetNode<TextEdit>("Root/MainMenu/MainMenuCanvas/VBoxContainer/Name/NameEdit").Text;
Player player = new Player{Name = Name, Strength = Strength, Perception = Perception, Endurance = Endurance, Charisma = Charisma, Intelligence = Intelligence, Agility = Agility, Luck = Luck};
if (player.isValid())
{
llmApiRequests?.PostToApi(OnRequestCompleted);
var node = this.GetTree().Root.GetNode<CanvasLayer>("Root/Ingame/IngameCanvas");
node.SetProcess(true);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Strength").Text = String.Format("Strength: {0}", Strength);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Perception").Text = String.Format("Perception: {0}", Perception);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Endurance").Text = String.Format("Endurance: {0}", Endurance);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Charisma").Text = String.Format("Charisma: {0}", Charisma);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Intelligence").Text = String.Format("Intelligence: {0}", Intelligence);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Agility").Text = String.Format("Agility: {0}", Agility);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Luck").Text = String.Format("Luck: {0}", Luck);
GetTree().Root.GetNode<TextEdit>("Root/Ingame/IngameCanvas/Stats/Name").Text = String.Format("Name: {0}", Name);
node.Show();
var GParent = this.GetTree().Root.GetNode<CanvasLayer>("Root/MainMenu/MainMenuCanvas");
GParent.Hide();
}
}
private void OnRequestCompleted(long result, long responseCode, string[] headers, byte[] body)
{
// Godot.Collections.Dictionary json = Json.ParseString(System.Text.Encoding.UTF8.GetString(body)).AsGodotDictionary();
// GD.Print(json["name"]);
// GD.Print(Json.ParseString(System.Text.Encoding.UTF8.GetString(body)).AsGodotDictionary());
GD.Print(System.Text.Encoding.UTF8.GetString(body));
}
}