💄 Optimize the unable to place sound plays
This commit is contained in:
@@ -223,6 +223,20 @@ public partial class PlacementManager : Node2D
|
||||
return;
|
||||
}
|
||||
|
||||
// First check if area is free
|
||||
if (!IsAreaFree(_hoveredCell, building.Size, _currentRotation, building.Layer))
|
||||
{
|
||||
// Check if the area is occupied by under-construction tiles
|
||||
var occupiedCells = GridUtils.GetOccupiedCells(_hoveredCell, building.Size, _currentRotation);
|
||||
var isUnderConstruction = occupiedCells.Any(cell =>
|
||||
Grid.GetBuildingAtCell(cell, building.Layer) is BaseTile { IsConstructing: true });
|
||||
|
||||
if (!isUnderConstruction)
|
||||
_cannotDeploySound.Play();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Consume resources first
|
||||
if (!ConsumeBuildingResources(_currentBuildingId))
|
||||
{
|
||||
@@ -230,7 +244,7 @@ public partial class PlacementManager : Node2D
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the building instance first
|
||||
// Create the building instance
|
||||
var scene = building.Scene;
|
||||
var buildingInstance = (BaseTile)scene.Instantiate();
|
||||
buildingInstance.Grid = Grid;
|
||||
@@ -239,15 +253,6 @@ public partial class PlacementManager : Node2D
|
||||
buildingInstance.Position = _ghostBuilding.Position;
|
||||
AddChild(buildingInstance);
|
||||
|
||||
// First check if area is free
|
||||
if (!IsAreaFree(_hoveredCell, building.Size, _currentRotation, building.Layer))
|
||||
{
|
||||
_cannotDeploySound.Play();
|
||||
RefundBuildingResources(_currentBuildingId);
|
||||
buildingInstance.QueueFree();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we get here, area is free, so we can safely occupy it
|
||||
Grid.OccupyArea(_hoveredCell, buildingInstance, building.Size, _currentRotation, building.Layer);
|
||||
|
||||
@@ -286,11 +291,11 @@ public partial class PlacementManager : Node2D
|
||||
// Right click to destroy from current layer
|
||||
var building = Grid.GetBuildingAtCell(_hoveredCell);
|
||||
if (building == null) return;
|
||||
|
||||
|
||||
// Find all cells occupied by this building
|
||||
var buildingInfo = Grid.GetBuildingInfoAtCell(_hoveredCell, GridLayer.Building);
|
||||
if (buildingInfo == null) return;
|
||||
|
||||
|
||||
// Check if this building is in the build tasks (under construction)
|
||||
if (_buildTasks.TryGetValue(building, out var buildTask))
|
||||
{
|
||||
@@ -300,13 +305,13 @@ public partial class PlacementManager : Node2D
|
||||
_buildTasks.Remove(building);
|
||||
_canceledSound.Play();
|
||||
if (buildingTile == null) return;
|
||||
|
||||
|
||||
// Refund resources for canceled build
|
||||
var buildingData = Registry.GetBuilding(buildingTile.TileId);
|
||||
if (buildingData != null)
|
||||
RefundBuildingResources(buildingTile.TileId);
|
||||
}
|
||||
|
||||
|
||||
// Clean up the building and grid
|
||||
building.QueueFree();
|
||||
Grid.FreeArea(buildingInfo.Value.Position, buildingInfo.Value.Size, buildingInfo.Value.Rotation);
|
||||
|
Reference in New Issue
Block a user