More typescript improvements

This commit is contained in:
2025-02-07 20:54:55 +01:00
parent f5e7d10fb4
commit 52b8a9b7ad
12 changed files with 35 additions and 14 deletions

View File

@ -64,7 +64,7 @@ export default class CharacterCreateEvent extends BaseEvent {
} catch (error: any) {
this.logger.error(`character:create error: ${error.message}`)
if (error instanceof ZodError) {
return this.socket.emit('notification', { title: 'Error', message: error.issues[0].message })
return this.socket.emit('notification', { title: 'Error', message: error.issues[0]!.message })
}
return this.socket.emit('notification', { title: 'Error', message: 'Could not create character. Please try again (later).' })
}

View File

@ -1,5 +1,7 @@
import type { MapCacheT } from '#entities/map'
import { BaseEvent } from '#application/base/baseEvent'
import { Map, MapCacheT } from '#entities/map'
import { Map } from '#entities/map'
type Payload = {
name: string

View File

@ -63,9 +63,11 @@ export default class MapUpdateEvent extends BaseEvent {
if (data.tiles.length > data.height) {
data.tiles = data.tiles.slice(0, data.height)
}
for (let i = 0; i < data.tiles.length; i++) {
if (data.tiles[i].length > data.width) {
data.tiles[i] = data.tiles[i].slice(0, data.width)
const row = data.tiles[i]
if (row !== undefined && row.length > data.width) {
data.tiles[i] = row.slice(0, data.width)
}
}

View File

@ -1,5 +1,6 @@
import type { MapEventTileWithTeleport } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
import { MapEventTileWithTeleport } from '#application/types'
import MapManager from '#managers/mapManager'
import MapCharacter from '#models/mapCharacter'
import MapEventTileRepository from '#repositories/mapEventTileRepository'
@ -75,6 +76,11 @@ export default class CharacterMove extends BaseEvent {
const [start, end] = [path[i], path[i + 1]]
if (!start || !end) {
this.logger.error('Invalid path step detected')
break
}
// Validate each step
if (Math.abs(end.positionX - start.positionX) > 1 || Math.abs(end.positionY - start.positionY) > 1) {
this.logger.error('Invalid path step detected')