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

Add basic sounds

This commit is contained in:
tobspr
2020-05-14 19:12:58 +02:00
parent e960773a15
commit af0f56b5e4
24 changed files with 87 additions and 56 deletions

View File

@@ -7,6 +7,7 @@ import { ReplaceableMapEntityComponent } from "../components/replaceable_map_ent
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { SOUNDS } from "../../platform/sound";
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
@@ -69,6 +70,10 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
return true;
}
getPlacementSound() {
return SOUNDS.placeBelt;
}
/**
* Creates the entity at the given location
* @param {Entity} entity

View File

@@ -1,8 +1,8 @@
import { BaseHUDPart } from "../base_hud_part";
import { makeDiv, removeAllChildren, formatBigNumber } from "../../../core/utils";
import { ClickDetector } from "../../../core/click_detector";
import { ShapeDefinition } from "../../shape_definition";
import { Math_max } from "../../../core/builtins";
import { ClickDetector } from "../../../core/click_detector";
import { formatBigNumber, makeDiv } from "../../../core/utils";
import { ShapeDefinition } from "../../shape_definition";
import { BaseHUDPart } from "../base_hud_part";
export class HUDPinnedShapes extends BaseHUDPart {
createElements(parent) {

View File

@@ -14,6 +14,7 @@ import { MetaRotaterBuilding } from "../../buildings/rotater";
import { MetaStackerBuilding } from "../../buildings/stacker";
import { MetaUndergroundBeltBuilding } from "../../buildings/underground_belt";
import { globalConfig } from "../../../core/config";
import { SOUNDS } from "../../../platform/sound";
export class HUDUnlockNotification extends BaseHUDPart {
initialize() {
@@ -110,6 +111,8 @@ export class HUDUnlockNotification extends BaseHUDPart {
this.elemContents.innerHTML = html;
this.visible = true;
this.root.soundProxy.playUi(SOUNDS.levelComplete);
}
close() {

View File

@@ -4,9 +4,9 @@ import { Vector, enumDirectionToVector, enumDirection } from "../core/vector";
import { MetaBuilding } from "./meta_building";
import { StaticMapEntityComponent } from "./components/static_map_entity";
import { Math_abs } from "../core/builtins";
import { Rectangle } from "../core/rectangle";
import { createLogger } from "../core/logging";
import { MetaBeltBaseBuilding, arrayBeltVariantToRotation } from "./buildings/belt_base";
import { SOUNDS } from "../platform/sound";
const logger = createLogger("ingame/logic");
@@ -175,6 +175,9 @@ export class GameLogic {
rotationVariant,
originalRotation,
});
this.root.soundProxy.playUi(building.getPlacementSound());
return true;
}
return false;

View File

@@ -4,6 +4,7 @@ import { GameRoot } from "./root";
import { AtlasSprite } from "../core/sprites";
import { Entity } from "./entity";
import { StaticMapEntityComponent } from "./components/static_map_entity";
import { SOUNDS } from "../platform/sound";
export class MetaBuilding {
/**
@@ -64,6 +65,14 @@ export class MetaBuilding {
return false;
}
/**
* Returns the placement sound
* @returns {string}
*/
getPlacementSound() {
return SOUNDS.placeBuilding;
}
/**
* Returns a preview sprite
* @returns {AtlasSprite}

View File

@@ -55,11 +55,6 @@ export class SoundProxy {
if (this.playingSounds.length > maxOngoingSounds) {
// Too many ongoing sounds
// console.warn(
// "Not playing",
// id,
// "because there are too many sounds playing"
// );
return false;
}

View File

@@ -49,17 +49,23 @@ export class HubSystem extends GameSystemWithFilter {
const textOffsetY = -6;
// Deliver count
context.font = "bold 25px GameFont";
const delivered = this.root.hubGoals.getCurrentGoalDelivered();
if (delivered > 9999) {
context.font = "bold 16px GameFont";
} else if (delivered > 999) {
context.font = "bold 20px GameFont";
} else {
context.font = "bold 25px GameFont";
}
context.fillStyle = "#64666e";
context.textAlign = "left";
context.fillText(
"" + formatBigNumber(this.root.hubGoals.getCurrentGoalDelivered()),
pos.x + textOffsetX,
pos.y + textOffsetY
);
context.fillText("" + formatBigNumber(delivered), pos.x + textOffsetX, pos.y + textOffsetY);
// Required
context.font = "13px GameFont";
context.fillStyle = "#a4a6b0";
context.fillText(
"/ " + formatBigNumber(goals.required),