From 3f8c911e9d979467b88fa420571aff681154c36b Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sun, 12 Jan 2025 20:54:59 +0100 Subject: [PATCH] Clean up --- src/App.vue | 6 ++-- src/components/game/character/Character.vue | 4 +++ src/components/game/map/Map.vue | 16 ++++----- src/components/screens/Game.vue | 20 ++--------- src/components/screens/MapEditor.vue | 39 +++------------------ src/composables/gameComposable.ts | 2 -- 6 files changed, 23 insertions(+), 64 deletions(-) diff --git a/src/App.vue b/src/App.vue index f4af5ff..9b9864d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,7 +18,7 @@ import Debug from '@/components/utilities/Debug.vue' import Notifications from '@/components/utilities/Notifications.vue' import { useGameStore } from '@/stores/gameStore' import { useMapEditorStore } from '@/stores/mapEditorStore' -import { computed, onMounted, onUnmounted, watch } from 'vue' +import { computed, watch } from 'vue' const gameStore = useGameStore() const mapEditorStore = useMapEditorStore() @@ -57,7 +57,9 @@ addEventListener('keydown', (event) => { if (gameStore.character?.role !== 'gm') return // Only allow toggling the gm panel if the character is a gm // Check if no input is active or focus is on an input - if (event.repeat || event.isComposing || event.defaultPrevented || document.activeElement?.tagName.toUpperCase() === 'INPUT' || document.activeElement?.tagName.toUpperCase() === 'TEXTAREA') return + if (event.repeat || event.isComposing || event.defaultPrevented || document.activeElement?.tagName.toUpperCase() === 'INPUT' || document.activeElement?.tagName.toUpperCase() === 'TEXTAREA') { + return + } if (event.key === 'G') { gameStore.toggleGmPanel() diff --git a/src/components/game/character/Character.vue b/src/components/game/character/Character.vue index 96f99bd..a70d14c 100644 --- a/src/components/game/character/Character.vue +++ b/src/components/game/character/Character.vue @@ -150,6 +150,10 @@ onMounted(async () => { const characterTypeStorage = new CharacterTypeStorage() const spriteId = await characterTypeStorage.getSpriteId(props.mapCharacter.character.characterType!) + if (!spriteId) return + + charSpriteId.value = spriteId + await loadSpriteTextures(scene, spriteId) charSprite.value!.setTexture(charTexture.value) diff --git a/src/components/game/map/Map.vue b/src/components/game/map/Map.vue index 7c86e5a..454fc72 100644 --- a/src/components/game/map/Map.vue +++ b/src/components/game/map/Map.vue @@ -18,14 +18,6 @@ const mapStore = useMapStore() const tileMap = shallowRef() -onUnmounted(() => { - mapStore.reset() - gameStore.connection?.off('map:character:teleport') - gameStore.connection?.off('map:character:join') - gameStore.connection?.off('map:character:leave') - gameStore.connection?.off('map:character:move') -}) - // Event listeners gameStore.connection?.on('map:character:teleport', async (data: mapLoadData) => { mapStore.setMapId(data.mapId) @@ -43,4 +35,12 @@ gameStore.connection?.on('map:character:leave', (characterId: UUID) => { gameStore.connection?.on('map:character:move', (data: { characterId: UUID; positionX: number; positionY: number; rotation: number; isMoving: boolean }) => { mapStore.updateCharacterPosition(data) }) + +onUnmounted(() => { + mapStore.reset() + gameStore.connection?.off('map:character:teleport') + gameStore.connection?.off('map:character:join') + gameStore.connection?.off('map:character:leave') + gameStore.connection?.off('map:character:move') +}) diff --git a/src/components/screens/Game.vue b/src/components/screens/Game.vue index 24650f6..59f0fa7 100644 --- a/src/components/screens/Game.vue +++ b/src/components/screens/Game.vue @@ -24,7 +24,6 @@ import Effects from '@/components/Effects.vue' import Map from '@/components/game/map/Map.vue' import CharacterProfile from '@/components/gui/CharacterProfile.vue' import Chat from '@/components/gui/Chat.vue' -// import Minimap from '@/components/gui/Minimap.vue' import Clock from '@/components/gui/Clock.vue' import ExpBar from '@/components/gui/ExpBar.vue' import Hotkeys from '@/components/gui/Hotkeys.vue' @@ -42,22 +41,11 @@ const gameConfig = { width: window.innerWidth, height: window.innerHeight, type: Phaser.AUTO, // AUTO, CANVAS, WEBGL, HEADLESS - resolution: 5, - plugins: { - global: [ - { - key: 'rexAwaitLoader', - plugin: AwaitLoaderPlugin, - start: true - } - ] - } + resolution: 5 } const createGame = (game: Phaser.Game) => { - /** - * Resize the game when the window is resized - */ + // Resize the game when the window is resized addEventListener('resize', () => { game.scale.resize(window.innerWidth, window.innerHeight) }) @@ -73,9 +61,7 @@ const createGame = (game: Phaser.Game) => { } function preloadScene(scene: Phaser.Scene) { - /** - * Load the base assets into the Phaser scene - */ + // Load the base assets into the Phaser scene scene.load.image('blank_tile', '/assets/map/blank_tile.png') scene.load.image('waypoint', '/assets/waypoint.png') } diff --git a/src/components/screens/MapEditor.vue b/src/components/screens/MapEditor.vue index 6e676c8..5b7e06c 100644 --- a/src/components/screens/MapEditor.vue +++ b/src/components/screens/MapEditor.vue @@ -2,7 +2,7 @@
- +
@@ -11,12 +11,9 @@