Zone editor UX improvements, possibly fixed login issue after registration

This commit is contained in:
Dennis Postma 2024-07-21 22:48:16 +02:00
parent 12cd7b667a
commit 338d4d312b
5 changed files with 21 additions and 14 deletions

View File

@ -9,6 +9,7 @@ import { storeToRefs } from 'pinia'
import config from '@/config' import config from '@/config'
import { getTile, tileToWorldXY } from '@/services/zone' import { getTile, tileToWorldXY } from '@/services/zone'
import { useZoneEditorStore } from '@/stores/zoneEditor' import { useZoneEditorStore } from '@/stores/zoneEditor'
import { useGameStore } from '@/stores/game'
const props = defineProps<{ const props = defineProps<{
layer: Phaser.Tilemaps.TilemapLayer layer: Phaser.Tilemaps.TilemapLayer
@ -16,6 +17,7 @@ const props = defineProps<{
const scene = useScene() const scene = useScene()
const zoneEditorStore = useZoneEditorStore() const zoneEditorStore = useZoneEditorStore()
const gameStore = useGameStore()
const { tool } = storeToRefs(zoneEditorStore) const { tool } = storeToRefs(zoneEditorStore)
const waypoint = ref({ const waypoint = ref({
@ -63,11 +65,13 @@ function setupEventListeners() {
scene.input.on(Phaser.Input.Events.POINTER_DOWN, (pointer: Phaser.Input.Pointer) => { scene.input.on(Phaser.Input.Events.POINTER_DOWN, (pointer: Phaser.Input.Pointer) => {
if (pointer.event.altKey || tool.value === 'move') { if (pointer.event.altKey || tool.value === 'move') {
gameStore.setMovingCamera(true)
scene.input.on(Phaser.Input.Events.POINTER_MOVE, dragZone) scene.input.on(Phaser.Input.Events.POINTER_MOVE, dragZone)
} }
}) })
scene.input.on(Phaser.Input.Events.POINTER_UP, () => { scene.input.on(Phaser.Input.Events.POINTER_UP, () => {
gameStore.setMovingCamera(false)
scene.input.off(Phaser.Input.Events.POINTER_MOVE, dragZone) scene.input.off(Phaser.Input.Events.POINTER_MOVE, dragZone)
}) })
} }

View File

@ -39,7 +39,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { Object } from '@/types' import type { Object } from '@/types'
import { computed, onBeforeMount, onBeforeUnmount, onMounted, ref, watch } from 'vue' import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useAssetManagerStore } from '@/stores/assetManager' import { useAssetManagerStore } from '@/stores/assetManager'
import { useZoneEditorStore } from '@/stores/zoneEditor' import { useZoneEditorStore } from '@/stores/zoneEditor'
import { useGameStore } from '@/stores/game' import { useGameStore } from '@/stores/game'
@ -56,7 +56,7 @@ const objectName = ref('')
const objectTags = ref([] as string[]) const objectTags = ref([] as string[])
const objectOriginX = ref(0) const objectOriginX = ref(0)
const objectOriginY = ref(0) const objectOriginY = ref(0)
const objectIsAnimated = ref(0) const objectIsAnimated = ref(false)
if (!selectedObject.value) { if (!selectedObject.value) {
console.error('No object selected') console.error('No object selected')
@ -67,7 +67,7 @@ if (selectedObject.value) {
objectTags.value = selectedObject.value.tags objectTags.value = selectedObject.value.tags
objectOriginX.value = selectedObject.value.origin_x objectOriginX.value = selectedObject.value.origin_x
objectOriginY.value = selectedObject.value.origin_y objectOriginY.value = selectedObject.value.origin_y
objectIsAnimated.value = selectedObject.value.is_animated objectIsAnimated.value = selectedObject.value.isAnimated
} }
function removeObject() { function removeObject() {

View File

@ -25,7 +25,6 @@
</form> </form>
</div> </div>
</div> </div>
<audio ref="bgm" id="bgm" src="/assets/music/bgm.mp3" loop autoplay></audio>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -35,12 +34,6 @@ import { useNotificationStore } from '@/stores/notifications'
import { useGameStore } from '@/stores/game' import { useGameStore } from '@/stores/game'
import { useAssetStore } from '@/stores/assets' import { useAssetStore } from '@/stores/assets'
const bgm = ref('bgm')
if (bgm.value.paused) {
addEventListener('click', () => bgm.value.play())
addEventListener('keydown', () => bgm.value.play())
}
const gameStore = useGameStore() const gameStore = useGameStore()
const notifications = useNotificationStore() const notifications = useNotificationStore()
const assetStore = useAssetStore() const assetStore = useAssetStore()
@ -73,7 +66,7 @@ async function loginFunc() {
} }
gameStore.setToken(response.token) gameStore.setToken(response.token)
await gameStore.initConnection() gameStore.initConnection()
} }
async function registerFunc() { async function registerFunc() {
@ -91,7 +84,6 @@ async function registerFunc() {
return return
} }
gameStore.setToken(response.token) await loginFunc()
await gameStore.initConnection()
} }
</script> </script>

View File

@ -11,7 +11,8 @@ export const useGameStore = defineStore('game', {
connection: null as Socket | null, connection: null as Socket | null,
user: null as User | null, user: null as User | null,
character: null as Character | null, character: null as Character | null,
isGmPanelOpen: false isGmPanelOpen: false,
isMovingCamera: false
}), }),
actions: { actions: {
setScreen(screen: string) { setScreen(screen: string) {
@ -29,6 +30,12 @@ export const useGameStore = defineStore('game', {
toggleGmPanel() { toggleGmPanel() {
this.isGmPanelOpen = !this.isGmPanelOpen this.isGmPanelOpen = !this.isGmPanelOpen
}, },
toggleMovingCamera() {
this.isMovingCamera = !this.isMovingCamera
},
setMovingCamera(moving: boolean) {
this.isMovingCamera = moving
},
initConnection() { initConnection() {
this.connection = io(config.server_endpoint, { this.connection = io(config.server_endpoint, {
secure: !config.development, secure: !config.development,

View File

@ -1,4 +1,5 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { useGameStore } from '@/stores/game';
import type { Zone, Object, Tile, ZoneObject } from '@/types' import type { Zone, Object, Tile, ZoneObject } from '@/types'
export const useZoneEditorStore = defineStore('zoneEditor', { export const useZoneEditorStore = defineStore('zoneEditor', {
@ -62,6 +63,9 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
this.selectedObject = object this.selectedObject = object
}, },
setSelectedZoneObject(zoneObject: ZoneObject) { setSelectedZoneObject(zoneObject: ZoneObject) {
const gameStore = useGameStore(); // Access the gameStore
if (gameStore.isMovingCamera) return; // Step 2: Check isMovingCamera before proceeding
this.selectedZoneObject = zoneObject this.selectedZoneObject = zoneObject
}, },
setObjectDepth(depth: number) { setObjectDepth(depth: number) {