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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
23
scripts/world/PickupMarker.cs
Normal file
23
scripts/world/PickupMarker.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using Godot;
|
||||
|
||||
public partial class PickupMarker : Area2D
|
||||
{
|
||||
public string PickupId { get; set; } = "";
|
||||
public string ItemId { get; set; } = "";
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
BodyEntered += OnBodyEntered;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (body is not CharacterBody2D) return;
|
||||
|
||||
// Defer to avoid freeing during signal processing edge cases
|
||||
EmitSignal(SignalName.PickedUp, PickupId, ItemId);
|
||||
}
|
||||
|
||||
[Signal]
|
||||
public delegate void PickedUpEventHandler(string pickupId, string itemId);
|
||||
}
|
||||
1
scripts/world/PickupMarker.cs.uid
Normal file
1
scripts/world/PickupMarker.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://di8apqyxtfmfp
|
||||
11
scripts/world/PickupVisual.cs
Normal file
11
scripts/world/PickupVisual.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using Godot;
|
||||
|
||||
public partial class PickupVisual : Node2D
|
||||
{
|
||||
public override void _Draw()
|
||||
{
|
||||
DrawRect(new Rect2(-5, -5, 10, 10), new Color(0.2f, 1f, 0.2f, 0.9f));
|
||||
}
|
||||
|
||||
public override void _Ready() => QueueRedraw();
|
||||
}
|
||||
1
scripts/world/PickupVisual.cs.uid
Normal file
1
scripts/world/PickupVisual.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://u5olxge8tsb4
|
||||
Loading…
Add table
Add a link
Reference in a new issue