Big project cleanup with overhaul of file responsibilities (KISS) and code (DRY, YAGNI)

This commit is contained in:
2026-05-14 11:17:02 +02:00
parent bd6cdeb97b
commit 300c8f5a42
54 changed files with 2030 additions and 1745 deletions
+36 -22
View File
@@ -30,37 +30,50 @@ public partial class RobotList : PanelContainer
}
public void ReloadRobots()
{
ClearRobotList();
foreach (Robot robotObject in GameData.robots)
{
robotList.AddChild(CreateRobotDisplay(robotObject));
}
}
private void ClearRobotList()
{
foreach (Node node in robotList.GetChildren())
{
robotList.RemoveChild(node);
node.QueueFree();
}
RobotDisplay display;
}
foreach (Robot robotObject in GameData.robots)
{
display = robotDisplayPrefab.Instantiate<RobotDisplay>();
display.robot = robotObject;
display.listItem.Text = robotObject.Name;
display.OnRobotJumpTo += (robot) =>
{
EmitSignal(SignalName.OnRobotJumpTo, robot);
Visible = false;
};
display.OnRobotFollow += (robot) =>
{
EmitSignal(SignalName.OnRobotFollow, robot);
Visible = false;
};
robotList.AddChild(display);
}
private RobotDisplay CreateRobotDisplay(Robot robotObject)
{
RobotDisplay display = robotDisplayPrefab.Instantiate<RobotDisplay>();
display.robot = robotObject;
display.listItem.Text = robotObject.Name;
display.OnRobotJumpTo += HandleRobotJumpTo;
display.OnRobotFollow += HandleRobotFollow;
return display;
}
private void HandleRobotJumpTo(Robot robot)
{
EmitSignal(SignalName.OnRobotJumpTo, robot);
Visible = false;
}
private void HandleRobotFollow(Robot robot)
{
EmitSignal(SignalName.OnRobotFollow, robot);
Visible = false;
}
public void ReloadSelectableRobots()
{
selectableRobots.Clear();
if(GameData.robots.Count >= GameData.maxRobotCount)
if (GameData.robots.Count >= GameData.maxRobotCount)
{
selectableRobots.AddItem("You can't have more robots currently!");
selectableRobots.Disabled = true;
@@ -81,7 +94,8 @@ public partial class RobotList : PanelContainer
public void SpawnRobot()
{
if(spawnId.Length <= 0) return;
if (spawnId.Length <= 0) return;
GameData.inventory.RemoveItem(spawnId, 1);
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
robot.Name = $"Robot #{GameData.robots.Count}";
@@ -97,8 +111,8 @@ public partial class RobotList : PanelContainer
public void OnRobotSelect(int index)
{
//Selected option is the "please select..." option
if(index == 0) return;
if (index == 0) return;
spawnId = ItemData.GetIndex(selectableRobots.GetItemText(index));
}
}