More teleport improvements
This commit is contained in:
@ -16,17 +16,23 @@ class LoadedMap {
|
||||
return this.map
|
||||
}
|
||||
|
||||
public addCharacter(character: Character) {
|
||||
public addCharacter(character: Character): MapCharacter {
|
||||
const existingCharacter = this.getCharacterById(character.id)
|
||||
if (existingCharacter) {
|
||||
return existingCharacter
|
||||
}
|
||||
|
||||
const mapCharacter = new MapCharacter(character)
|
||||
this.characters.push(mapCharacter)
|
||||
return mapCharacter
|
||||
}
|
||||
|
||||
public async removeCharacter(id: UUID) {
|
||||
public async removeCharacter(id: UUID): Promise<void> {
|
||||
const mapCharacter = this.getCharacterById(id)
|
||||
if (mapCharacter) {
|
||||
await mapCharacter.savePosition()
|
||||
this.characters = this.characters.filter((c) => c.character.id !== id)
|
||||
}
|
||||
if (!mapCharacter) return
|
||||
|
||||
await mapCharacter.savePosition()
|
||||
this.characters = this.characters.filter((c) => c.character.id !== id)
|
||||
}
|
||||
|
||||
public getCharacterById(id: UUID): MapCharacter | undefined {
|
||||
@ -38,12 +44,11 @@ class LoadedMap {
|
||||
}
|
||||
|
||||
public async getGrid(): Promise<number[][]> {
|
||||
let grid: number[][] = Array.from({ length: this.map.height }, () => Array.from({ length: this.map.width }, () => 0))
|
||||
const grid: number[][] = Array.from({ length: this.map.height }, () => Array.from({ length: this.map.width }, () => 0))
|
||||
|
||||
const mapEventTileRepository = new MapEventTileRepository()
|
||||
const eventTiles = await mapEventTileRepository.getAll(this.map.id)
|
||||
|
||||
// Set the grid values based on the event tiles, these are strings
|
||||
eventTiles.forEach((eventTile) => {
|
||||
if (eventTile.type === 'BLOCK') {
|
||||
grid[eventTile.positionY]![eventTile.positionX] = 1
|
||||
|
Reference in New Issue
Block a user