From c5d4ae8d63eb6e7bc3db14f599476ccafd155c0c Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Mon, 28 Feb 2022 20:35:15 +0100 Subject: [PATCH] fix factorio command --- .../main/commands/kafkatorioCommands.ts | 81 ++++++++++--------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/modules/events-mod/src/main/typescript/main/commands/kafkatorioCommands.ts b/modules/events-mod/src/main/typescript/main/commands/kafkatorioCommands.ts index 9b5faba..8286f8c 100644 --- a/modules/events-mod/src/main/typescript/main/commands/kafkatorioCommands.ts +++ b/modules/events-mod/src/main/typescript/main/commands/kafkatorioCommands.ts @@ -11,60 +11,63 @@ commands.add_command( const player = (e.player_index != null) ? game.get_player(e.player_index) : null - const paramUppercase = e.parameter?.toUpperCase() - - if (paramUppercase == undefined) { + if (e.parameter == undefined) { if (player != null) { player.print("no parameter") } // do nothing - } else if ("PROTOTYPES" == paramUppercase) { - emitPrototypes() - } else if (paramUppercase.startsWith("CHUNKS")) { + } else { - let size = paramUppercase.split(" ")?.[1] ?? null - let radius = (size != null) ? parseInt(size) : 1 + const paramUppercase: string = e.parameter.toUpperCase() - if (e.player_index != undefined) { - let player = game.players[e.player_index] + if ("PROTOTYPES" == paramUppercase) { + emitPrototypes() + } else if (paramUppercase.startsWith("CHUNKS")) { - let chunkPosition: ChunkPosition = { - x: floor(player.position.x / 32), - y: floor(player.position.y / 32), - } + let size = paramUppercase.split(" ")?.[1] ?? null + let radius = (size != null) ? parseInt(size) : 1 - let chunkXMin = chunkPosition.x - radius - let chunkXMax = chunkPosition.x + radius - let chunkYMin = chunkPosition.y - radius - let chunkYMax = chunkPosition.y + radius + if (e.player_index != undefined) { + let player = game.players[e.player_index] - for (let [, surface] of game.surfaces) { - for (let chunk of surface.get_chunks()) { - if ( - (chunk.x >= chunkXMin && chunk.x <= chunkXMax) - && - (chunk.y >= chunkYMin && chunk.y <= chunkYMax) - ) { + let chunkPosition: ChunkPosition = { + x: floor(player.position.x / 32), + y: floor(player.position.y / 32), + } - let data: OnChunkGeneratedEvent = { - name: defines.events.on_chunk_generated, - position: {x: chunk.x, y: chunk.y}, - area: chunk.area, - surface: surface, - tick: e.tick + let chunkXMin = chunkPosition.x - radius + let chunkXMax = chunkPosition.x + radius + let chunkYMin = chunkPosition.y - radius + let chunkYMax = chunkPosition.y + radius + + for (let [, surface] of game.surfaces) { + for (let chunk of surface.get_chunks()) { + if ( + (chunk.x >= chunkXMin && chunk.x <= chunkXMax) + && + (chunk.y >= chunkYMin && chunk.y <= chunkYMax) + ) { + + let data: OnChunkGeneratedEvent = { + name: defines.events.on_chunk_generated, + position: {x: chunk.x, y: chunk.y}, + area: chunk.area, + surface: surface, + tick: e.tick + } + + Queue.enqueue( + `${surface.index}${chunk.x}${chunk.y}`, + data, + 50 + ) } - - Queue.enqueue( - `${surface.index}${chunk.x}${chunk.y}`, - data, - 50 - ) } } } + } else if (paramUppercase.startsWith("INIT_GLOBAL")) { + initGlobal(paramUppercase.startsWith("INIT_GLOBAL FORCE")) } - } else if (paramUppercase.startsWith("INIT_GLOBAL")) { - initGlobal(paramUppercase.startsWith("INIT_GLOBAL FORCE")) } } )