✨ Miner tile
This commit is contained in:
@@ -2,7 +2,7 @@ using Godot;
|
||||
|
||||
namespace AceFieldNewHorizon.Scripts.System;
|
||||
|
||||
public partial class ItemPickup : Node2D
|
||||
public partial class ItemPickup : Area2D
|
||||
{
|
||||
public const string PickupGroupName = "ItemPickupTarget";
|
||||
|
||||
@@ -19,8 +19,7 @@ public partial class ItemPickup : Node2D
|
||||
// Called when the node enters the scene tree
|
||||
public override void _Ready()
|
||||
{
|
||||
var area = GetNode<Area2D>("Area2D");
|
||||
area.BodyEntered += OnBodyEntered;
|
||||
BodyEntered += OnBodyEntered;
|
||||
|
||||
_sprite = GetNode<Sprite2D>("Sprite2D");
|
||||
UpdateTexture();
|
||||
@@ -114,7 +113,29 @@ public partial class ItemPickup : Node2D
|
||||
if (body.IsInGroup(PickupGroupName))
|
||||
{
|
||||
if (body.HasMethod("AddItem"))
|
||||
body.Call("AddItem", ItemId, Quantity);
|
||||
{
|
||||
// First check if we can merge with existing items
|
||||
if (body.HasMethod("HasItem"))
|
||||
{
|
||||
var hasItem = (bool)body.Call("HasItem", ItemId);
|
||||
if (hasItem && body.HasMethod("GetItemQuantity"))
|
||||
{
|
||||
// Get current quantity and add to it
|
||||
var currentQuantity = (int)body.Call("GetItemQuantity", ItemId);
|
||||
body.Call("SetItemQuantity", ItemId, currentQuantity + Quantity);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No existing item, add as new
|
||||
body.Call("AddItem", ItemId, Quantity);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback to original behavior if HasItem method doesn't exist
|
||||
body.Call("AddItem", ItemId, Quantity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Infinite)
|
||||
QueueFree(); // remove the pickup from the world
|
||||
|
@@ -4,6 +4,7 @@ using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AceFieldNewHorizon.Scripts.Entities;
|
||||
using AceFieldNewHorizon.Scripts.Tiles;
|
||||
|
||||
namespace AceFieldNewHorizon.Scripts.System;
|
||||
|
||||
@@ -376,7 +377,7 @@ public partial class NaturalResourceGenerator : Node2D
|
||||
return false;
|
||||
}
|
||||
|
||||
if (scene.Instantiate() is not Node2D instance)
|
||||
if (scene.Instantiate() is not BaseTile instance)
|
||||
{
|
||||
GD.PrintErr($"{LogPrefix} Failed to instantiate scene for: {tileType}");
|
||||
return false;
|
||||
@@ -387,6 +388,7 @@ public partial class NaturalResourceGenerator : Node2D
|
||||
var offset = GridUtils.GetCenterOffset(rotatedSize, 0f); // 0f for no rotation
|
||||
instance.GlobalPosition = GridUtils.GridToWorld(cell) + offset;
|
||||
instance.ZIndex = (int)building.Layer;
|
||||
instance.Grid = Grid;
|
||||
AddChild(instance);
|
||||
Grid.OccupyArea(cell, instance, building.Size, 0f, building.Layer);
|
||||
// GD.Print($"{LogPrefix} Successfully placed {tileType} at {cell}");
|
||||
|
@@ -199,6 +199,7 @@ public partial class PlacementManager : Node2D
|
||||
var scene = building.Scene;
|
||||
|
||||
_ghostBuilding = (BaseTile)scene.Instantiate();
|
||||
_ghostBuilding.Grid = Grid;
|
||||
_ghostBuilding.SetGhostMode(true);
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
_ghostBuilding.ZAsRelative = false;
|
||||
@@ -232,6 +233,7 @@ public partial class PlacementManager : Node2D
|
||||
// Create the building instance first
|
||||
var scene = building.Scene;
|
||||
var buildingInstance = (BaseTile)scene.Instantiate();
|
||||
buildingInstance.Grid = Grid;
|
||||
buildingInstance.RotationDegrees = _currentRotation;
|
||||
buildingInstance.ZIndex = (int)building.Layer;
|
||||
buildingInstance.Position = _ghostBuilding.Position;
|
||||
|
Reference in New Issue
Block a user