Deserialize chunk json + spawn debug markers
This commit is contained in:
parent
dbdfd2bb74
commit
77114f5551
3 changed files with 86 additions and 4 deletions
20
scripts/world/ChunkData.cs
Normal file
20
scripts/world/ChunkData.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public record ChunkData(
|
||||||
|
int schema,
|
||||||
|
string id,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
string? biome,
|
||||||
|
List<ChunkPickup>? pickups,
|
||||||
|
List<ChunkGate>? gates,
|
||||||
|
List<ChunkNpc>? npcs,
|
||||||
|
List<ChunkSpawnZone>? spawn_zones,
|
||||||
|
List<ChunkCollisionRect>? collision_rects
|
||||||
|
);
|
||||||
|
|
||||||
|
public record ChunkPickup(string id, string item, int[] pos, int respawn_seconds);
|
||||||
|
public record ChunkGate(string id, int[] rect, string requires, string? message);
|
||||||
|
public record ChunkNpc(string id, string kind, int[] pos, string @ref);
|
||||||
|
public record ChunkSpawnZone(string id, string biome, int[] rect, List<string>? time_windows, List<string>? weather);
|
||||||
|
public record ChunkCollisionRect(string id, int[] rect);
|
||||||
1
scripts/world/ChunkData.cs.uid
Normal file
1
scripts/world/ChunkData.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bxjiroh5ymv1m
|
||||||
|
|
@ -99,10 +99,17 @@ public partial class ChunkManager : Node2D
|
||||||
}
|
}
|
||||||
|
|
||||||
var chunkJson = FileAccess.GetFileAsString(chunkPath);
|
var chunkJson = FileAccess.GetFileAsString(chunkPath);
|
||||||
using var doc = JsonDocument.Parse(chunkJson);
|
var data = JsonSerializer.Deserialize<ChunkData>(chunkJson);
|
||||||
var biome = doc.RootElement.TryGetProperty("biome", out var b) ? b.GetString() : "biome:unknown";
|
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);
|
AddChild(node);
|
||||||
_loaded[key] = node;
|
_loaded[key] = node;
|
||||||
}
|
}
|
||||||
|
|
@ -138,4 +145,58 @@ public partial class ChunkManager : Node2D
|
||||||
n.AddChild(rect);
|
n.AddChild(rect);
|
||||||
return n;
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue