From f7b8c235d8dfe615a49c4ea0f72fc4bfc9402504 Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sun, 24 Nov 2024 15:13:11 +0100 Subject: [PATCH] Renamed hair > characterHair, split character logic (chat bubble, healthbar etc) into separate components for better DX --- package-lock.json | 6 +- src/components/game/character/Character.vue | 68 ++----------------- .../game/character/partials/CharacterHair.vue | 50 ++++++++++++++ .../game/character/partials/ChatBubble.vue | 46 +++++++++++++ .../game/character/partials/Healthbar.vue | 35 ++++++++++ .../game/zone/partials/ZoneObject.vue | 2 +- src/components/screens/Characters.vue | 6 +- src/composables/gameComposable.ts | 2 + src/stores/gameStore.ts | 5 +- src/types.ts | 8 +-- 10 files changed, 153 insertions(+), 75 deletions(-) create mode 100644 src/components/game/character/partials/CharacterHair.vue create mode 100644 src/components/game/character/partials/Healthbar.vue diff --git a/package-lock.json b/package-lock.json index d0efd8e..0ae476e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3147,9 +3147,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001683", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001683.tgz", - "integrity": "sha512-iqmNnThZ0n70mNwvxpEC2nBJ037ZHZUoBI5Gorh1Mw6IlEAZujEoU1tXA628iZfzm7R9FvFzxbfdgml82a3k8Q==", + "version": "1.0.30001684", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001684.tgz", + "integrity": "sha512-G1LRwLIQjBQoyq0ZJGqGIJUXzJ8irpbjHLpVRXDvBEScFJ9b17sgK6vlx0GAJFE21okD7zXl08rRRUfq6HdoEQ==", "dev": true, "funding": [ { diff --git a/src/components/game/character/Character.vue b/src/components/game/character/Character.vue index 1b5bf1a..f682b05 100644 --- a/src/components/game/character/Character.vue +++ b/src/components/game/character/Character.vue @@ -1,19 +1,8 @@ @@ -27,22 +16,24 @@ import { watch, computed, ref, onMounted, onUnmounted } from 'vue' import { Container, Image, refObj, RoundRectangle, Sprite, Text, useGame, useScene } from 'phavuer' import { calculateIsometricDepth, tileToWorldX, tileToWorldY } from '@/composables/zoneComposable' import { loadSpriteTextures } from '@/composables/gameComposable' +import ChatBubble from '@/components/game/character/partials/ChatBubble.vue' +import Healthbar from '@/components/game/character/partials/Healthbar.vue' +import CharacterHair from '@/components/game/character/partials/CharacterHair.vue' enum Direction { POSITIVE, NEGATIVE, UNCHANGED } + const props = defineProps<{ layer: Phaser.Tilemaps.TilemapLayer zoneCharacter: ZoneCharacter }>() -const charChatContainer = refObj() const charContainer = refObj() const charSprite = refObj() -const game = useGame() const gameStore = useGameStore() const zoneStore = useZoneStore() const scene = useScene() @@ -133,41 +124,6 @@ const updateSprite = () => { charSprite.value!.setTexture(charTexture.value) } -const createChatBubble = (container: Phaser.GameObjects.Container) => { - container.setName(`${props.zoneCharacter.character.name}_chatBubble`) -} - -const createChatText = (text: Phaser.GameObjects.Text) => { - text.setName(`${props.zoneCharacter.character.name}_chatText`) - text.setFontSize(13) - text.setFontFamily('Arial') - text.setOrigin(0.5, 10.9) - - // Fix text alignment on Windows and Android - if (game.device.os.windows || game.device.os.android) { - text.setOrigin(0.5, 9.75) - - if (game.device.browser.firefox) { - text.setOrigin(0.5, 10.9) - } - } -} - -const createNicknameText = (text: Phaser.GameObjects.Text) => { - text.setFontSize(13) - text.setFontFamily('Arial') - text.setOrigin(0.5, 9) - - // Fix text alignment on Windows and Android - if (game.device.os.windows || game.device.os.android) { - text.setOrigin(0.5, 8) - - if (game.device.browser.firefox) { - text.setOrigin(0.5, 9) - } - } -} - watch( () => props.zoneCharacter.character, (newChar, oldChar) => { @@ -182,14 +138,6 @@ watch( watch(() => props.zoneCharacter, updateSprite) - -// Hair demo -loadSpriteTextures(scene, props.zoneCharacter.character.hair?.sprite as SpriteT) - .then(() => {}) - .catch((error) => { - console.error('Error loading texture:', error) - }) - loadSpriteTextures(scene, props.zoneCharacter.character.characterType?.sprite as SpriteT) .then(() => { charSprite.value!.setTexture(charTexture.value) @@ -200,8 +148,6 @@ loadSpriteTextures(scene, props.zoneCharacter.character.characterType?.sprite as }) onMounted(() => { - charChatContainer.value!.setName(`${props.zoneCharacter.character!.name}_chatContainer`) - charChatContainer.value!.setVisible(false) charContainer.value!.setName(props.zoneCharacter.character!.name) if (props.zoneCharacter.character.id === gameStore.character!.id) { diff --git a/src/components/game/character/partials/CharacterHair.vue b/src/components/game/character/partials/CharacterHair.vue new file mode 100644 index 0000000..0fabfde --- /dev/null +++ b/src/components/game/character/partials/CharacterHair.vue @@ -0,0 +1,50 @@ + + + \ No newline at end of file diff --git a/src/components/game/character/partials/ChatBubble.vue b/src/components/game/character/partials/ChatBubble.vue index e69de29..b1be974 100644 --- a/src/components/game/character/partials/ChatBubble.vue +++ b/src/components/game/character/partials/ChatBubble.vue @@ -0,0 +1,46 @@ + + + \ No newline at end of file diff --git a/src/components/game/character/partials/Healthbar.vue b/src/components/game/character/partials/Healthbar.vue new file mode 100644 index 0000000..19fc0f4 --- /dev/null +++ b/src/components/game/character/partials/Healthbar.vue @@ -0,0 +1,35 @@ + + + \ No newline at end of file diff --git a/src/components/game/zone/partials/ZoneObject.vue b/src/components/game/zone/partials/ZoneObject.vue index a3678ae..6ef72ea 100644 --- a/src/components/game/zone/partials/ZoneObject.vue +++ b/src/components/game/zone/partials/ZoneObject.vue @@ -3,7 +3,7 @@