idle-starship/scripts/Controller.cs
2025-09-12 08:34:06 -04:00

77 lines
2 KiB
C#

using System;
using Godot;
public partial class Controller : Node
{
private decimal LastTick = 0;
private bool TicksThrottled = false;
public Ship PlayerShip { get; private set; }
public Button ExitToMenuButton { get; private set; }
public Label ShipInfoLabel { get; private set; }
public override void _Ready()
{
base._Ready();
this.ExitToMenuButton = GetNode<Button>("Container/Top/ExitToMenuButton");
this.ExitToMenuButton.Pressed += OnExitToMenu;
this.ShipInfoLabel = GetNode<Label>("Container/TabContainer/Ship/ShipInfo/ShipInfoLabel");
CallDeferred("ReadyPlayerShip");
}
private void ReadyPlayerShip()
{
}
public void UpdatePlayerShip(Ship playerShip)
{
this.PlayerShip = playerShip;
}
public void OnTick(decimal tick, bool ticksThrottled)
{
this.LastTick = tick;
this.TicksThrottled = ticksThrottled;
CallDeferred("_OnUpdateGUI");
}
public void UpdateGUI()
{
CallDeferred("_OnUpdateGUI");
}
private void _OnUpdateGUI()
{
this.ShipInfoLabel.Text = $@"Name: {this.PlayerShip.Name}
Current Action: {this.PlayerShip.CurrentOrder?.Type.ToString() ?? "IDLE"}
Location: {this.PlayerShip.Parent.Name}
Local X: {Math.Round(Helpers.GetLocalCoordinatesX(this.PlayerShip))}
Local Y: {Math.Round(Helpers.GetLocalCoordinatesY(this.PlayerShip))}
Global X: {Math.Round(this.PlayerShip.Position.X)}
Global Y: {Math.Round(this.PlayerShip.Position.Y)}";
}
public void OnExitToMenu()
{
GetTree().ChangeSceneToFile("res://scenes/main_menu.tscn");
}
public void OnTest()
{
CoordinateVector destination = new CoordinateVector(this.PlayerShip.Position.X + Helpers.GetCoordinateFromLY(3), this.PlayerShip.Position.Y);
Order newOrder = new DestinationOrder(Order.OrderType.MOVE_WARP, destination);
this.PlayerShip.SetNewPlayerOrder(newOrder);
UpdateGUI();
}
}