✨ Rotate building tiles
This commit is contained in:
@@ -12,7 +12,7 @@ public partial class PlacementManager : Node2D
|
||||
|
||||
private Vector2I _hoveredCell;
|
||||
private BaseTile _ghostBuilding;
|
||||
|
||||
|
||||
public void SetCurrentBuilding(string buildingId)
|
||||
{
|
||||
_currentBuildingId = buildingId;
|
||||
@@ -23,19 +23,39 @@ public partial class PlacementManager : Node2D
|
||||
_ghostBuilding = null;
|
||||
}
|
||||
|
||||
// Add this field to PlacementManager
|
||||
private float _currentRotation = 0f;
|
||||
|
||||
// Add this method to handle rotation
|
||||
private void RotateGhost(bool reverse = false)
|
||||
{
|
||||
if (_ghostBuilding == null) return;
|
||||
if (reverse)
|
||||
_currentRotation = (_currentRotation - 90f) % 360f;
|
||||
else
|
||||
_currentRotation = (_currentRotation + 90f) % 360f;
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
// Snap mouse to grid
|
||||
var mousePos = GetGlobalMousePosition();
|
||||
_hoveredCell = GridUtils.WorldToGrid(mousePos);
|
||||
|
||||
if (Input.IsActionJustPressed("rotate_tile_reverse"))
|
||||
RotateGhost(reverse: true);
|
||||
else if (Input.IsActionJustPressed("rotate_tile"))
|
||||
RotateGhost();
|
||||
|
||||
if (_ghostBuilding == null)
|
||||
{
|
||||
var scene = Registry.GetBuilding(_currentBuildingId)?.Scene;
|
||||
if (scene == null) return;
|
||||
|
||||
|
||||
_ghostBuilding = (BaseTile)scene.Instantiate();
|
||||
_ghostBuilding.SetGhostMode(true);
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
AddChild(_ghostBuilding);
|
||||
}
|
||||
|
||||
@@ -58,13 +78,15 @@ public partial class PlacementManager : Node2D
|
||||
_ghostBuilding.Position = placementPos;
|
||||
_ghostBuilding.SetGhostMode(canPlace);
|
||||
|
||||
|
||||
// Left click to place
|
||||
if (Input.IsActionPressed("build_tile") && canPlace)
|
||||
{
|
||||
var scene = Registry.GetBuilding(_currentBuildingId)?.Scene;
|
||||
if (scene == null) return;
|
||||
|
||||
|
||||
_ghostBuilding.FinalizePlacement();
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
|
||||
var buildingData = Registry.GetBuilding(_currentBuildingId);
|
||||
Grid.OccupyCell(_hoveredCell, _ghostBuilding);
|
||||
@@ -74,6 +96,7 @@ public partial class PlacementManager : Node2D
|
||||
|
||||
_ghostBuilding = (BaseTile)scene.Instantiate();
|
||||
_ghostBuilding.SetGhostMode(true);
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
AddChild(_ghostBuilding);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user