diff --git a/src/js/game/hud/parts/building_placer.js b/src/js/game/hud/parts/building_placer.js index f0bbcdae..0e9752ef 100644 --- a/src/js/game/hud/parts/building_placer.js +++ b/src/js/game/hud/parts/building_placer.js @@ -372,7 +372,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic { size: 12, offsetY: -globalConfig.halfTileSize - - clamp((this.root.time.now() * 1.5) % 1.0, 0, 1) * 1 * globalConfig.tileSize + + clamp((this.root.time.realtimeNow() * 1.5) % 1.0, 0, 1) * 1 * globalConfig.tileSize + globalConfig.halfTileSize, }); } diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index 7d8e3838..337e43f7 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -516,15 +516,32 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { * releasing the mouse */ executeDirectionLockedPlacement() { + const metaBuilding = this.currentMetaBuilding.get(); + if (!metaBuilding) { + // No active building + return; + } + + // Get path to place const path = this.computeDirectionLockPath(); + + // Store if we placed anything + let anythingPlaced = false; + + // Perform this in bulk to avoid recalculations this.root.logic.performBulkOperation(() => { for (let i = 0; i < path.length; ++i) { const { rotation, tile } = path[i]; - this.currentBaseRotation = rotation; - this.tryPlaceCurrentBuildingAt(tile); + if (this.tryPlaceCurrentBuildingAt(tile)) { + anythingPlaced = true; + } } }); + + if (anythingPlaced) { + this.root.soundProxy.playUi(metaBuilding.getPlacementSound()); + } } /** @@ -647,7 +664,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { // Place initial building, but only if direction lock is not active if (!this.isDirectionLockActive) { - this.tryPlaceCurrentBuildingAt(this.lastDragTile); + if (this.tryPlaceCurrentBuildingAt(this.lastDragTile)) { + this.root.soundProxy.playUi(metaBuilding.getPlacementSound()); + } } return STOP_PROPAGATION; } @@ -724,16 +743,25 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { var sy = y0 < y1 ? 1 : -1; var err = dx - dy; + let anythingPlaced = false; + let anythingDeleted = false; + while (this.currentlyDeleting || this.currentMetaBuilding.get()) { if (this.currentlyDeleting) { + // Deletion const contents = this.root.map.getTileContentXY(x0, y0); if (contents && !contents.queuedForDestroy && !contents.destroyed) { - this.root.logic.tryDeleteBuilding(contents); - this.root.soundProxy.playUi(SOUNDS.destroyBuilding); + if (this.root.logic.tryDeleteBuilding(contents)) { + anythingDeleted = true; + } } } else { - this.tryPlaceCurrentBuildingAt(new Vector(x0, y0)); + // Placement + if (this.tryPlaceCurrentBuildingAt(new Vector(x0, y0))) { + anythingPlaced = true; + } } + if (x0 === x1 && y0 === y1) break; var e2 = 2 * err; if (e2 > -dy) { @@ -745,6 +773,13 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { y0 += sy; } } + + if (anythingPlaced) { + this.root.soundProxy.playUi(metaBuilding.getPlacementSound()); + } + if (anythingDeleted) { + this.root.soundProxy.playUi(SOUNDS.destroyBuilding); + } } this.lastDragTile = newPos; diff --git a/src/js/game/logic.js b/src/js/game/logic.js index 408bf89d..5c1bbf66 100644 --- a/src/js/game/logic.js +++ b/src/js/game/logic.js @@ -186,7 +186,6 @@ export class GameLogic { variant, }); - this.root.soundProxy.playUi(building.getPlacementSound()); return entity; } return null; diff --git a/src/js/game/sound_proxy.js b/src/js/game/sound_proxy.js index 0408586d..162f0bc0 100644 --- a/src/js/game/sound_proxy.js +++ b/src/js/game/sound_proxy.js @@ -5,10 +5,9 @@ import { GameRoot } from "./root"; import { Vector } from "../core/vector"; import { SOUNDS } from "../platform/sound"; -const avgSoundDurationSeconds = 0.25; +const avgSoundDurationSeconds = 0.1; const maxOngoingSounds = 2; - -const maxOngoingUiSounds = 10; +const maxOngoingUiSounds = 5; // Proxy to the application sound instance export class SoundProxy {