using Godot; using System; public class Overlays : Node { [Signal] delegate void OverlayCycled(Overlay overlay); [Export] private KeyList _cycleOverlayKey; [Export] private Resource _overlaysResource; public Overlay Current => _overlays[_overlayIdx]; private OverlayCollection _overlays; private int _overlayIdx = 0; [Export] private Resource _tileGridResource; private TileGrid _tileGrid; [Export] private NodePath _worldGridPath; private WorldGrid _worldGrid; public override void _Ready() { _overlays = (OverlayCollection)_overlaysResource; _tileGrid = (TileGrid)_tileGridResource; _worldGrid = GetNode(_worldGridPath); } public override void _Input(InputEvent @event) { base._Input(@event); if (!(@event is InputEventKey keyEvent)) return; if (!(keyEvent.Pressed)) return; if ((KeyList)keyEvent.Scancode != _cycleOverlayKey) return; CycleOverlay(); } public override void _Process(float delta) { base._Process(delta); for (int i = 0; i < _tileGrid.Count; i++) { var tile = _tileGrid[i]; var material = _worldGrid.GetTileMaterial(i); Current.Apply(tile, material); } } public void CycleOverlay() { _overlayIdx++; _overlayIdx %= _overlays.Count; EmitSignal(nameof(OverlayCycled), Current); } }