From 2c620ba4fbe88c1d265663ea3003dd5fca0e4ff2 Mon Sep 17 00:00:00 2001 From: Triston Stuart Date: Wed, 24 Jun 2020 03:28:58 -0700 Subject: [PATCH] Fix Building Placer Sound Bug Fixes the sound distortion when using the building placer caused by many buildings trying to play their sounds at once. This will only play 1 building sound. Includes checks for if building was actually placed. --- src/js/game/hud/parts/building_placer_logic.js | 13 +++++++++++-- src/js/game/logic.js | 9 +++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/js/game/hud/parts/building_placer_logic.js b/src/js/game/hud/parts/building_placer_logic.js index 6aee65b6..3e99c36e 100644 --- a/src/js/game/hud/parts/building_placer_logic.js +++ b/src/js/game/hud/parts/building_placer_logic.js @@ -366,8 +366,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { /** * Tries to place the current building at the given tile * @param {Vector} tile + * @param {Object} options */ - tryPlaceCurrentBuildingAt(tile) { + tryPlaceCurrentBuildingAt(tile, options = {}) { if (this.root.camera.zoomLevel < globalConfig.mapChunkOverviewMinZoom) { // Dont allow placing in overview mode return; @@ -388,6 +389,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { originalRotation: this.currentBaseRotation, building: this.currentMetaBuilding.get(), variant: this.currentVariant.get(), + sound: ((options.supressSound!=null)? !options.supressSound : true) }); if (entity) { @@ -447,12 +449,19 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart { */ executeDirectionLockedPlacement() { const path = this.computeDirectionLockPath(); + let needSound = false; this.root.logic.performBulkOperation(() => { for (let i = 0; i < path.length; ++i) { const { rotation, tile } = path[i]; this.currentBaseRotation = rotation; - this.tryPlaceCurrentBuildingAt(tile); + // Add supressSound flag + let addedBuilding = this.tryPlaceCurrentBuildingAt(tile, {supressSound: ((i==0||needSound)? false : true)}); + if (!addedBuilding && (i==0 || needSound)){ + needSound = true; + }else { + needSound = false; + } } }); } diff --git a/src/js/game/logic.js b/src/js/game/logic.js index 408bf89d..d9cb2d6d 100644 --- a/src/js/game/logic.js +++ b/src/js/game/logic.js @@ -151,9 +151,11 @@ export class GameLogic { * @param {number} param0.rotationVariant * @param {string} param0.variant * @param {MetaBuilding} param0.building + * @param {boolean} param0.sound * @returns {Entity} */ - tryPlaceBuilding({ origin, rotation, rotationVariant, originalRotation, variant, building }) { + tryPlaceBuilding({ origin, rotation, rotationVariant, originalRotation, variant, building, sound }) { + sound = (sound!==null)? sound : true; // Check for sound argument if (this.checkCanPlaceBuilding({ origin, rotation, rotationVariant, variant, building })) { // Remove any removeable entities below const checker = new StaticMapEntityComponent({ @@ -186,7 +188,10 @@ export class GameLogic { variant, }); - this.root.soundProxy.playUi(building.getPlacementSound()); + // Play sound + if (sound){ + this.root.soundProxy.playUi(building.getPlacementSound()); + } return entity; } return null;