1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-02-13 19:39:20 +00:00

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.
This commit is contained in:
Triston Stuart 2020-06-24 03:28:58 -07:00
parent 80fa97976d
commit 2c620ba4fb
2 changed files with 18 additions and 4 deletions

View File

@ -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;
}
}
});
}

View File

@ -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;