1
0
forked from noxious/server

Minor improvements

This commit is contained in:
Dennis Postma 2025-02-06 13:12:19 +01:00
parent 9baffd1327
commit ba96ae7dd4
3 changed files with 18 additions and 11 deletions

View File

@ -27,19 +27,19 @@ export default class MapObjectUpdateEvent extends BaseEvent {
const mapObject = await mapObjectRepository.getById(data.id)
if (!mapObject) return callback(false)
await mapObject
.setName(data.name)
.setTags(data.tags)
.setOriginX(data.originX)
.setOriginY(data.originY)
.setFrameRate(data.frameRate)
.setFrameWidth(data.frameWidth)
.setFrameHeight(data.frameHeight)
.save()
if (data.name !== undefined) mapObject.name = data.name
if (data.tags !== undefined) mapObject.tags = data.tags
if (data.originX !== undefined) mapObject.originX = data.originX
if (data.originY !== undefined) mapObject.originY = data.originY
if (data.frameRate !== undefined) mapObject.frameRate = data.frameRate
if (data.frameWidth !== undefined) mapObject.frameWidth = data.frameWidth
if (data.frameHeight !== undefined) mapObject.frameHeight = data.frameHeight
await mapObject.save()
return callback(true)
} catch (error) {
console.error(error)
this.socket.emit('notification', { title: 'Error', message: 'Failed to update mapObject.' })
return callback(false)
}
}

View File

@ -23,7 +23,8 @@ export default class CharacterMove extends BaseEvent {
// If already moving, cancel current movement and wait for it to fully stop
if (mapCharacter.isMoving) {
mapCharacter.isMoving = false
await new Promise((resolve) => setTimeout(resolve, 100))
mapCharacter.currentPath = null
await new Promise((resolve) => setTimeout(resolve, 10))
}
const path = await this.characterService.calculatePath(mapCharacter.character, positionX, positionY)

View File

@ -29,6 +29,7 @@ class CharacterMoveService extends BaseService {
return null
}
// Ensure we're working with valid coordinates
const start: Position = {
positionX: Math.floor(character.positionX),
positionY: Math.floor(character.positionY)
@ -39,6 +40,11 @@ class CharacterMoveService extends BaseService {
positionY: Math.floor(targetY)
}
// Don't calculate path if start and end are the same
if (start.positionX === end.positionX && start.positionY === end.positionY) {
return null
}
return this.findPath(start, end, grid)
}