45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Godot;
|
|
|
|
namespace AceFieldNewHorizon.Scripts.Tiles
|
|
{
|
|
public partial class BaseTile : Node2D
|
|
{
|
|
private CollisionShape2D _collisionShape;
|
|
private Sprite2D _sprite;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_collisionShape = GetNodeOrNull<CollisionShape2D>("CollisionShape2D");
|
|
_sprite = GetNodeOrNull<Sprite2D>("Sprite2D");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Switch between ghost and placed mode.
|
|
/// </summary>
|
|
/// <param name="canPlace">If in ghost mode, true = green, false = red. If placed, always white.</param>
|
|
public void SetGhostMode(bool canPlace)
|
|
{
|
|
if (_collisionShape != null)
|
|
_collisionShape.Disabled = true; // always disabled in ghost mode
|
|
|
|
if (_sprite != null)
|
|
{
|
|
// Ghost preview coloring
|
|
_sprite.Modulate = canPlace ? new Color(1, 1, 1, 0.2f) : // white semi-transparent
|
|
new Color(1, 0, 0, 0.2f); // red semi-transparent
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Call when placement is finalized.
|
|
/// </summary>
|
|
public void FinalizePlacement()
|
|
{
|
|
if (_collisionShape != null)
|
|
_collisionShape.Disabled = false;
|
|
|
|
if (_sprite != null)
|
|
_sprite.Modulate = Colors.White; // reset to normal
|
|
}
|
|
}
|
|
} |