💄 Optimize the unable to place sound plays
This commit is contained in:
@@ -223,6 +223,20 @@ public partial class PlacementManager : Node2D
|
|||||||
return;
|
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
|
// Consume resources first
|
||||||
if (!ConsumeBuildingResources(_currentBuildingId))
|
if (!ConsumeBuildingResources(_currentBuildingId))
|
||||||
{
|
{
|
||||||
@@ -230,7 +244,7 @@ public partial class PlacementManager : Node2D
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the building instance first
|
// Create the building instance
|
||||||
var scene = building.Scene;
|
var scene = building.Scene;
|
||||||
var buildingInstance = (BaseTile)scene.Instantiate();
|
var buildingInstance = (BaseTile)scene.Instantiate();
|
||||||
buildingInstance.Grid = Grid;
|
buildingInstance.Grid = Grid;
|
||||||
@@ -239,15 +253,6 @@ public partial class PlacementManager : Node2D
|
|||||||
buildingInstance.Position = _ghostBuilding.Position;
|
buildingInstance.Position = _ghostBuilding.Position;
|
||||||
AddChild(buildingInstance);
|
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
|
// If we get here, area is free, so we can safely occupy it
|
||||||
Grid.OccupyArea(_hoveredCell, buildingInstance, building.Size, _currentRotation, building.Layer);
|
Grid.OccupyArea(_hoveredCell, buildingInstance, building.Size, _currentRotation, building.Layer);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user