- start code clean up by commenting out unused/deprecated code (start moving towards the 'event updates' Kafkatorio packets
- bring back the event Queue, and the command to emit lots of chunks - allow setting the event update timeout directly when debouncing/throttling an update
This commit is contained in:
parent
1fbe0d87b0
commit
8d36111d9a
11 changed files with 613 additions and 636 deletions
|
|
@ -11,7 +11,6 @@ require("./main/cache/cacheChecker")
|
|||
|
||||
script.on_configuration_changed((data: ConfigurationChangedData) => {
|
||||
// runs whenever the version of the base game, or a mod, changes
|
||||
|
||||
initGlobal(true)
|
||||
KafkatorioSettings.loadSettings()
|
||||
emitConfigurationUpdate(data)
|
||||
|
|
|
|||
|
|
@ -1,38 +1,11 @@
|
|||
// Generated by TypeScriptGenerator - do not edit this file manually
|
||||
|
||||
type ObjectName = "LuaPlayer" | "LuaEntity" | "LuaSurface" | "MapChunk" | "LuaTiles" | "ConsoleChatMessage";
|
||||
type ObjectName = "LuaSurface" | "ConsoleChatMessage";
|
||||
|
||||
interface FactorioObjectData {
|
||||
objectName: ObjectName;
|
||||
}
|
||||
|
||||
interface PlayerData extends FactorioObjectData, FactorioLuaControl {
|
||||
associatedCharactersUnitNumbers: uint[];
|
||||
characterUnitNumber: uint | null;
|
||||
chatColour: Colour;
|
||||
colour: Colour;
|
||||
force: uint;
|
||||
lastOnline: uint;
|
||||
name: string;
|
||||
objectName: ObjectName;
|
||||
position: MapEntityPosition;
|
||||
surface: uint;
|
||||
}
|
||||
|
||||
interface EntityData extends FactorioObjectData, FactorioLuaControl {
|
||||
active: boolean;
|
||||
force: uint;
|
||||
health: double | null;
|
||||
healthRatio: double | null;
|
||||
name: string;
|
||||
objectName: ObjectName;
|
||||
playerIndex: uint | null;
|
||||
position: MapEntityPosition;
|
||||
surface: uint;
|
||||
type: string;
|
||||
unitNumber: uint | null;
|
||||
}
|
||||
|
||||
interface SurfaceData extends FactorioObjectData {
|
||||
daytime: double;
|
||||
index: uint;
|
||||
|
|
@ -40,19 +13,6 @@ interface SurfaceData extends FactorioObjectData {
|
|||
objectName: ObjectName;
|
||||
}
|
||||
|
||||
interface MapTiles extends FactorioObjectData {
|
||||
objectName: ObjectName;
|
||||
surfaceIndex: uint;
|
||||
tiles: MapTile[];
|
||||
}
|
||||
|
||||
interface MapChunk extends FactorioObjectData {
|
||||
area: MapBoundingBox;
|
||||
objectName: ObjectName;
|
||||
position: MapChunkPosition;
|
||||
tiles: MapTiles;
|
||||
}
|
||||
|
||||
interface ConsoleChatMessage extends FactorioObjectData {
|
||||
authorPlayerIndex: uint | null;
|
||||
content: string;
|
||||
|
|
|
|||
|
|
@ -16,17 +16,6 @@ interface FactorioEvent extends KafkatorioPacket {
|
|||
tick: uint;
|
||||
}
|
||||
|
||||
interface MapEntityPosition {
|
||||
x: double;
|
||||
y: double;
|
||||
}
|
||||
|
||||
interface FactorioLuaControl {
|
||||
force: uint;
|
||||
position: MapEntityPosition;
|
||||
surface: uint;
|
||||
}
|
||||
|
||||
interface Colour {
|
||||
alpha: float;
|
||||
blue: float;
|
||||
|
|
@ -34,33 +23,28 @@ interface Colour {
|
|||
red: float;
|
||||
}
|
||||
|
||||
interface MapTilePosition {
|
||||
x: int;
|
||||
y: int;
|
||||
}
|
||||
|
||||
interface MapBoundingBox {
|
||||
bottomRight: MapTilePosition;
|
||||
topLeft: MapTilePosition;
|
||||
}
|
||||
|
||||
interface MapChunkPosition {
|
||||
x: int;
|
||||
y: int;
|
||||
}
|
||||
|
||||
interface MapTile {
|
||||
proto: string;
|
||||
x: int;
|
||||
y: int;
|
||||
}
|
||||
|
||||
interface EntityIdentifiers {
|
||||
name: string;
|
||||
type: string;
|
||||
unitNumber: uint | null;
|
||||
}
|
||||
|
||||
interface EntityIdentifiersData extends EntityIdentifiers {
|
||||
name: string;
|
||||
type: string;
|
||||
unitNumber: uint | null;
|
||||
}
|
||||
|
||||
interface MapEntityPosition {
|
||||
x: double;
|
||||
y: double;
|
||||
}
|
||||
|
||||
interface MapChunkPosition {
|
||||
x: int;
|
||||
y: int;
|
||||
}
|
||||
|
||||
interface MapTileDictionary {
|
||||
protos: { [key: string]: string };
|
||||
tilesXY: { [key: string]: { [key: string]: string } };
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@ export namespace EventUpdates {
|
|||
public throttle<TYPE extends FactorioEventUpdateType>(
|
||||
key: CacheKey<TYPE>,
|
||||
mutate: CacheDataMutator<TYPE>,
|
||||
expirationDurationTicks?: uint,
|
||||
) {
|
||||
this.update(key, mutate, false)
|
||||
this.update(key, mutate, false, expirationDurationTicks)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -44,8 +45,9 @@ export namespace EventUpdates {
|
|||
public debounce<TYPE extends FactorioEventUpdateType>(
|
||||
key: CacheKey<TYPE>,
|
||||
mutate: CacheDataMutator<TYPE>,
|
||||
expirationDurationTicks?: uint,
|
||||
) {
|
||||
this.update(key, mutate, true)
|
||||
this.update(key, mutate, true, expirationDurationTicks)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -53,12 +55,16 @@ export namespace EventUpdates {
|
|||
key: CacheKey<TYPE>,
|
||||
mutate: CacheDataMutator<TYPE>,
|
||||
resetLastUpdated: boolean,
|
||||
expirationDurationTicks?: uint,
|
||||
) {
|
||||
const entry = this.getCacheEntry(key) ?? this.createCacheEntry(key, mutate)
|
||||
const entry: CacheEntry<TYPE> = this.getCacheEntry(key) ?? this.createCacheEntry(key, mutate)
|
||||
mutate(entry.data)
|
||||
if (resetLastUpdated) {
|
||||
entry.lastUpdatedTick = game.tick
|
||||
}
|
||||
if (expirationDurationTicks != undefined) {
|
||||
entry.expirationDurationTicks = expirationDurationTicks
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {emitPrototypes} from "../config-update/prototypes";
|
||||
import {Queue} from "../queue/queue";
|
||||
import {initGlobal} from "../global-init";
|
||||
import floor = math.floor;
|
||||
import {Queue} from "../queue/queue";
|
||||
|
||||
|
||||
commands.add_command(
|
||||
|
|
@ -24,22 +24,24 @@ commands.add_command(
|
|||
emitPrototypes()
|
||||
} else if (paramUppercase.startsWith("CHUNKS")) {
|
||||
|
||||
let size = paramUppercase.split(" ")?.[1] ?? null
|
||||
const size = paramUppercase.split(" ")?.[1] ?? null
|
||||
let radius = (size != null) ? parseInt(size) : 1
|
||||
// radius = Math.max(radius, 10)
|
||||
|
||||
if (e.player_index != undefined) {
|
||||
let player = game.players[e.player_index]
|
||||
|
||||
let chunkPosition: ChunkPosition = {
|
||||
const chunkPosition: ChunkPosition = {
|
||||
x: floor(player.position.x / 32),
|
||||
y: floor(player.position.y / 32),
|
||||
}
|
||||
|
||||
let chunkXMin = chunkPosition.x - radius
|
||||
let chunkXMax = chunkPosition.x + radius
|
||||
let chunkYMin = chunkPosition.y - radius
|
||||
let chunkYMax = chunkPosition.y + radius
|
||||
const chunkXMin = chunkPosition.x - radius
|
||||
const chunkXMax = chunkPosition.x + radius
|
||||
const chunkYMin = chunkPosition.y - radius
|
||||
const chunkYMax = chunkPosition.y + radius
|
||||
|
||||
// let i = 100
|
||||
for (const [, surface] of game.surfaces) {
|
||||
for (const chunk of surface.get_chunks()) {
|
||||
if (
|
||||
|
|
@ -48,7 +50,7 @@ commands.add_command(
|
|||
(chunk.y >= chunkYMin && chunk.y <= chunkYMax)
|
||||
) {
|
||||
|
||||
let data: OnChunkGeneratedEvent = {
|
||||
const data: OnChunkGeneratedEvent = {
|
||||
name: defines.events.on_chunk_generated,
|
||||
position: {x: chunk.x, y: chunk.y},
|
||||
area: chunk.area,
|
||||
|
|
@ -61,6 +63,9 @@ commands.add_command(
|
|||
data,
|
||||
50
|
||||
)
|
||||
|
||||
// handleChunkGeneratedEvent(data, i)
|
||||
// i = i + 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,38 +29,38 @@ export namespace Converters {
|
|||
}
|
||||
|
||||
|
||||
export function entityToTable(entity: LuaEntity): EntityData {
|
||||
|
||||
let player: LuaPlayer | null = entity.is_player() ? entity.player!! : null
|
||||
|
||||
return {
|
||||
objectName: entity.object_name,
|
||||
|
||||
// entity data
|
||||
name: entity.name,
|
||||
type: entity.type,
|
||||
active: entity.active,
|
||||
health: entity.health ?? null,
|
||||
healthRatio: entity.get_health_ratio() ?? null,
|
||||
surface: entity.surface.index,
|
||||
unitNumber: entity.unit_number ?? null,
|
||||
position: mapEntityPosition(entity.position),
|
||||
force: entity.force.index,
|
||||
|
||||
// player data
|
||||
playerIndex: player?.index ?? null
|
||||
}
|
||||
}
|
||||
|
||||
function entitiesToUnitNumbers(entities: LuaEntity[]): uint[] {
|
||||
let result: (uint) [] = []
|
||||
for (let entity of entities) {
|
||||
if (entity.unit_number != null) {
|
||||
result[result.length] = entity.unit_number
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
// export function entityToTable(entity: LuaEntity): EntityData {
|
||||
//
|
||||
// let player: LuaPlayer | null = entity.is_player() ? entity.player!! : null
|
||||
//
|
||||
// return {
|
||||
// objectName: entity.object_name,
|
||||
//
|
||||
// // entity data
|
||||
// name: entity.name,
|
||||
// type: entity.type,
|
||||
// active: entity.active,
|
||||
// health: entity.health ?? null,
|
||||
// healthRatio: entity.get_health_ratio() ?? null,
|
||||
// surface: entity.surface.index,
|
||||
// unitNumber: entity.unit_number ?? null,
|
||||
// position: mapEntityPosition(entity.position),
|
||||
// force: entity.force.index,
|
||||
//
|
||||
// // player data
|
||||
// playerIndex: player?.index ?? null
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// function entitiesToUnitNumbers(entities: LuaEntity[]): uint[] {
|
||||
// let result: (uint) [] = []
|
||||
// for (let entity of entities) {
|
||||
// if (entity.unit_number != null) {
|
||||
// result[result.length] = entity.unit_number
|
||||
// }
|
||||
// }
|
||||
// return result
|
||||
// }
|
||||
|
||||
export function surfaceToTable(surface: LuaSurface): SurfaceData {
|
||||
return {
|
||||
|
|
@ -72,26 +72,26 @@ export namespace Converters {
|
|||
}
|
||||
}
|
||||
|
||||
export function mapEntityPosition(mapPos: MapPositionTable): MapEntityPosition {
|
||||
return {
|
||||
x: mapPos.x,
|
||||
y: mapPos.y,
|
||||
}
|
||||
}
|
||||
// export function mapEntityPosition(mapPos: MapPositionTable): MapEntityPosition {
|
||||
// return {
|
||||
// x: mapPos.x,
|
||||
// y: mapPos.y,
|
||||
// }
|
||||
// }
|
||||
|
||||
export function mapTilePosition(mapPos: MapPositionTable): MapTilePosition {
|
||||
return {
|
||||
x: mapPos.x,
|
||||
y: mapPos.y,
|
||||
}
|
||||
}
|
||||
// export function mapTilePosition(mapPos: MapPositionTable): MapTilePosition {
|
||||
// return {
|
||||
// x: mapPos.x,
|
||||
// y: mapPos.y,
|
||||
// }
|
||||
// }
|
||||
|
||||
export function mapChunkPosition(mapPos: ChunkPositionTable): MapChunkPosition {
|
||||
return {
|
||||
x: mapPos.x,
|
||||
y: mapPos.y,
|
||||
}
|
||||
}
|
||||
// export function mapChunkPosition(mapPos: ChunkPositionTable): MapChunkPosition {
|
||||
// return {
|
||||
// x: mapPos.x,
|
||||
// y: mapPos.y,
|
||||
// }
|
||||
// }
|
||||
|
||||
export function mapColour(color: ColorTable): Colour {
|
||||
return {
|
||||
|
|
@ -111,23 +111,23 @@ export namespace Converters {
|
|||
}
|
||||
}
|
||||
|
||||
export function convertTile(tile: LuaTile): MapTile {
|
||||
return {
|
||||
x: tile.position.x,
|
||||
y: tile.position.y,
|
||||
proto: tile.prototype.name,
|
||||
}
|
||||
}
|
||||
// export function convertTile(tile: LuaTile): MapTile {
|
||||
// return {
|
||||
// x: tile.position.x,
|
||||
// y: tile.position.y,
|
||||
// proto: tile.prototype.name,
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// export function convertTiles(tiles: LuaTile[]): MapTile[] {
|
||||
// return tiles.map((tile: LuaTile) => convertTile(tile))
|
||||
// }
|
||||
|
||||
export function convertTiles(tiles: LuaTile[]): MapTile[] {
|
||||
return tiles.map((tile: LuaTile) => convertTile(tile))
|
||||
}
|
||||
|
||||
export function convertBoundingBox(bb: BoundingBoxRead): MapBoundingBox {
|
||||
return {
|
||||
topLeft: mapTilePosition(bb.left_top),
|
||||
bottomRight: mapTilePosition(bb.right_bottom),
|
||||
}
|
||||
}
|
||||
// export function convertBoundingBox(bb: BoundingBoxRead): MapBoundingBox {
|
||||
// return {
|
||||
// topLeft: mapTilePosition(bb.left_top),
|
||||
// bottomRight: mapTilePosition(bb.right_bottom),
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,24 +10,24 @@ import {emitEvent} from "./emitEvent";
|
|||
// handleCharactersEvent(tick, eventType, playerIndex)
|
||||
// }
|
||||
|
||||
export function handleCharactersEvent(tick: uint, eventType: string, playerIndex: uint) {
|
||||
// export function handleCharactersEvent(tick: uint, eventType: string, playerIndex: uint) {
|
||||
//
|
||||
// let player: LuaPlayer = game.players[playerIndex]
|
||||
//
|
||||
// if (player.character != undefined) {
|
||||
// handleEntityUpdate(tick, eventType, player.character)
|
||||
// }
|
||||
// for (const character of player.get_associated_characters()) {
|
||||
// if (character != undefined) {
|
||||
// handleEntityUpdate(tick, eventType, character)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
let player: LuaPlayer = game.players[playerIndex]
|
||||
|
||||
if (player.character != undefined) {
|
||||
handleEntityUpdate(tick, eventType, player.character)
|
||||
}
|
||||
for (const character of player.get_associated_characters()) {
|
||||
if (character != undefined) {
|
||||
handleEntityUpdate(tick, eventType, character)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function handleEntityUpdate(tick: uint, eventType: string, entity: LuaEntity) {
|
||||
let table = Converters.entityToTable(entity)
|
||||
emitEvent(table, tick, eventType)
|
||||
}
|
||||
// export function handleEntityUpdate(tick: uint, eventType: string, entity: LuaEntity) {
|
||||
// let table = Converters.entityToTable(entity)
|
||||
// emitEvent(table, tick, eventType)
|
||||
// }
|
||||
|
||||
export function handleSurfaceUpdate(
|
||||
tick: uint,
|
||||
|
|
@ -48,35 +48,35 @@ export function handleConsoleChat(
|
|||
emitEvent(table, tick, eventType)
|
||||
}
|
||||
|
||||
export function handleChunkUpdate(
|
||||
tick: uint,
|
||||
eventType: string,
|
||||
surfaceIndex: uint,
|
||||
position: ChunkPositionTable,
|
||||
area: BoundingBoxRead,
|
||||
) {
|
||||
|
||||
let surface = game.get_surface(surfaceIndex)
|
||||
|
||||
let tiles: LuaTile[] = surface?.find_tiles_filtered({
|
||||
area: area,
|
||||
collision_mask: ["ground-tile", "water-tile"]
|
||||
}
|
||||
) ?? []
|
||||
|
||||
let convertedTiles: MapTile[] = tiles.map((tile: LuaTile) => {
|
||||
return Converters.convertTile(tile)
|
||||
})
|
||||
|
||||
let mapChunk: MapChunk = {
|
||||
objectName: "MapChunk",
|
||||
tiles: createMapTiles(surfaceIndex, convertedTiles),
|
||||
position: Converters.mapChunkPosition(position),
|
||||
area: Converters.convertBoundingBox(area),
|
||||
}
|
||||
|
||||
emitEvent(mapChunk, tick, eventType)
|
||||
}
|
||||
// export function handleChunkUpdate(
|
||||
// tick: uint,
|
||||
// eventType: string,
|
||||
// surfaceIndex: uint,
|
||||
// position: ChunkPositionTable,
|
||||
// area: BoundingBoxRead,
|
||||
// ) {
|
||||
//
|
||||
// let surface = game.get_surface(surfaceIndex)
|
||||
//
|
||||
// let tiles: LuaTile[] = surface?.find_tiles_filtered({
|
||||
// area: area,
|
||||
// collision_mask: ["ground-tile", "water-tile"]
|
||||
// }
|
||||
// ) ?? []
|
||||
//
|
||||
// let convertedTiles: MapTile[] = tiles.map((tile: LuaTile) => {
|
||||
// return Converters.convertTile(tile)
|
||||
// })
|
||||
//
|
||||
// let mapChunk: MapChunk = {
|
||||
// objectName: "MapChunk",
|
||||
// tiles: createMapTiles(surfaceIndex, convertedTiles),
|
||||
// position: Converters.mapChunkPosition(position),
|
||||
// area: Converters.convertBoundingBox(area),
|
||||
// }
|
||||
//
|
||||
// emitEvent(mapChunk, tick, eventType)
|
||||
// }
|
||||
|
||||
// export function handleTilesUpdate(
|
||||
// tick: uint,
|
||||
|
|
@ -104,13 +104,13 @@ export function handleChunkUpdate(
|
|||
// }
|
||||
// }
|
||||
|
||||
function createMapTiles(
|
||||
surfaceIndex: uint,
|
||||
tiles: MapTile[],
|
||||
): MapTiles {
|
||||
return {
|
||||
objectName: "LuaTiles",
|
||||
surfaceIndex: surfaceIndex,
|
||||
tiles: tiles,
|
||||
}
|
||||
}
|
||||
// function createMapTiles(
|
||||
// surfaceIndex: uint,
|
||||
// tiles: MapTile[],
|
||||
// ): MapTiles {
|
||||
// return {
|
||||
// objectName: "LuaTiles",
|
||||
// surfaceIndex: surfaceIndex,
|
||||
// tiles: tiles,
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ type MapChunkUpdater = (data: CacheData<"MAP_CHUNK">) => void
|
|||
const mapProtoNameToKey: { [key: string]: string } = {}
|
||||
let protoIndex: uint = 0
|
||||
|
||||
|
||||
function getProtoKey(protoName: string): string {
|
||||
if (mapProtoNameToKey[protoName] == undefined) {
|
||||
mapProtoNameToKey[protoName] = `${protoIndex++}`
|
||||
|
|
@ -25,6 +26,7 @@ function mapTilesUpdateDebounce(
|
|||
tiles: TileRead[],
|
||||
eventName: string,
|
||||
updater?: MapChunkUpdater,
|
||||
expirationDurationTicks?: uint,
|
||||
) {
|
||||
|
||||
if (surface == undefined) {
|
||||
|
|
@ -64,7 +66,8 @@ function mapTilesUpdateDebounce(
|
|||
if (updater != undefined) {
|
||||
updater(data)
|
||||
}
|
||||
}
|
||||
},
|
||||
expirationDurationTicks,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -80,20 +83,37 @@ function getTiles(
|
|||
) ?? []
|
||||
}
|
||||
|
||||
|
||||
function getSurface(surfaceIndex: uint): LuaSurface | undefined {
|
||||
return game.surfaces[surfaceIndex]
|
||||
}
|
||||
|
||||
|
||||
script.on_event(
|
||||
defines.events.on_chunk_generated,
|
||||
(e: OnChunkGeneratedEvent) => {
|
||||
log(`on_chunk_generated ${e.tick}`)
|
||||
|
||||
let tiles = getTiles(e.surface, e.area)
|
||||
mapTilesUpdateDebounce(e.surface, e.position, tiles, Converters.eventNameString(e.name))
|
||||
handleChunkGeneratedEvent(e)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
export function handleChunkGeneratedEvent(
|
||||
e: OnChunkGeneratedEvent,
|
||||
expirationDurationTicks?: uint,
|
||||
) {
|
||||
let tiles = getTiles(e.surface, e.area)
|
||||
mapTilesUpdateDebounce(
|
||||
e.surface,
|
||||
e.position,
|
||||
tiles,
|
||||
Converters.eventNameString(e.name),
|
||||
undefined,
|
||||
expirationDurationTicks,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
script.on_event(
|
||||
defines.events.on_chunk_charted,
|
||||
(e: OnChunkChartedEvent) => {
|
||||
|
|
@ -111,6 +131,7 @@ script.on_event(
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
script.on_event(
|
||||
defines.events.script_raised_set_tiles,
|
||||
(e: ScriptRaisedSetTilesEvent) => {
|
||||
|
|
@ -146,6 +167,7 @@ function groupTiles(tiles: TileRead[]): Map<MapChunkPosition, TileRead[]> {
|
|||
return mapChunkPositionToTiles
|
||||
}
|
||||
|
||||
|
||||
function convertOldPosition(
|
||||
oldTiles: OldTileAndPosition[],
|
||||
placedTile: LuaTilePrototype,
|
||||
|
|
@ -160,6 +182,7 @@ function convertOldPosition(
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
function onBuildTileEvent(event: OnPlayerBuiltTileEvent | OnRobotBuiltTileEvent) {
|
||||
|
||||
const surface = getSurface(event.surface_index)
|
||||
|
|
@ -199,6 +222,7 @@ function onBuildTileEvent(event: OnPlayerBuiltTileEvent | OnRobotBuiltTileEvent)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
script.on_event(defines.events.on_player_built_tile, (e: OnPlayerBuiltTileEvent) => {
|
||||
log(`on_player_built_tile ${e.tick}`)
|
||||
onBuildTileEvent(e)
|
||||
|
|
@ -246,10 +270,9 @@ script.on_event(
|
|||
key,
|
||||
data => {
|
||||
data.isDeleted = true
|
||||
}
|
||||
},
|
||||
0, // deletion is important - emit ASAP
|
||||
)
|
||||
// deletion is important - emit ASAP
|
||||
EventUpdatesManager.setExpiration(key, 0)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,19 @@
|
|||
import {
|
||||
handleChunkUpdate,
|
||||
handleConsoleChat,
|
||||
handleEntityUpdate,
|
||||
handleSurfaceUpdate,
|
||||
} from "./handlers";
|
||||
import {handleConsoleChat, handleSurfaceUpdate,} from "./handlers";
|
||||
import {Queue} from "../queue/queue";
|
||||
import {isEventType} from "./eventTypeCheck";
|
||||
import {Converters} from "./converters";
|
||||
import KafkatorioSettings from "../settings/KafkatorioSettings";
|
||||
import {handleChunkGeneratedEvent} from "./onMapChunkEventListeners";
|
||||
|
||||
|
||||
script.on_event(
|
||||
defines.events.on_player_mined_entity,
|
||||
(e: OnPlayerMinedEntityEvent) => {
|
||||
let eventName = Converters.eventNameString(e.name)
|
||||
// handlePlayerUpdate(e.tick, eventName, e.player_index)
|
||||
handleEntityUpdate(e.tick, eventName, e.entity)
|
||||
}
|
||||
)
|
||||
// script.on_event(
|
||||
// defines.events.on_player_mined_entity,
|
||||
// (e: OnPlayerMinedEntityEvent) => {
|
||||
// let eventName = Converters.eventNameString(e.name)
|
||||
// // handlePlayerUpdate(e.tick, eventName, e.player_index)
|
||||
// handleEntityUpdate(e.tick, eventName, e.entity)
|
||||
// }
|
||||
// )
|
||||
|
||||
// script.on_event(
|
||||
// defines.events.on_player_joined_game,
|
||||
|
|
@ -47,22 +43,24 @@ script.on_event(
|
|||
// }
|
||||
}
|
||||
|
||||
// if (e.tick % 30 == 0) {
|
||||
// let events: EventData[] = Queue.dequeueValues(1)
|
||||
//
|
||||
// if (events.length > 0) {
|
||||
// log(`[${e.tick}] dequed ${events.length} events, current size: ${Queue.size()}`)
|
||||
//
|
||||
// for (const event of events) {
|
||||
// if (isEventType(event, defines.events.on_chunk_generated)) {
|
||||
// let eName = Converters.eventNameString(event.name)
|
||||
//
|
||||
// log(`[${e.tick}] dequed event ${eName}`)
|
||||
// handleChunkUpdate(e.tick, eName, event.surface.index, event.position, event.area)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (e.tick % 7 == 0) {
|
||||
const events: EventData[] = Queue.dequeueValues(1)
|
||||
|
||||
if (events.length > 0) {
|
||||
log(`[${e.tick}] dequed ${events.length} events, current size: ${Queue.size()}`)
|
||||
|
||||
let i = 100
|
||||
for (const event of events) {
|
||||
if (isEventType(event, defines.events.on_chunk_generated)) {
|
||||
let eName = Converters.eventNameString(event.name)
|
||||
|
||||
log(`[${e.tick}] dequed event ${eName}`)
|
||||
handleChunkGeneratedEvent(event, i)
|
||||
i += 10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue