mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Fix sound being played too often
This commit is contained in:
parent
7ca425c8f3
commit
66eac93460
@ -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,
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -186,7 +186,6 @@ export class GameLogic {
|
||||
variant,
|
||||
});
|
||||
|
||||
this.root.soundProxy.playUi(building.getPlacementSound());
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user