Deserialize chunk json + spawn debug markers

This commit is contained in:
anonoe 2026-02-09 23:30:17 +01:00
parent dbdfd2bb74
commit 77114f5551
Signed by: anonoe
SSH key fingerprint: SHA256:OnAs6gNQelOnDiY5tBpDYKQiuTgBvnmIdMo5P09cdqg
3 changed files with 86 additions and 4 deletions

View file

@ -97,12 +97,19 @@ public partial class ChunkManager : Node2D
GD.PrintErr($"Chunk missing in packs: {relPath}");
return;
}
var chunkJson = FileAccess.GetFileAsString(chunkPath);
using var doc = JsonDocument.Parse(chunkJson);
var biome = doc.RootElement.TryGetProperty("biome", out var b) ? b.GetString() : "biome:unknown";
var data = JsonSerializer.Deserialize<ChunkData>(chunkJson);
if (data == null)
{
GD.PrintErr($"Failed to parse chunk: {chunkPath}");
return;
}
var node = CreateDebugChunkNode(x, y, _world!.chunk_size_px, biome ?? "biome:unknown");
var biome = data.biome ?? "biome:unknown";
var node = CreateDebugChunkNode(x, y, _world!.chunk_size_px, biome);
AddChunkMarkers(node, data);
AddChild(node);
_loaded[key] = node;
}
@ -138,4 +145,58 @@ public partial class ChunkManager : Node2D
n.AddChild(rect);
return n;
}
private static void AddChunkMarkers(Node2D chunkNode, ChunkData data)
{
// Pickups: small green squares
if (data.pickups != null)
{
foreach (var p in data.pickups)
{
var r = new ColorRect
{
Size = new Vector2(10, 10),
Color = new Color(0.2f, 1.0f, 0.2f, 0.9f),
MouseFilter = Control.MouseFilterEnum.Ignore,
Position = new Vector2(p.pos[0] - 5, p.pos[1] - 5)
};
chunkNode.AddChild(r);
}
}
// NPCs: blue squares
if (data.npcs != null)
{
foreach (var n in data.npcs)
{
var r = new ColorRect
{
Size = new Vector2(12, 12),
Color = new Color(0.2f, 0.5f, 1.0f, 0.9f),
MouseFilter = Control.MouseFilterEnum.Ignore,
Position = new Vector2(n.pos[0] - 6, n.pos[1] - 6)
};
chunkNode.AddChild(r);
}
}
// Gates: red rectangles
if (data.gates != null)
{
foreach (var g in data.gates)
{
var rect = g.rect; // [x,y,w,h]
var r = new ColorRect
{
Size = new Vector2(rect[2], rect[3]),
Color = new Color(1.0f, 0.2f, 0.2f, 0.35f),
MouseFilter = Control.MouseFilterEnum.Ignore,
Position = new Vector2(rect[0], rect[1])
};
chunkNode.AddChild(r);
}
}
// Collision rects: gray outlines (optional later)
}
}