make 'chunks' command accept a 'radius' param (which makes current_chunk redundant)
This commit is contained in:
parent
494b9b4107
commit
46ad618134
1 changed files with 15 additions and 41 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
import {emitPrototypes} from "../config-update/prototypes";
|
import {emitPrototypes} from "../config-update/prototypes";
|
||||||
import {handleChunkUpdate} from "../events/handlers";
|
|
||||||
import {Queue} from "../queue/queue";
|
import {Queue} from "../queue/queue";
|
||||||
import floor = math.floor;
|
import floor = math.floor;
|
||||||
|
|
||||||
|
|
@ -8,43 +7,20 @@ commands.add_command(
|
||||||
"kafkatorio",
|
"kafkatorio",
|
||||||
"kafkatorio innit bruv",
|
"kafkatorio innit bruv",
|
||||||
(e: CustomCommandData) => {
|
(e: CustomCommandData) => {
|
||||||
|
|
||||||
|
let player = (e.player_index != null) ? game.get_player(e.player_index) : null
|
||||||
|
|
||||||
if (e.parameter == undefined) {
|
if (e.parameter == undefined) {
|
||||||
|
if (player != null) {
|
||||||
|
player.print("no parameter")
|
||||||
|
}
|
||||||
// do nothing
|
// do nothing
|
||||||
} else if ("PROTOTYPES" == e.parameter.toUpperCase()) {
|
} else if ("PROTOTYPES" == e.parameter.toUpperCase()) {
|
||||||
emitPrototypes()
|
emitPrototypes()
|
||||||
} else if ("CURRENT_CHUNK" == e.parameter.toUpperCase()) {
|
} else if (e.parameter.toUpperCase().startsWith("CHUNKS")) {
|
||||||
|
|
||||||
if (e.player_index != undefined) {
|
let size = e.parameter.split(" ")?.[1] ?? null
|
||||||
|
let radius = (size != null) ? parseInt(size) : 1
|
||||||
let player = game.players[e.player_index]
|
|
||||||
|
|
||||||
let chunkPosition: ChunkPosition = {
|
|
||||||
x: floor(player.position.x / 32),
|
|
||||||
y: floor(player.position.y / 32),
|
|
||||||
}
|
|
||||||
|
|
||||||
let chunkLeftTop: Position = {
|
|
||||||
x: chunkPosition.x * 32,
|
|
||||||
y: chunkPosition.y * 32,
|
|
||||||
}
|
|
||||||
let chunkBottomRight: Position = {
|
|
||||||
x: chunkLeftTop.x + 32 - 1,
|
|
||||||
y: chunkLeftTop.y + 32 - 1,
|
|
||||||
}
|
|
||||||
let chunkArea: BoundingBoxRead = {
|
|
||||||
left_top: chunkLeftTop,
|
|
||||||
right_bottom: chunkBottomRight
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChunkUpdate(
|
|
||||||
e.tick,
|
|
||||||
"player-command-" + e.parameter,
|
|
||||||
player.surface.index,
|
|
||||||
chunkPosition,
|
|
||||||
chunkArea,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if ("CHUNKS" == e.parameter.toUpperCase()) {
|
|
||||||
|
|
||||||
if (e.player_index != undefined) {
|
if (e.player_index != undefined) {
|
||||||
let player = game.players[e.player_index]
|
let player = game.players[e.player_index]
|
||||||
|
|
@ -54,19 +30,17 @@ commands.add_command(
|
||||||
y: floor(player.position.y / 32),
|
y: floor(player.position.y / 32),
|
||||||
}
|
}
|
||||||
|
|
||||||
let delta = 1
|
let chunkXMin = chunkPosition.x - radius
|
||||||
|
let chunkXMax = chunkPosition.x + radius
|
||||||
let chunkXMin = chunkPosition.x - delta
|
let chunkYMin = chunkPosition.y - radius
|
||||||
let chunkXMax = chunkPosition.x + delta
|
let chunkYMax = chunkPosition.y + radius
|
||||||
let chunkYMin = chunkPosition.y - delta
|
|
||||||
let chunkYMax = chunkPosition.y + delta
|
|
||||||
|
|
||||||
for (let [, surface] of game.surfaces) {
|
for (let [, surface] of game.surfaces) {
|
||||||
for (let chunk of surface.get_chunks()) {
|
for (let chunk of surface.get_chunks()) {
|
||||||
if (
|
if (
|
||||||
(chunk.x >= chunkXMin || chunk.x <= chunkXMax)
|
(chunk.x >= chunkXMin && chunk.x <= chunkXMax)
|
||||||
&&
|
&&
|
||||||
(chunk.y >= chunkYMin || chunk.y <= chunkYMax)
|
(chunk.y >= chunkYMin && chunk.y <= chunkYMax)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
let data: OnChunkGeneratedEvent = {
|
let data: OnChunkGeneratedEvent = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue