More typescript improvements
This commit is contained in:
@ -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).' })
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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')
|
||||
|
Reference in New Issue
Block a user