From fb74df5d53e6b3918b443454ba5d5eb04c5da7e6 Mon Sep 17 00:00:00 2001 From: Gautam Anand Date: Sun, 24 Dec 2023 18:17:31 -0600 Subject: [PATCH] Changes --- client/src/game/Controls.ts | 16 ++++++++++------ client/src/game/Settings.ts | 6 ++++-- client/src/game/entities/Player.ts | 6 ++++++ client/src/ui/App.tsx | 2 +- server/src/game/Game.js | 3 +++ server/src/game/entities/Player.js | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/client/src/game/Controls.ts b/client/src/game/Controls.ts index 192b8493..cd35d85c 100644 --- a/client/src/game/Controls.ts +++ b/client/src/game/Controls.ts @@ -66,14 +66,11 @@ export class Controls { }); input.on('pointerup', (pointer: Phaser.Input.Pointer) => { pointer.event.preventDefault(); - if (pointer.leftButtonReleased()) { this.inputUp(InputTypes.SwordSwing); - } - if (pointer.rightButtonReleased()) { this.inputUp(InputTypes.SwordThrow); - } }); + window.addEventListener('blur', () => this.clear()); this.disabledKeys = []; } @@ -112,8 +109,15 @@ export class Controls { this.disabled = true; } - disableKeys(keys: number[]) { - this.disabledKeys = keys; + disableKeys(keys: number[], append = false) { + if(!append) this.disabledKeys = keys; + else this.disabledKeys = this.disabledKeys.concat(keys); + + this.disabledKeys = Array.from(new Set(this.disabledKeys)); + } + + enableKeys(keys: number[]) { + this.disabledKeys = this.disabledKeys.filter(key => !keys.includes(key)); } enableAllKeys() { diff --git a/client/src/game/Settings.ts b/client/src/game/Settings.ts index 64a68be3..53e70363 100644 --- a/client/src/game/Settings.ts +++ b/client/src/game/Settings.ts @@ -53,7 +53,7 @@ export const settingsList: Record = { { name: 'Mouse Only', value: 'mouse' }, { name: 'Mouse + Keys', value: 'keys' }, ], - default: 'mouse', + default: 'keys', }, sound: { name: 'Sound', @@ -98,7 +98,8 @@ class SettingsManager { let savedSettings: any = {}; try { const data = JSON.parse(localStorage.getItem(this.key) as string); - if (data) { + console.log('Loaded Settings', data); + if (data) { savedSettings = data; } } catch (e) { @@ -113,6 +114,7 @@ class SettingsManager { savedSettings[key] = value; localStorage.setItem(this.key, JSON.stringify(savedSettings)); + console.log('Saved Settings', savedSettings); if (settingsList[key].onChange) { settingsList[key].onChange(value); } diff --git a/client/src/game/entities/Player.ts b/client/src/game/entities/Player.ts index 5a043688..86530a1f 100644 --- a/client/src/game/entities/Player.ts +++ b/client/src/game/entities/Player.ts @@ -228,6 +228,9 @@ class Player extends BaseEntity { this.swordLerpProgress -= swordLerpDt; if (this.swordLerpProgress <= 0) { this.swordLerpProgress = 0; + if(this.isMe && this.swordDecreaseStarted) { + this.game.controls.enableKeys([InputTypes.SwordThrow]); + } this.swordDecreaseStarted = false; } } @@ -254,7 +257,10 @@ class Player extends BaseEntity { if (this.game.controls.isInputDown(InputTypes.SwordSwing)) { if (!(this.swordFlying || this.swordRaiseStarted || this.swordDecreaseStarted)) { + if(!this.swordRaiseStarted) { this.swordRaiseStarted = true; + this.game.controls.disableKeys([InputTypes.SwordThrow], true); + } } } diff --git a/client/src/ui/App.tsx b/client/src/ui/App.tsx index df7ad212..6c08f60c 100644 --- a/client/src/ui/App.tsx +++ b/client/src/ui/App.tsx @@ -55,7 +55,7 @@ function App() { if(gameStarted && firstGame) setFirstGame(false); if(gameStarted) return; setTimeout(() => { - api.get(`${api.endpoint}/auth/account`, (data) => { + api.get(`${api.endpoint}/auth/account?now=${Date.now()}`, (data) => { setAccountReady(true); if (data.account) { data.account.token = data.token; diff --git a/server/src/game/Game.js b/server/src/game/Game.js index ee19a4f8..5e4d4eb1 100644 --- a/server/src/game/Game.js +++ b/server/src/game/Game.js @@ -220,6 +220,9 @@ class Game { client.player && client.player.name ? client.player.name : this.handleNickname(data.name || '') ) + if(data?.name && data.name !== name) { + data.name = name; + } // if (this.isNameReserved(name)) return; diff --git a/server/src/game/entities/Player.js b/server/src/game/entities/Player.js index eae0b03d..6a0734ac 100644 --- a/server/src/game/entities/Player.js +++ b/server/src/game/entities/Player.js @@ -114,7 +114,7 @@ class Player extends Entity { this.effects.forEach(effect => effect.update(dt)); this.health.update(dt); this.applyInputs(dt); - this.sword.flySpeed.value = clamp(this.speed.value / 10, 50, 200); + this.sword.flySpeed.value = clamp(this.speed.value / 10, 100, 200); if (this.inputs.isInputDown(Types.Input.Ability) && this.evolutions.evolutionEffect.canActivateAbility) { this.evolutions.evolutionEffect.activateAbility();