♻️ Better miner tile

This commit is contained in:
2025-08-29 18:05:30 +08:00
parent 60b6d6f989
commit ac1d8cfab9
3 changed files with 27 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ namespace AceFieldNewHorizon.Scripts.Tiles;
public partial class MinerTile : BaseTile
{
[Export] public PackedScene ItemPickup { get; set; }
[Export] public string ItemToMine { get; set; } = "OreIron";
[Export] public string ItemToMine { get; set; }
[Export] public int MiningRate = 1; // Items per second
private Vector2I _gridPosition;
@@ -16,10 +16,29 @@ public partial class MinerTile : BaseTile
{
base._Ready();
_gridPosition = GridUtils.WorldToGrid(Position);
var ground = Grid.GetTileAtCell(_gridPosition, GridLayer.Ground) as BaseTile;
if (ground == null)
{
GD.Print($"[Miner] Miner {GetInstanceId()} not found available resource...");
return;
}
ItemToMine = (ground.TileId) switch
{
"stone" => "stone",
"ore_iron" => "ore_iron",
_ => null
};
if (ItemToMine == null)
GD.Print($"[Miner] Miner {GetInstanceId()} not found available resource...");
}
public override void _Process(double delta)
{
if (ItemToMine == null)
return;
// Don't mine if building is not completed
if (!IsConstructed || ItemPickup == null)
return;