Map event tile improvements

This commit is contained in:
2025-01-05 06:22:22 +01:00
parent 57b21f1499
commit d7982493e1
23 changed files with 198 additions and 115 deletions

View File

@ -8,7 +8,10 @@ class MapRepository extends BaseRepository {
async getFirst(): Promise<Map | null> {
try {
const repository = this.getEntityManager().getRepository(Map)
return await repository.findOne({ id: { $exists: true } })
const result = await repository.findOne({ id: { $exists: true } })
if (result) result.setEntityManager(this.getEntityManager())
return result
} catch (error: any) {
this.logger.error(`Failed to get first map: ${error instanceof Error ? error.message : String(error)}`)
return null
@ -18,7 +21,10 @@ class MapRepository extends BaseRepository {
async getAll(): Promise<Map[]> {
try {
const repository = this.getEntityManager().getRepository(Map)
return await repository.findAll()
const results = await repository.findAll()
for (const result of results) result.setEntityManager(this.getEntityManager())
return results
} catch (error: any) {
this.logger.error(`Failed to get all map: ${error.message}`)
return []
@ -41,7 +47,10 @@ class MapRepository extends BaseRepository {
async getEventTiles(id: UUID): Promise<MapEventTile[]> {
try {
const repository = this.getEntityManager().getRepository(MapEventTile)
return await repository.find({ map: id })
const results = await repository.find({ map: id })
for (const result of results) result.setEntityManager(this.getEntityManager())
return results
} catch (error: any) {
this.logger.error(`Failed to get map event tiles: ${error.message}`)
return []
@ -51,26 +60,19 @@ class MapRepository extends BaseRepository {
async getFirstEventTile(mapId: UUID, positionX: number, positionY: number): Promise<MapEventTile | null> {
try {
const repository = this.getEntityManager().getRepository(MapEventTile)
return await repository.findOne({
const result = await repository.findOne({
map: mapId,
positionX: positionX,
positionY: positionY
})
if (result) result.setEntityManager(this.getEntityManager())
return result
} catch (error: any) {
this.logger.error(`Failed to get map event tile: ${error.message}`)
return null
}
}
async getMapObjects(id: UUID): Promise<MapObject[]> {
try {
const repository = this.getEntityManager().getRepository(MapObject)
return await repository.find({ map: id })
} catch (error: any) {
this.logger.error(`Failed to get map objects: ${error.message}`)
return []
}
}
}
export default MapRepository