Removed conflicting and redundant logic

This commit is contained in:
Dennis Postma 2025-02-10 13:39:17 +01:00
parent 9413fdbb2f
commit 592d1df9bf
7 changed files with 14 additions and 43 deletions

View File

@ -1,20 +1,18 @@
<template>
<div class="absolute top-0 right-4 hidden lg:block">
<p class="text-white text-lg">{{ gameStore.world.date.toLocaleString() }}</p>
<p class="text-white text-lg">
{{ useDateFormat(gameStore.world.date ?? new Date(), 'YYYY:MM:DD HH:mm:ss') }}
</p>
</div>
</template>
<script setup lang="ts">
import { useGameStore } from '@/stores/gameStore'
import { useDateFormat } from '@vueuse/core'
import { onUnmounted } from 'vue'
const gameStore = useGameStore()
// Listen for new date from socket
gameStore.connection?.on('date', (data: Date) => {
gameStore.world.date = new Date(data)
})
onUnmounted(() => {
gameStore.connection?.off('date')
})

View File

@ -46,7 +46,7 @@ const previewPlacedMapObject = computed(() => ({
function updatePreviewPosition(pointer: Phaser.Input.Pointer) {
const tile = getTile(props.tileMap, pointer.worldX, pointer.worldY)
if (!tile || previewPosition.value.x === tile.x && previewPosition.value.y === tile.y) return
if (!tile || (previewPosition.value.x === tile.x && previewPosition.value.y === tile.y)) return
previewPosition.value = { x: tile.x, y: tile.y }
}

View File

@ -39,15 +39,6 @@ const password = ref('')
const formError = ref('')
const showPassword = ref(false)
// automatic login because of development
onMounted(async () => {
const token = useCookies().get('token')
if (token) {
gameStore.setToken(token)
gameStore.initConnection()
}
})
async function submit() {
// check if username and password are valid
if (username.value === '' || password.value === '') {

View File

@ -34,15 +34,6 @@ const password = ref('')
const newPasswordError = ref('')
const showPassword = ref(false)
// automatic login because of development
onMounted(async () => {
const token = useCookies().get('token')
if (token) {
gameStore.setToken(token)
gameStore.initConnection()
}
})
async function newPasswordFunc() {
// check if username and password are valid
if (password.value === '') {

View File

@ -40,15 +40,6 @@ const email = ref('')
const formError = ref('')
const showPassword = ref(false)
// automatic login because of development
onMounted(async () => {
const token = useCookies().get('token')
if (token) {
gameStore.setToken(token)
gameStore.initConnection()
}
})
async function submit() {
// check if username and password are valid
if (username.value === '' || email.value === '' || password.value === '') {

View File

@ -44,13 +44,4 @@ function switchToLogin() {
currentForm.value = 'login'
doesUrlHaveToken.value = false
}
// automatic login because of development
onMounted(async () => {
const token = useCookies().get('token')
if (token) {
gameStore.setToken(token)
gameStore.initConnection()
}
})
</script>

View File

@ -96,8 +96,17 @@ export const useGameStore = defineStore('game', {
this.connection.on('reconnect_failed', () => {
this.disconnectSocket()
})
// Listen for new date from socket
this.connection.on('date', (data: Date) => {
this.world.date = new Date(data)
})
},
disconnectSocket() {
// Remove event listeners
this.connection?.off('connect_error')
this.connection?.off('reconnect_failed')
this.connection?.off('date')
this.connection?.disconnect()
useCookies().remove('token', {