From c5918e851b105b22f8e41adbeb59ea10ba4ed0a4 Mon Sep 17 00:00:00 2001 From: Daniel Maixner Date: Sat, 2 Sep 2023 12:07:05 +0200 Subject: [PATCH] Tuning --- www/assets/js/Game.js | 40 +++++++++++++------------------- www/assets/js/Hud.js | 2 +- www/assets/js/ModelRepository.js | 3 --- www/assets/js/World.js | 6 ++++- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/www/assets/js/Game.js b/www/assets/js/Game.js index 4bfbc85..e59b3b5 100644 --- a/www/assets/js/Game.js +++ b/www/assets/js/Game.js @@ -1,6 +1,6 @@ import {EventProcessor} from "./EventProcessor.js"; import {Player} from "./Player.js"; -import {InventorySlot, ItemId, SoundType} from "./Enums.js"; +import {InventorySlot, SoundType} from "./Enums.js"; import {SoundRepository} from "./SoundRepository.js"; export class Game { @@ -21,9 +21,15 @@ export class Game { #hudDebounceTicks = 1 #bombTimerId = null; #eventProcessor - #dropItems = []; - #throwables = []; + #dropItems = {}; + #throwables = {}; #roundIntervalIds = []; + #playerSlotsVisibleModels = [ + InventorySlot.SLOT_KNIFE, InventorySlot.SLOT_PRIMARY, InventorySlot.SLOT_SECONDARY, + InventorySlot.SLOT_BOMB, InventorySlot.SLOT_GRENADE_DECOY, InventorySlot.SLOT_GRENADE_MOLOTOV, + InventorySlot.SLOT_GRENADE_SMOKE, InventorySlot.SLOT_GRENADE_FLASH, InventorySlot.SLOT_GRENADE_HE, + InventorySlot.SLOT_TASER, InventorySlot.SLOT_KIT, + ] score = null bombDropPosition = null alivePlayers = [0, 0] @@ -31,19 +37,6 @@ export class Game { players = [] playerMe = null playerSpectate = null - #playerSlotsVisibleModels = [ - InventorySlot.SLOT_KNIFE, - InventorySlot.SLOT_PRIMARY, - InventorySlot.SLOT_SECONDARY, - InventorySlot.SLOT_BOMB, - InventorySlot.SLOT_GRENADE_DECOY, - InventorySlot.SLOT_GRENADE_MOLOTOV, - InventorySlot.SLOT_GRENADE_SMOKE, - InventorySlot.SLOT_GRENADE_FLASH, - InventorySlot.SLOT_GRENADE_HE, - InventorySlot.SLOT_TASER, - InventorySlot.SLOT_KIT, - ] constructor(world, hud, stats) { this.#world = world @@ -53,17 +46,19 @@ export class Game { this.#soundRepository = new SoundRepository((...args) => world.playSound(...args)) } - pause(msg, score, timeMs) { - this.#paused = true - console.log("Pause: " + msg + " for " + timeMs + "ms") + #roundReset() { clearInterval(this.#bombTimerId) this.#roundIntervalIds.forEach((id) => clearInterval(id)) this.#roundIntervalIds = [] Object.keys(this.#dropItems).forEach((id) => this.itemPickUp(id)) - this.#dropItems = [] Object.keys(this.#throwables).forEach((id) => this.removeGrenade(id)) - this.#throwables = [] this.#world.reset() + } + + pause(msg, score, timeMs) { + this.#paused = true + console.log("Pause: " + msg + " for " + timeMs + "ms") + this.#roundReset() const game = this this.players.forEach(function (player) { @@ -175,9 +170,6 @@ export class Game { this.playerHit(data, true) } if (data.type === SoundType.ITEM_PICKUP) { - if (data.item.id === ItemId.Bomb && spectatorId === data.player) { - this.#dropItems[data.extra.id].visible = false - } this.itemPickUp(data.extra.id) } if (data.type === SoundType.ITEM_DROP_AIR) { diff --git a/www/assets/js/Hud.js b/www/assets/js/Hud.js index 77743c9..e744d66 100644 --- a/www/assets/js/Hud.js +++ b/www/assets/js/Hud.js @@ -225,7 +225,7 @@ export class HUD { if (player.ammo === null) { this.#elements.ammo.innerText = Enum.ItemIdToName[player.item.id] } else { - this.#elements.ammo.innerText = `${Enum.ItemIdToName[player.item.id]} \u00a0 ${player.ammo} / ${player.ammoReserve}` + this.#elements.ammo.innerText = `${Enum.ItemIdToName[player.item.id]} \u00a0 ${player.ammo} / ${player.ammoReserve}` } let myTeamIndex = this.#game.playerMe.getTeamIndex() diff --git a/www/assets/js/ModelRepository.js b/www/assets/js/ModelRepository.js index 5a180b4..a63d703 100644 --- a/www/assets/js/ModelRepository.js +++ b/www/assets/js/ModelRepository.js @@ -2,7 +2,6 @@ import {ItemId} from "./Enums.js"; export class ModelRepository { #gltfLoader - #objectLoader #textureLoader #models = {} #meshes = {} @@ -18,9 +17,7 @@ export class ModelRepository { constructor() { this.#gltfLoader = new THREE.GLTFLoader() - this.#objectLoader = new THREE.ObjectLoader() this.#textureLoader = new THREE.TextureLoader() - } #loadModel(url) { diff --git a/www/assets/js/World.js b/www/assets/js/World.js index f3dc6d0..8c591e5 100644 --- a/www/assets/js/World.js +++ b/www/assets/js/World.js @@ -21,6 +21,7 @@ export class World { init(mapName, setting) { const scene = new THREE.Scene() + scene.name = 'MainScene' scene.background = new THREE.Color(0xdadada) const promises = [] @@ -204,13 +205,16 @@ export class World { reset() { this.clearDecals() const bomb = this.#modelRepository.getBomb() - if (bomb.parent && bomb.parent.type === 'Scene') { + if (bomb.parent && bomb.parent.name === 'MainScene') { bomb.visible = false } } destroyObject(object) { if (object.name === `item-${Enum.ItemId.Bomb}`) { + if (object.parent && object.parent.name === 'MainScene') { + object.visible = false + } return }