Refactor App.vue

This commit is contained in:
Dennis Postma 2024-10-16 16:04:29 +02:00
parent 27e857b9a6
commit 13be1a38fa

View File

@ -1,34 +1,31 @@
<template> <template>
<div class="overflow-hidden"> <div class="overflow-hidden">
<Notifications /> <Notifications />
<Login v-if="screen === 'login'" /> <component :is="currentScreen" />
<Characters v-if="screen === 'characters'" />
<Game v-if="screen === 'game'" />
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useGameStore } from '@/stores/gameStore' import { useGameStore } from '@/stores/gameStore'
import { useZoneEditorStore } from '@/stores/zoneEditorStore'
import Notifications from '@/components/utilities/Notifications.vue' import Notifications from '@/components/utilities/Notifications.vue'
import Login from '@/screens/Login.vue' import Login from '@/screens/Login.vue'
import Characters from '@/screens/Characters.vue' import Characters from '@/screens/Characters.vue'
import Game from '@/screens/Game.vue' import Game from '@/screens/Game.vue'
import ZoneEditor from '@/screens/ZoneEditor.vue'
import { computed } from 'vue' import { computed } from 'vue'
const gameStore = useGameStore() const gameStore = useGameStore()
const zoneEditorStore = useZoneEditorStore()
const screen = computed(() => { const currentScreen = computed(() => {
if (!gameStore.connection) { if (!gameStore.connection) return Login
return 'login' if (!gameStore.token) return Login
} else if (gameStore.token && gameStore.connection) { if (!gameStore.character) return Characters
if (gameStore.character) { if (zoneEditorStore.active) return ZoneEditor
return 'game' return Game
}
return 'characters'
}
return 'login' // default fallback
}) })
// Disable right click // Disable right click
addEventListener('contextmenu', (event) => event.preventDefault()) addEventListener('contextmenu', (event) => event.preventDefault())
</script> </script>