Added testing and save/load mechanic to the game. Game is now entering final phase.

This commit is contained in:
2026-05-09 21:25:36 +02:00
parent e7de2433de
commit 7e70471227
18 changed files with 1073 additions and 46 deletions
+46 -17
View File
@@ -16,6 +16,13 @@ public partial class World : Node3D
public override void _Ready()
{
bool shouldLoadSave = loadSaveOnStart && SaveGameManager.SaveExists();
SaveGameData saveGame = shouldLoadSave ? SaveGameManager.LoadSaveData() : null;
if (saveGame != null)
{
seed = saveGame.Seed;
}
ResetRunState();
WFC.FillAdjacencies();
@@ -41,18 +48,27 @@ public partial class World : Node3D
map = new Layer[ruinSize];
GenerateWorld();
SetGateRequirements();
if (shouldLoadSave && saveGame != null)
{
SaveGameManager.ApplyWorldData(saveGame);
}
Pathfinding.BuildAStarGraph();
HandleRenderData(BuildRenderData(0));
HandleRenderData(BuildRenderData(visibleLayer));
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
robot.Name = "Bob";
robot.Position = map[0].tiles[0, 0].Position;
AddChild(robot);
robots.Add(robot);
if (shouldLoadSave && saveGame != null)
{
SpawnSavedRobots(saveGame.Robots);
}
else
{
SpawnDefaultRobot();
}
SetGateRequirements();
loadSaveOnStart = false;
}
private Dictionary<string, MultiMeshInstance3D> CreateMultiMeshes(Dictionary<string, Mesh> meshLibrary)
@@ -94,17 +110,30 @@ public partial class World : Node3D
}
}
private void ResetRunState()
private void SpawnDefaultRobot()
{
survival = new SurvivalState();
robotStats = new RobotStats();
inventory = new Inventory();
availableResearch = ResourceLoader.LoadResearch();
robots.Clear();
currentLayer = 0;
visibleLayer = 0;
lowestLayer = 0;
canMove = true;
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
robot.Name = "Bob";
robot.Position = map[0].tiles[0, 0].Position;
AddChild(robot);
robots.Add(robot);
}
private void SpawnSavedRobots(List<RobotSaveData> savedRobots)
{
if (savedRobots == null || savedRobots.Count <= 0)
{
SpawnDefaultRobot();
return;
}
foreach (RobotSaveData savedRobot in savedRobots)
{
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
robot.LoadSaveData(savedRobot);
AddChild(robot);
robots.Add(robot);
}
}
private void GenerateWorld()