Pickups + Save-diff
This commit is contained in:
parent
b49c0ee55f
commit
bf874ba633
11 changed files with 133 additions and 16 deletions
|
|
@ -8,10 +8,11 @@ public partial class ChunkManager : Node2D
|
|||
[Export] public NodePath PlayerPath { get; set; }
|
||||
[Export] public NodePath PackManagerPath { get; set; }
|
||||
[Export] public int LoadRadius { get; set; } = 1; // 1 => 3x3
|
||||
|
||||
[Export] public PackedScene PickupMarkerScene { get; set; }
|
||||
[Export] public NodePath SaveManagerPath { get; set; }
|
||||
private SaveManager? _save;
|
||||
private CharacterBody2D? _player;
|
||||
private PackManager? _packs;
|
||||
|
||||
private WorldIndex? _world;
|
||||
private Dictionary<(int x, int y), string> _chunkMap = new();
|
||||
private readonly Dictionary<(int x, int y), Node2D> _loaded = new();
|
||||
|
|
@ -31,7 +32,10 @@ public partial class ChunkManager : Node2D
|
|||
GD.PrintErr("ChunkManager: PackManagerPath not set or invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_save = GetNodeOrNull<SaveManager>(SaveManagerPath);
|
||||
if (_save == null) GD.PrintErr("ChunkManager: SaveManagerPath not set or invalid.");
|
||||
|
||||
LoadWorldIndex();
|
||||
}
|
||||
|
||||
|
|
@ -154,21 +158,33 @@ public partial class ChunkManager : Node2D
|
|||
return n;
|
||||
}
|
||||
|
||||
private static void AddChunkMarkers(Node2D chunkNode, ChunkData data)
|
||||
private void AddChunkMarkers(Node2D chunkNode, ChunkData data)
|
||||
{
|
||||
// Pickups: small green squares
|
||||
if (data.pickups != null)
|
||||
if (_save == null || PickupMarkerScene == null) return;
|
||||
|
||||
if (data.pickups != null && _save != null)
|
||||
{
|
||||
foreach (var p in data.pickups)
|
||||
{
|
||||
var r = new ColorRect
|
||||
if (_save.State.CollectedPickups.Contains(p.id))
|
||||
continue; // already collected
|
||||
|
||||
var marker = (PickupMarker)PickupMarkerScene.Instantiate();
|
||||
marker.Position = new Vector2(p.pos[0], p.pos[1]);
|
||||
marker.PickupId = p.id;
|
||||
marker.ItemId = p.item;
|
||||
|
||||
marker.PickedUp += (pickupId, itemId) =>
|
||||
{
|
||||
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)
|
||||
GD.Print($"Picked up {itemId} ({pickupId})");
|
||||
|
||||
_save.State.CollectedPickups.Add(pickupId);
|
||||
_save.Save();
|
||||
|
||||
marker.QueueFree();
|
||||
};
|
||||
chunkNode.AddChild(r);
|
||||
|
||||
chunkNode.AddChild(marker);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue