fix factorio command

This commit is contained in:
Adam 2022-02-28 20:35:15 +01:00
parent 52fcfbaa93
commit c5d4ae8d63

View file

@ -11,60 +11,63 @@ commands.add_command(
const player = (e.player_index != null) ? game.get_player(e.player_index) : null const player = (e.player_index != null) ? game.get_player(e.player_index) : null
const paramUppercase = e.parameter?.toUpperCase() if (e.parameter == undefined) {
if (paramUppercase == undefined) {
if (player != null) { if (player != null) {
player.print("no parameter") player.print("no parameter")
} }
// do nothing // do nothing
} else if ("PROTOTYPES" == paramUppercase) { } else {
emitPrototypes()
} else if (paramUppercase.startsWith("CHUNKS")) {
let size = paramUppercase.split(" ")?.[1] ?? null const paramUppercase: string = e.parameter.toUpperCase()
let radius = (size != null) ? parseInt(size) : 1
if (e.player_index != undefined) { if ("PROTOTYPES" == paramUppercase) {
let player = game.players[e.player_index] emitPrototypes()
} else if (paramUppercase.startsWith("CHUNKS")) {
let chunkPosition: ChunkPosition = { let size = paramUppercase.split(" ")?.[1] ?? null
x: floor(player.position.x / 32), let radius = (size != null) ? parseInt(size) : 1
y: floor(player.position.y / 32),
}
let chunkXMin = chunkPosition.x - radius if (e.player_index != undefined) {
let chunkXMax = chunkPosition.x + radius let player = game.players[e.player_index]
let chunkYMin = chunkPosition.y - radius
let chunkYMax = chunkPosition.y + radius
for (let [, surface] of game.surfaces) { let chunkPosition: ChunkPosition = {
for (let chunk of surface.get_chunks()) { x: floor(player.position.x / 32),
if ( y: floor(player.position.y / 32),
(chunk.x >= chunkXMin && chunk.x <= chunkXMax) }
&&
(chunk.y >= chunkYMin && chunk.y <= chunkYMax)
) {
let data: OnChunkGeneratedEvent = { let chunkXMin = chunkPosition.x - radius
name: defines.events.on_chunk_generated, let chunkXMax = chunkPosition.x + radius
position: {x: chunk.x, y: chunk.y}, let chunkYMin = chunkPosition.y - radius
area: chunk.area, let chunkYMax = chunkPosition.y + radius
surface: surface,
tick: e.tick 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"))
} }
} }
) )