remove generated lua (it's stable - moved it to temp dir)

This commit is contained in:
Adam 2022-12-19 16:52:49 +01:00
parent 9f2b9cbd5c
commit a99ed5bb85
26 changed files with 0 additions and 4160 deletions

View file

@ -1,15 +0,0 @@
local ____exports = {}
local ____global_2Dinit = require("main.global-init")
local initGlobal = ____global_2Dinit.initGlobal
local ____prototypeUpdates = require("main.events.prototypeUpdates")
local emitPrototypes = ____prototypeUpdates.emitPrototypes
require("main.events.registerEventListeners")
require("main.events.mapChunkUpdates")
require("main.events.playerUpdates")
require("main.events.entityUpdates")
require("main.commands.kafkatorioCommands")
script.on_init(function()
initGlobal(true)
emitPrototypes()
end)
return ____exports

View file

@ -1,82 +0,0 @@
local ____exports = {}
____exports.KafkatorioPacketData = {}
local KafkatorioPacketData = ____exports.KafkatorioPacketData
do
KafkatorioPacketData.Type = Type or ({})
KafkatorioPacketData.Type.ConfigurationUpdate = "kafkatorio.packet.instant.ConfigurationUpdate"
KafkatorioPacketData.Type.ConsoleChatUpdate = "kafkatorio.packet.instant.ConsoleChatUpdate"
KafkatorioPacketData.Type.ConsoleCommandUpdate = "kafkatorio.packet.instant.ConsoleCommandUpdate"
KafkatorioPacketData.Type.PrototypesUpdate = "kafkatorio.packet.instant.PrototypesUpdate"
KafkatorioPacketData.Type.SurfaceUpdate = "kafkatorio.packet.instant.SurfaceUpdate"
KafkatorioPacketData.Type.EntityUpdate = "kafkatorio.packet.keyed.EntityUpdate"
KafkatorioPacketData.Type.MapChunkEntityUpdate = "kafkatorio.packet.keyed.MapChunkEntityUpdate"
KafkatorioPacketData.Type.MapChunkResourceUpdate = "kafkatorio.packet.keyed.MapChunkResourceUpdate"
KafkatorioPacketData.Type.MapChunkTileUpdate = "kafkatorio.packet.keyed.MapChunkTileUpdate"
KafkatorioPacketData.Type.PlayerUpdate = "kafkatorio.packet.keyed.PlayerUpdate"
KafkatorioPacketData.Type.Error = "kafkatorio.packet.KafkatorioPacketData.Error"
end
____exports.FactorioPrototype = {}
local FactorioPrototype = ____exports.FactorioPrototype
do
FactorioPrototype.Type = Type or ({})
FactorioPrototype.Type.Entity = "kafkatorio.prototype.Entity"
FactorioPrototype.Type.MapTile = "kafkatorio.prototype.MapTile"
end
____exports.ChunkSize = ChunkSize or ({})
____exports.ChunkSize.CHUNK_512 = "CHUNK_512"
____exports.ChunkSize.CHUNK_256 = "CHUNK_256"
____exports.ChunkSize.CHUNK_128 = "CHUNK_128"
____exports.ChunkSize.CHUNK_064 = "CHUNK_064"
____exports.ChunkSize.CHUNK_032 = "CHUNK_032"
____exports.MinedProduct = {}
local MinedProduct = ____exports.MinedProduct
do
MinedProduct.Type = Type or ({})
MinedProduct.Type.MinedProductFluid = "kafkatorio.resource.MinedProduct.MinedProductFluid"
MinedProduct.Type.MinedProductItem = "kafkatorio.resource.MinedProduct.MinedProductItem"
end
____exports.FactorioEntityStatus = FactorioEntityStatus or ({})
____exports.FactorioEntityStatus.WORKING = "WORKING"
____exports.FactorioEntityStatus.NORMAL = "NORMAL"
____exports.FactorioEntityStatus.NO_POWER = "NO_POWER"
____exports.FactorioEntityStatus.LOW_POWER = "LOW_POWER"
____exports.FactorioEntityStatus.NO_FUEL = "NO_FUEL"
____exports.FactorioEntityStatus.DISABLED_BY_CONTROL_BEHAVIOR = "DISABLED_BY_CONTROL_BEHAVIOR"
____exports.FactorioEntityStatus.OPENED_BY_CIRCUIT_NETWORK = "OPENED_BY_CIRCUIT_NETWORK"
____exports.FactorioEntityStatus.CLOSED_BY_CIRCUIT_NETWORK = "CLOSED_BY_CIRCUIT_NETWORK"
____exports.FactorioEntityStatus.DISABLED_BY_SCRIPT = "DISABLED_BY_SCRIPT"
____exports.FactorioEntityStatus.MARKED_FOR_DECONSTRUCTION = "MARKED_FOR_DECONSTRUCTION"
____exports.FactorioEntityStatus.NOT_PLUGGED_IN_ELECTRIC_NETWORK = "NOT_PLUGGED_IN_ELECTRIC_NETWORK"
____exports.FactorioEntityStatus.NETWORKS_CONNECTED = "NETWORKS_CONNECTED"
____exports.FactorioEntityStatus.NETWORKS_DISCONNECTED = "NETWORKS_DISCONNECTED"
____exports.FactorioEntityStatus.CHARGING = "CHARGING"
____exports.FactorioEntityStatus.DISCHARGING = "DISCHARGING"
____exports.FactorioEntityStatus.FULLY_CHARGED = "FULLY_CHARGED"
____exports.FactorioEntityStatus.OUT_OF_LOGISTIC_NETWORK = "OUT_OF_LOGISTIC_NETWORK"
____exports.FactorioEntityStatus.NO_RECIPE = "NO_RECIPE"
____exports.FactorioEntityStatus.NO_INGREDIENTS = "NO_INGREDIENTS"
____exports.FactorioEntityStatus.NO_INPUT_FLUID = "NO_INPUT_FLUID"
____exports.FactorioEntityStatus.NO_RESEARCH_IN_PROGRESS = "NO_RESEARCH_IN_PROGRESS"
____exports.FactorioEntityStatus.NO_MINABLE_RESOURCES = "NO_MINABLE_RESOURCES"
____exports.FactorioEntityStatus.LOW_INPUT_FLUID = "LOW_INPUT_FLUID"
____exports.FactorioEntityStatus.FLUID_INGREDIENT_SHORTAGE = "FLUID_INGREDIENT_SHORTAGE"
____exports.FactorioEntityStatus.FULL_OUTPUT = "FULL_OUTPUT"
____exports.FactorioEntityStatus.ITEM_INGREDIENT_SHORTAGE = "ITEM_INGREDIENT_SHORTAGE"
____exports.FactorioEntityStatus.MISSING_REQUIRED_FLUID = "MISSING_REQUIRED_FLUID"
____exports.FactorioEntityStatus.MISSING_SCIENCE_PACKS = "MISSING_SCIENCE_PACKS"
____exports.FactorioEntityStatus.WAITING_FOR_SOURCE_ITEMS = "WAITING_FOR_SOURCE_ITEMS"
____exports.FactorioEntityStatus.WAITING_FOR_SPACE_IN_DESTINATION = "WAITING_FOR_SPACE_IN_DESTINATION"
____exports.FactorioEntityStatus.PREPARING_ROCKET_FOR_LAUNCH = "PREPARING_ROCKET_FOR_LAUNCH"
____exports.FactorioEntityStatus.WAITING_TO_LAUNCH_ROCKET = "WAITING_TO_LAUNCH_ROCKET"
____exports.FactorioEntityStatus.LAUNCHING_ROCKET = "LAUNCHING_ROCKET"
____exports.FactorioEntityStatus.NO_MODULES_TO_TRANSMIT = "NO_MODULES_TO_TRANSMIT"
____exports.FactorioEntityStatus.RECHARGING_AFTER_POWER_OUTAGE = "RECHARGING_AFTER_POWER_OUTAGE"
____exports.FactorioEntityStatus.WAITING_FOR_TARGET_TO_BE_BUILT = "WAITING_FOR_TARGET_TO_BE_BUILT"
____exports.FactorioEntityStatus.WAITING_FOR_TRAIN = "WAITING_FOR_TRAIN"
____exports.FactorioEntityStatus.NO_AMMO = "NO_AMMO"
____exports.FactorioEntityStatus.LOW_TEMPERATURE = "LOW_TEMPERATURE"
____exports.FactorioEntityStatus.DISABLED = "DISABLED"
____exports.FactorioEntityStatus.TURNED_OFF_DURING_DAYTIME = "TURNED_OFF_DURING_DAYTIME"
____exports.FactorioEntityStatus.NOT_CONNECTED_TO_RAIL = "NOT_CONNECTED_TO_RAIL"
____exports.FactorioEntityStatus.CANT_DIVIDE_SEGMENTS = "CANT_DIVIDE_SEGMENTS"
return ____exports

File diff suppressed because it is too large Load diff

View file

@ -1,76 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
local __TS__StringSplit = ____lualib.__TS__StringSplit
local __TS__ParseInt = ____lualib.__TS__ParseInt
local ____exports = {}
local ____global_2Dinit = require("main.global-init")
local initGlobal = ____global_2Dinit.initGlobal
local ____prototypeUpdates = require("main.events.prototypeUpdates")
local emitPrototypes = ____prototypeUpdates.emitPrototypes
local ____EventDataQueue = require("main.emitting.EventDataQueue")
local EventDataQueue = ____EventDataQueue.default
commands.add_command(
"kafkatorio",
"kafkatorio innit bruv",
function(e)
local ____temp_0
if e.player_index ~= nil then
____temp_0 = game.get_player(e.player_index)
else
____temp_0 = nil
end
local player = ____temp_0
if e.parameter == nil then
if player ~= nil then
player.print("no parameter")
end
else
local paramUppercase = string.upper(e.parameter)
if "PROTOTYPES" == paramUppercase then
emitPrototypes()
elseif __TS__StringStartsWith(paramUppercase, "CHUNKS") then
local ____paramUppercase_split_result__1_1 = __TS__StringSplit(paramUppercase, " ")
if ____paramUppercase_split_result__1_1 ~= nil then
____paramUppercase_split_result__1_1 = ____paramUppercase_split_result__1_1[2]
end
local size = ____paramUppercase_split_result__1_1 or nil
local radius = size ~= nil and __TS__ParseInt(size) or 1
if e.player_index ~= nil then
local player = game.players[e.player_index]
local chunkPosition = {
x = math.floor(player.position.x / 32),
y = math.floor(player.position.y / 32)
}
local chunkXMin = chunkPosition.x - radius
local chunkXMax = chunkPosition.x + radius
local chunkYMin = chunkPosition.y - radius
local chunkYMax = chunkPosition.y + radius
local chunkCount = 0
for ____, surface in pairs(game.surfaces) do
for chunk in surface.get_chunks() do
if chunk.x >= chunkXMin and chunk.x <= chunkXMax and (chunk.y >= chunkYMin and chunk.y <= chunkYMax) then
local data = {
name = defines.events.on_chunk_generated,
position = {x = chunk.x, y = chunk.y},
area = chunk.area,
surface = surface,
tick = e.tick
}
EventDataQueue:enqueue(
(tostring(surface.index) .. tostring(chunk.x)) .. tostring(chunk.y),
data,
50
)
chunkCount = chunkCount + 1
end
end
end
player.print(((((((((("enqueued " .. tostring(chunkCount)) .. " chunks from [x:") .. tostring(chunkXMin)) .. ", y:") .. tostring(chunkYMin)) .. "] to [x:") .. tostring(chunkXMax)) .. ", y:") .. tostring(chunkYMax)) .. "]")
end
elseif __TS__StringStartsWith(paramUppercase, "INIT_GLOBAL") then
initGlobal(__TS__StringStartsWith(paramUppercase, "INIT_GLOBAL FORCE"))
end
end
end
)
return ____exports

View file

@ -1,141 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local CacheEntry
local ____KafkatorioSettings = require("main.settings.KafkatorioSettings")
local KafkatorioSettings = ____KafkatorioSettings.default
local ____PacketEmitter = require("main.emitting.PacketEmitter")
local PacketEmitter = ____PacketEmitter.default
____exports.EventUpdatesManager = __TS__Class()
local EventUpdatesManager = ____exports.EventUpdatesManager
EventUpdatesManager.name = "EventUpdatesManager"
function EventUpdatesManager.prototype.____constructor(self)
self:init()
end
function EventUpdatesManager.prototype.init(self, force)
local isAnythingUndefined = global.eventUpdatesManagerCache == nil
log(((("Initialising EventDataCache (force=" .. tostring(force)) .. ", isAnythingUndefined=") .. tostring(isAnythingUndefined)) .. ")...")
if force == true or isAnythingUndefined then
log("Initialising global.cache")
global.eventUpdatesManagerCache = {}
end
log("Finished initialising EventDataCache")
end
function EventUpdatesManager.prototype.throttle(self, key, ____type, mutate, expirationDurationTicks)
self:update(
key,
____type,
mutate,
false,
expirationDurationTicks
)
end
function EventUpdatesManager.prototype.debounce(self, key, ____type, mutate, expirationDurationTicks)
self:update(
key,
____type,
mutate,
true,
expirationDurationTicks
)
end
function EventUpdatesManager.prototype.update(self, key, ____type, mutate, resetLastUpdated, expirationDurationTicks)
local entry = self:getCacheEntry(key, ____type) or ____exports.EventUpdatesManager:createCacheEntry(key, ____type)
mutate(entry.packet)
if resetLastUpdated then
entry.lastUpdatedTick = game.tick
end
if expirationDurationTicks ~= nil then
entry.expirationDurationTicks = expirationDurationTicks
end
if entry.expirationDurationTicks ~= nil and entry.expirationDurationTicks <= 0 then
self:extractAndEmitExpiredPackets()
end
end
function EventUpdatesManager.prototype.setExpiration(self, key, ____type, expirationDurationTicks)
local entry = self:getCacheEntry(key, ____type)
if entry ~= nil then
entry.expirationDurationTicks = expirationDurationTicks
end
end
function EventUpdatesManager.prototype.extractExpired(self)
local countExpired = 0
local countTotal = 0
local expiredData = {}
for key, entry in pairs(global.eventUpdatesManagerCache) do
countTotal = countTotal + 1
if self:isExpired(entry) then
countExpired = countExpired + 1
expiredData[#expiredData + 1] = entry.packet
global.eventUpdatesManagerCache[key] = nil
end
end
local hasExpiredItems = countExpired > 0
local hasAnyItem = countTotal > 0
if hasExpiredItems or game.tick % 30 == 0 and hasAnyItem then
log((("[extractExpired] expired items: " .. tostring(countExpired)) .. ", total: ") .. tostring(countTotal))
end
return expiredData
end
function EventUpdatesManager.prototype.extractAndEmitExpiredPackets(self)
local cachedEvents = self:extractExpired()
if #cachedEvents > 0 then
log((("[EventDataCache] emitting " .. tostring(#cachedEvents)) .. " events on tick ") .. tostring(game.tick))
for ____, event in ipairs(cachedEvents) do
PacketEmitter:emitKeyedPacket(event)
end
end
return #cachedEvents
end
function EventUpdatesManager.prototype.getCacheEntry(self, key, ____type)
local hash = ____exports.EventUpdatesManager:hashKey(key)
if not (global.eventUpdatesManagerCache[hash] ~= nil) then
return nil
end
local value = global.eventUpdatesManagerCache[hash]
if self:isEntryInstanceOf(value, ____type) then
return value
else
return nil
end
end
function EventUpdatesManager.createCacheEntry(self, key, ____type)
local data = {type = ____type, key = key}
local entry = __TS__New(CacheEntry, data)
local hash = ____exports.EventUpdatesManager:hashKey(key)
global.eventUpdatesManagerCache[hash] = entry
return entry
end
function EventUpdatesManager.prototype.isExpired(self, entry)
local expiryDuration = entry.expirationDurationTicks or KafkatorioSettings:getEventCacheExpirationTicks(entry.packet)
if expiryDuration == nil then
return true
else
return game.tick - entry.lastUpdatedTick > expiryDuration
end
end
function EventUpdatesManager.prototype.isEntryInstanceOf(self, entry, ____type)
local ____self_isDataInstanceOf_2 = self.isDataInstanceOf
local ____entry_packet_0 = entry
if ____entry_packet_0 ~= nil then
____entry_packet_0 = ____entry_packet_0.packet
end
return ____self_isDataInstanceOf_2(self, ____entry_packet_0, ____type)
end
function EventUpdatesManager.prototype.isDataInstanceOf(self, packet, ____type)
return packet ~= nil and packet.type == ____type
end
function EventUpdatesManager.hashKey(self, key)
return game.encode_string(game.table_to_json(key))
end
local EventUpdates = __TS__New(____exports.EventUpdatesManager)
____exports.default = EventUpdates
CacheEntry = __TS__Class()
CacheEntry.name = "CacheEntry"
function CacheEntry.prototype.____constructor(self, packet, expirationDurationTicks)
self.lastUpdatedTick = game.tick
self.packet = packet
self.expirationDurationTicks = expirationDurationTicks
end
return ____exports

View file

@ -1,87 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local Node
____exports.EventDataQueueManager = __TS__Class()
local EventDataQueueManager = ____exports.EventDataQueueManager
EventDataQueueManager.name = "EventDataQueueManager"
function EventDataQueueManager.prototype.____constructor(self)
end
function EventDataQueueManager.init(self, force)
local isAnythingUndefined = global.store == nil or global.size == nil or global.head == nil or global.tail == nil
log(((("Initialising EventDataQueueManager globals (force=" .. tostring(force)) .. ", isAnythingUndefined=") .. tostring(isAnythingUndefined)) .. ")")
if force == true or isAnythingUndefined then
global.store = {}
global.head = nil
global.tail = nil
global.size = 0
end
log("Finished initialising EventDataQueueManager")
end
function EventDataQueueManager.prototype.size(self)
return global.size
end
function EventDataQueueManager.prototype.enqueue(self, key, event, weight)
if weight == nil then
weight = 1
end
if global.store[key] ~= nil then
local node = __TS__New(Node, key, weight)
if global.head == nil then
global.head = node
end
if global.tail ~= nil then
global.tail.next = node
end
global.tail = node
global.size = global.size + 1
end
global.store[key] = event
end
function EventDataQueueManager.prototype.dequeue(self)
if global.head == nil then
return nil
else
local weight = global.head.weight
local storeKey = global.head.storeKey
global.head = global.head.next
global.size = global.size - 1
local storedPacket = global.store[storeKey]
global.store[storeKey] = nil
if storedPacket == nil then
return nil
else
return {value = storedPacket, weight = weight}
end
end
end
function EventDataQueueManager.prototype.dequeueValues(self, targetWeight)
if targetWeight == nil then
targetWeight = 50
end
local values = {}
local weight = 0
repeat
do
local packet = self:dequeue()
if packet == nil then
break
else
weight = weight + packet.weight
values[#values + 1] = packet.value
end
end
until not (weight <= targetWeight)
return values
end
local EventDataQueue = __TS__New(____exports.EventDataQueueManager)
____exports.default = EventDataQueue
Node = __TS__Class()
Node.name = "Node"
function Node.prototype.____constructor(self, storeKey, weight)
self.next = nil
self.storeKey = storeKey
self.weight = weight
end
return ____exports

View file

@ -1,48 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
local __TS__New = ____lualib.__TS__New
local ____exports = {}
--- Simple ordered queue for {@link KafkatorioPacketData}.
--
-- Implemented so printing multiple packets won't flood the output log, causing messages to be
-- missed or garbled.
____exports.KafkatorioPacketQueueManager = __TS__Class()
local KafkatorioPacketQueueManager = ____exports.KafkatorioPacketQueueManager
KafkatorioPacketQueueManager.name = "KafkatorioPacketQueueManager"
function KafkatorioPacketQueueManager.prototype.____constructor(self)
self.size = 0
self.first = nil
self.last = nil
end
__TS__SetDescriptor(
KafkatorioPacketQueueManager.prototype,
"length",
{get = function(self)
return self.size
end},
true
)
function KafkatorioPacketQueueManager.prototype.enqueue(self, packet)
local last = self.last
self.last = {value = packet}
if last ~= nil then
last.next = self.last
end
if self.first == nil then
self.first = self.last
end
self.size = self.size + 1
end
function KafkatorioPacketQueueManager.prototype.dequeue(self)
local first = self.first
if first == nil then
return nil
end
self.first = first.next or nil
self.size = self.size - 1
return first.value
end
local KafkatorioPacketQueue = __TS__New(____exports.KafkatorioPacketQueueManager)
____exports.default = KafkatorioPacketQueue
return ____exports

View file

@ -1,33 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__StringTrim = ____lualib.__TS__StringTrim
local __TS__New = ____lualib.__TS__New
local ____exports = {}
____exports.KafkatorioPacketEmitter = __TS__Class()
local KafkatorioPacketEmitter = ____exports.KafkatorioPacketEmitter
KafkatorioPacketEmitter.name = "KafkatorioPacketEmitter"
function KafkatorioPacketEmitter.prototype.____constructor(self)
end
function KafkatorioPacketEmitter.prototype.emitInstantPacket(self, data)
____exports.KafkatorioPacketEmitter:emitPacket({data = data, modVersion = global.MOD_VERSION, tick = game.tick})
end
function KafkatorioPacketEmitter.prototype.emitKeyedPacket(self, data)
____exports.KafkatorioPacketEmitter:emitPacket({data = data, modVersion = global.MOD_VERSION, tick = game.tick})
end
function KafkatorioPacketEmitter.emitPacket(self, packet)
local data = game.table_to_json(packet)
if #__TS__StringTrim(data) <= 0 then
print("[error] table_to_json returned empty string for packet:" .. tostring(packet))
return
end
local encodedData = game.encode_string(data)
if encodedData == nil or #__TS__StringTrim(encodedData) <= 0 then
print("[error] could not encode packet")
print("KafkatorioPacket:::" .. data)
else
print("KafkatorioPacket:::encoded:" .. encodedData)
end
end
local PacketEmitter = __TS__New(____exports.KafkatorioPacketEmitter)
____exports.default = PacketEmitter
return ____exports

View file

@ -1,13 +0,0 @@
local ____exports = {}
local ____global_2Dinit = require("main.global-init")
local initGlobal = ____global_2Dinit.initGlobal
local ____prototypeUpdates = require("main.events.prototypeUpdates")
local emitPrototypes = ____prototypeUpdates.emitPrototypes
local ____ConfigurationUpdateHandler = require("main.events.handlers.ConfigurationUpdateHandler")
local ConfigurationUpdates = ____ConfigurationUpdateHandler.default
script.on_configuration_changed(function(data)
initGlobal(true)
ConfigurationUpdates:emitConfigurationUpdate(data)
emitPrototypes()
end)
return ____exports

View file

@ -1,20 +0,0 @@
local ____exports = {}
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local ____KafkatorioPacketQueue = require("main.emitting.KafkatorioPacketQueue")
local KafkatorioPacketQueue = ____KafkatorioPacketQueue.default
script.on_event(
defines.events.on_console_chat,
function(event)
local update = {type = KafkatorioPacketData.Type.ConsoleChatUpdate, authorPlayerIndex = event.player_index or nil, content = event.message}
KafkatorioPacketQueue:enqueue(update)
end
)
script.on_event(
defines.events.on_console_command,
function(event)
local update = {type = KafkatorioPacketData.Type.ConsoleCommandUpdate, authorPlayerIndex = event.player_index or nil, command = event.command, parameters = event.parameters}
KafkatorioPacketQueue:enqueue(update)
end
)
return ____exports

View file

@ -1,162 +0,0 @@
local ____exports = {}
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local ChunkSize = ____kafkatorio_2Dschema.ChunkSize
local FactorioEntityStatus = ____kafkatorio_2Dschema.FactorioEntityStatus
local MinedProduct = ____kafkatorio_2Dschema.MinedProduct
____exports.Converters = {}
local Converters = ____exports.Converters
do
local EntityStatusRecord
function Converters.prototypeId(____type, name)
return (____type .. "/") .. name
end
local floor = math.floor
local mapEventIdToName = {}
for eventName, eventId in pairs(defines.events) do
mapEventIdToName[eventId] = eventName
end
function Converters.eventNameString(event)
return mapEventIdToName[event]
end
function Converters.mapColour(color)
return {color.r or 0, color.g or 0, color.b or 0, color.a or 0}
end
function Converters.convertPlacedTiles(placedTile, oldTiles)
local converted = {}
for ____, tile in ipairs(oldTiles) do
converted[#converted + 1] = {position = {x = tile.position.x, y = tile.position.y}, name = placedTile.name}
end
return converted
end
function Converters.convertRemovedTiles(surface, oldTiles)
local converted = {}
for ____, tile in ipairs(oldTiles) do
converted[#converted + 1] = surface.get_tile(tile.position.x, tile.position.y)
end
return converted
end
function Converters.convertCollisionMaskToNames(cm)
local masks = {}
for name in pairs(cm) do
masks[#masks + 1] = name
end
return masks
end
local function convertEntityStatus(status)
if status == nil then
return nil
else
return EntityStatusRecord[status]
end
end
function Converters.prototypeIdEntity(entity)
return Converters.prototypeId(entity.type, entity.name)
end
function Converters.tilePositionToChunkPosition(mapPosition)
return {
floor(mapPosition.x / 32),
floor(mapPosition.y / 32),
ChunkSize.CHUNK_032
}
end
function Converters.mapPositionToChunkPosition(mapPosition)
return {
floor(mapPosition.x / 32),
floor(mapPosition.y / 32),
ChunkSize.CHUNK_032
}
end
function Converters.entityPosition(position)
return {position.x, position.y}
end
function Converters.chunkPosition(position)
return {position.x, position.y, ChunkSize.CHUNK_032}
end
function Converters.entityStatus(status)
if status == nil then
return nil
else
return EntityStatusRecord[status]
end
end
function Converters.miningProperties(properties)
local products = {}
if properties.products ~= nil then
for ____, product in ipairs(properties.products) do
if product.type == "fluid" then
products[#products + 1] = {
type = MinedProduct.Type.MinedProductFluid,
amount = product.amount,
resultProtoId = ____exports.Converters.prototypeId(product.type, product.name)
}
end
if product.type == "item" then
products[#products + 1] = {
type = MinedProduct.Type.MinedProductItem,
amount = product.amount,
resultProtoId = ____exports.Converters.prototypeId(product.type, product.name)
}
end
end
end
return {canBeMined = properties.minable, products = products}
end
function Converters.playerOnlineInfo(player, data)
data.lastOnline = player.last_online
data.onlineTime = player.online_time
data.afkTime = player.afk_time
data.isConnected = player.connected
end
function Converters.collisionBox(collision_box)
return {
leftTop = ____exports.Converters.entityPosition(collision_box.left_top),
rightBottom = ____exports.Converters.entityPosition(collision_box.right_bottom)
}
end
EntityStatusRecord = {
[defines.entity_status.cant_divide_segments] = FactorioEntityStatus.CANT_DIVIDE_SEGMENTS,
[defines.entity_status.charging] = FactorioEntityStatus.CHARGING,
[defines.entity_status.closed_by_circuit_network] = FactorioEntityStatus.CLOSED_BY_CIRCUIT_NETWORK,
[defines.entity_status.disabled] = FactorioEntityStatus.DISABLED,
[defines.entity_status.disabled_by_control_behavior] = FactorioEntityStatus.DISABLED_BY_CONTROL_BEHAVIOR,
[defines.entity_status.disabled_by_script] = FactorioEntityStatus.DISABLED_BY_SCRIPT,
[defines.entity_status.discharging] = FactorioEntityStatus.DISCHARGING,
[defines.entity_status.fluid_ingredient_shortage] = FactorioEntityStatus.FLUID_INGREDIENT_SHORTAGE,
[defines.entity_status.fully_charged] = FactorioEntityStatus.FULLY_CHARGED,
[defines.entity_status.full_output] = FactorioEntityStatus.FULL_OUTPUT,
[defines.entity_status.item_ingredient_shortage] = FactorioEntityStatus.ITEM_INGREDIENT_SHORTAGE,
[defines.entity_status.launching_rocket] = FactorioEntityStatus.LAUNCHING_ROCKET,
[defines.entity_status.low_input_fluid] = FactorioEntityStatus.LOW_INPUT_FLUID,
[defines.entity_status.low_power] = FactorioEntityStatus.LOW_POWER,
[defines.entity_status.low_temperature] = FactorioEntityStatus.LOW_TEMPERATURE,
[defines.entity_status.marked_for_deconstruction] = FactorioEntityStatus.MARKED_FOR_DECONSTRUCTION,
[defines.entity_status.missing_required_fluid] = FactorioEntityStatus.MISSING_REQUIRED_FLUID,
[defines.entity_status.missing_science_packs] = FactorioEntityStatus.MISSING_SCIENCE_PACKS,
[defines.entity_status.networks_connected] = FactorioEntityStatus.NETWORKS_CONNECTED,
[defines.entity_status.networks_disconnected] = FactorioEntityStatus.NETWORKS_DISCONNECTED,
[defines.entity_status.normal] = FactorioEntityStatus.NORMAL,
[defines.entity_status.not_connected_to_rail] = FactorioEntityStatus.NOT_CONNECTED_TO_RAIL,
[defines.entity_status.not_plugged_in_electric_network] = FactorioEntityStatus.NOT_PLUGGED_IN_ELECTRIC_NETWORK,
[defines.entity_status.no_ammo] = FactorioEntityStatus.NO_AMMO,
[defines.entity_status.no_fuel] = FactorioEntityStatus.NO_FUEL,
[defines.entity_status.no_ingredients] = FactorioEntityStatus.NO_INGREDIENTS,
[defines.entity_status.no_input_fluid] = FactorioEntityStatus.NO_INPUT_FLUID,
[defines.entity_status.no_minable_resources] = FactorioEntityStatus.NO_MINABLE_RESOURCES,
[defines.entity_status.no_modules_to_transmit] = FactorioEntityStatus.NO_MODULES_TO_TRANSMIT,
[defines.entity_status.no_power] = FactorioEntityStatus.NO_POWER,
[defines.entity_status.no_recipe] = FactorioEntityStatus.NO_RECIPE,
[defines.entity_status.no_research_in_progress] = FactorioEntityStatus.NO_RESEARCH_IN_PROGRESS,
[defines.entity_status.opened_by_circuit_network] = FactorioEntityStatus.OPENED_BY_CIRCUIT_NETWORK,
[defines.entity_status.out_of_logistic_network] = FactorioEntityStatus.OUT_OF_LOGISTIC_NETWORK,
[defines.entity_status.preparing_rocket_for_launch] = FactorioEntityStatus.PREPARING_ROCKET_FOR_LAUNCH,
[defines.entity_status.recharging_after_power_outage] = FactorioEntityStatus.RECHARGING_AFTER_POWER_OUTAGE,
[defines.entity_status.turned_off_during_daytime] = FactorioEntityStatus.TURNED_OFF_DURING_DAYTIME,
[defines.entity_status.waiting_for_source_items] = FactorioEntityStatus.WAITING_FOR_SOURCE_ITEMS,
[defines.entity_status.waiting_for_space_in_destination] = FactorioEntityStatus.WAITING_FOR_SPACE_IN_DESTINATION,
[defines.entity_status.waiting_for_target_to_be_built] = FactorioEntityStatus.WAITING_FOR_TARGET_TO_BE_BUILT,
[defines.entity_status.waiting_for_train] = FactorioEntityStatus.WAITING_FOR_TRAIN,
[defines.entity_status.waiting_to_launch_rocket] = FactorioEntityStatus.WAITING_TO_LAUNCH_ROCKET,
[defines.entity_status.working] = FactorioEntityStatus.WORKING
}
end
return ____exports

View file

@ -1,32 +0,0 @@
local ____exports = {}
local ____EntityUpdateHandler = require("main.events.handlers.EntityUpdateHandler")
local EntityUpdates = ____EntityUpdateHandler.default
script.on_event(
defines.events.on_built_entity,
function(e)
log("on_built_entity " .. tostring(e.tick))
EntityUpdates:handleBuiltEntityEvent(e)
end
)
script.on_event(
defines.events.on_robot_built_entity,
function(e)
log("on_robot_built_entity " .. tostring(e.tick))
EntityUpdates:handleBuiltEntityEvent(e)
end
)
script.on_event(
defines.events.on_player_mined_entity,
function(e)
log("on_player_mined_entity " .. tostring(e.tick))
EntityUpdates:handleMinedEntityEvent(e)
end
)
script.on_event(
defines.events.on_robot_mined_entity,
function(e)
log("on_robot_mined_entity " .. tostring(e.tick))
EntityUpdates:handleMinedEntityEvent(e)
end
)
return ____exports

View file

@ -1,6 +0,0 @@
local ____exports = {}
function ____exports.isEventType(eventData, ____type)
local id = eventData.name
return id == ____type
end
return ____exports

View file

@ -1,62 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
local __TS__ArrayConcat = ____lualib.__TS__ArrayConcat
local Set = ____lualib.Set
local __TS__New = ____lualib.__TS__New
local __TS__Spread = ____lualib.__TS__Spread
local __TS__ArrayMap = ____lualib.__TS__ArrayMap
local ____exports = {}
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local ____KafkatorioPacketQueue = require("main.emitting.KafkatorioPacketQueue")
local KafkatorioPacketQueue = ____KafkatorioPacketQueue.default
____exports.ConfigurationUpdateHandler = __TS__Class()
local ConfigurationUpdateHandler = ____exports.ConfigurationUpdateHandler
ConfigurationUpdateHandler.name = "ConfigurationUpdateHandler"
function ConfigurationUpdateHandler.prototype.____constructor(self)
end
function ConfigurationUpdateHandler.prototype.emitConfigurationUpdate(self, changeData)
local configUpdateData = {
type = KafkatorioPacketData.Type.ConfigurationUpdate,
migrationApplied = changeData.migration_applied,
modStartupSettingsChange = changeData.mod_startup_settings_changed,
allMods = ____exports.ConfigurationUpdateHandler:allMods(changeData),
factorioData = ____exports.ConfigurationUpdateHandler:factorioData(changeData)
}
KafkatorioPacketQueue:enqueue(configUpdateData)
end
function ConfigurationUpdateHandler.factorioData(self, changeData)
return {oldVersion = changeData.old_version or nil, newVersion = changeData.new_version or nil}
end
function ConfigurationUpdateHandler.allMods(self, e)
local namesOfChangedMods = __TS__ObjectKeys(e.mod_changes)
local namesOfCurrentMods = __TS__ObjectKeys(script.active_mods)
local modNames = {__TS__Spread(__TS__New(
Set,
__TS__ArrayConcat(namesOfChangedMods, namesOfCurrentMods)
))}
return __TS__ArrayMap(
modNames,
function(____, modName)
local ____script_active_mods_modName_2 = script.active_mods[modName]
if ____script_active_mods_modName_2 == nil then
local ____e_mod_changes_modName_new_version_0 = e.mod_changes[modName]
if ____e_mod_changes_modName_new_version_0 ~= nil then
____e_mod_changes_modName_new_version_0 = ____e_mod_changes_modName_new_version_0.new_version
end
____script_active_mods_modName_2 = ____e_mod_changes_modName_new_version_0
end
local currentVer = ____script_active_mods_modName_2 or nil
local ____e_mod_changes_modName_old_version_3 = e.mod_changes[modName]
if ____e_mod_changes_modName_old_version_3 ~= nil then
____e_mod_changes_modName_old_version_3 = ____e_mod_changes_modName_old_version_3.old_version
end
local previousVer = ____e_mod_changes_modName_old_version_3 or nil
return {modName = modName, currentVersion = currentVer, previousVersion = previousVer}
end
)
end
local ConfigurationUpdates = __TS__New(____exports.ConfigurationUpdateHandler)
____exports.default = ConfigurationUpdates
return ____exports

View file

@ -1,176 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local ____converters = require("main.events.converters")
local Converters = ____converters.Converters
local ____EventDataCache = require("main.emitting.EventDataCache")
local EventDataCache = ____EventDataCache.default
____exports.EntityUpdatesHandler = __TS__Class()
local EntityUpdatesHandler = ____exports.EntityUpdatesHandler
EntityUpdatesHandler.name = "EntityUpdatesHandler"
function EntityUpdatesHandler.prototype.____constructor(self)
end
function EntityUpdatesHandler.prototype.handleMinedTileEvent(self, event)
local surface = game.get_surface(event.surface_index)
if surface == nil then
return
end
local tilesByChunk = {}
for ____, tile in ipairs(event.tiles) do
local chunkPosition = Converters.tilePositionToChunkPosition(tile.position)
if not (tilesByChunk[chunkPosition] ~= nil) then
tilesByChunk[chunkPosition] = {}
end
local tiles = tilesByChunk[chunkPosition]
tiles[#tiles + 1] = tile
tilesByChunk[chunkPosition] = tiles
end
for chunkPos, tiles in pairs(tilesByChunk) do
local entities = {}
for ____, tile in ipairs(tiles) do
local tileEntities = ____exports.EntityUpdatesHandler:getTileResourceEntities(surface, tile.position)
for ____, resource in ipairs(tileEntities) do
entities[#entities + 1] = resource
end
end
____exports.EntityUpdatesHandler:throttleResourcesUpdate(
Converters.eventNameString(event.name),
event.tick,
event.surface_index,
chunkPos,
entities
)
end
end
function EntityUpdatesHandler.prototype.handleMinedEntityEvent(self, event)
____exports.EntityUpdatesHandler:throttleEntityUpdate(event, event.entity)
end
function EntityUpdatesHandler.prototype.handleBuiltEntityEvent(self, event)
____exports.EntityUpdatesHandler:throttleEntityUpdate(event, event.created_entity)
end
function EntityUpdatesHandler.prototype.handleChunkGeneratedEvent(self, event)
local entities = ____exports.EntityUpdatesHandler:getAreaResourceEntities(event.surface, event.area)
____exports.EntityUpdatesHandler:throttleResourcesUpdate(
Converters.eventNameString(event.name),
event.tick,
event.surface.index,
Converters.chunkPosition(event.position),
entities
)
end
function EntityUpdatesHandler.throttleEntityUpdate(self, event, entity)
if entity.unit_number == nil then
return
end
local eventName = Converters.eventNameString(event.name)
local entityUpdateKey = {
protoId = Converters.prototypeIdEntity(entity),
surfaceIndex = entity.surface.index,
chunkPosition = Converters.mapPositionToChunkPosition(entity.position)
}
local ____entity_unit_number_2 = entity.unit_number
local ____entity_graphics_variation_3 = entity.graphics_variation
local ____entity_health_4 = entity.health
local ____entity_active_5 = entity.active
local ____entity_rotatable_6 = entity.rotatable
local ____entity_last_user_index_0 = entity.last_user
if ____entity_last_user_index_0 ~= nil then
____entity_last_user_index_0 = ____entity_last_user_index_0.index
end
local entityUpdate = {
unitNumber = ____entity_unit_number_2,
graphicsVariation = ____entity_graphics_variation_3,
health = ____entity_health_4,
isActive = ____entity_active_5,
isRotatable = ____entity_rotatable_6,
lastUser = ____entity_last_user_index_0,
status = Converters.entityStatus(entity.status)
}
EventDataCache:throttle(
entityUpdateKey,
KafkatorioPacketData.Type.MapChunkEntityUpdate,
function(data)
if data.events == nil then
data.events = {}
end
local ____data_events_7, ____eventName_8 = data.events, eventName
if ____data_events_7[____eventName_8] == nil then
____data_events_7[____eventName_8] = {}
end
local ____data_events_eventName_9 = data.events[eventName]
____data_events_eventName_9[#____data_events_eventName_9 + 1] = event.tick
if data.entitiesXY == nil then
data.entitiesXY = {}
end
local ____data_entitiesXY_10, ____tostring_result_11 = data.entitiesXY, tostring(entity.position.x)
if ____data_entitiesXY_10[____tostring_result_11] == nil then
____data_entitiesXY_10[____tostring_result_11] = {}
end
local ____data_entitiesXY_tostring_result_12, ____tostring_result_13 = data.entitiesXY[tostring(entity.position.x)], tostring(entity.position.y)
if ____data_entitiesXY_tostring_result_12[____tostring_result_13] == nil then
____data_entitiesXY_tostring_result_12[____tostring_result_13] = entityUpdate
end
end
)
end
function EntityUpdatesHandler.throttleResourcesUpdate(self, eventName, eventTick, surfaceIndex, chunkPosition, entities)
local entitiesByProtoId = {}
for ____, entity in ipairs(entities) do
local protoId = Converters.prototypeIdEntity(entity)
if entitiesByProtoId[protoId] == nil then
entitiesByProtoId[protoId] = {}
end
local ____entitiesByProtoId_protoId_14 = entitiesByProtoId[protoId]
____entitiesByProtoId_protoId_14[#____entitiesByProtoId_protoId_14 + 1] = entity
end
for protoId, resourceEntities in pairs(entitiesByProtoId) do
local entityUpdateKey = {protoId = protoId, surfaceIndex = surfaceIndex, chunkPosition = chunkPosition}
EventDataCache:throttle(
entityUpdateKey,
KafkatorioPacketData.Type.MapChunkResourceUpdate,
function(data)
if data.events == nil then
data.events = {}
end
local ____data_events_15, ____eventName_16 = data.events, eventName
if ____data_events_15[____eventName_16] == nil then
____data_events_15[____eventName_16] = {}
end
local ____data_events_eventName_17 = data.events[eventName]
____data_events_eventName_17[#____data_events_eventName_17 + 1] = eventTick
for ____, entity in ipairs(resourceEntities) do
if data.amounts == nil then
data.amounts = {}
end
local ____data_amounts_18, ____tostring_result_19 = data.amounts, tostring(entity.position.x)
if ____data_amounts_18[____tostring_result_19] == nil then
____data_amounts_18[____tostring_result_19] = {}
end
data.amounts[tostring(entity.position.x)][tostring(entity.position.y)] = entity.amount
if entity.initial_amount ~= nil then
if data.initialAmounts == nil then
data.initialAmounts = {}
end
local ____data_initialAmounts_20, ____tostring_result_21 = data.initialAmounts, tostring(entity.position.x)
if ____data_initialAmounts_20[____tostring_result_21] == nil then
____data_initialAmounts_20[____tostring_result_21] = {}
end
data.initialAmounts[tostring(entity.position.x)][tostring(entity.position.y)] = entity.initial_amount
end
end
end
)
end
end
function EntityUpdatesHandler.getTileResourceEntities(self, surface, mapPosition)
return surface.find_entities_filtered({position = mapPosition, collision_mask = "resource-layer"})
end
function EntityUpdatesHandler.getAreaResourceEntities(self, surface, area)
return surface.find_entities_filtered({area = area, collision_mask = "resource-layer"})
end
local EntityUpdates = __TS__New(____exports.EntityUpdatesHandler)
____exports.default = EntityUpdates
return ____exports

View file

@ -1,208 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local Map = ____lualib.Map
local __TS__Iterator = ____lualib.__TS__Iterator
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local ____converters = require("main.events.converters")
local Converters = ____converters.Converters
local ____eventTypeCheck = require("main.events.eventTypeCheck")
local isEventType = ____eventTypeCheck.isEventType
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local ____EventDataCache = require("main.emitting.EventDataCache")
local EventUpdates = ____EventDataCache.default
local MapChunkUpdateHandler = __TS__Class()
MapChunkUpdateHandler.name = "MapChunkUpdateHandler"
function MapChunkUpdateHandler.prototype.____constructor(self)
end
function MapChunkUpdateHandler.prototype.handleChunkGeneratedEvent(self, event, expirationDurationTicks)
local tiles = event.surface.find_tiles_filtered({area = event.area})
MapChunkUpdateHandler:mapTilesUpdateDebounce(
event.surface,
Converters.chunkPosition(event.position),
tiles,
event,
nil,
expirationDurationTicks
)
end
function MapChunkUpdateHandler.prototype.handleBuiltTileEvent(self, event)
local surface = game.get_surface(event.surface_index)
if surface == nil then
local eventName = Converters.eventNameString(event.name)
log("[handleBuiltTileEvent] undefined surface " .. eventName)
return
end
local tiles = Converters.convertPlacedTiles(event.tile, event.tiles)
local groupedTiles = MapChunkUpdateHandler:groupTiles(tiles)
for ____, ____value in __TS__Iterator(groupedTiles) do
local chunkPos = ____value[1]
local tiles = ____value[2]
MapChunkUpdateHandler:mapTilesUpdateDebounce(
surface,
chunkPos,
tiles,
event,
function(data)
if isEventType(event, defines.events.on_player_built_tile) then
data.player = event.player_index
return
end
if isEventType(event, defines.events.on_robot_built_tile) then
local ____data_2 = data
local ____event_robot_unit_number_0 = event.robot
if ____event_robot_unit_number_0 ~= nil then
____event_robot_unit_number_0 = ____event_robot_unit_number_0.unit_number
end
____data_2.robot = {
unitNumber = ____event_robot_unit_number_0 or nil,
protoId = Converters.prototypeId(event.robot.type, event.robot.name)
}
return
end
local exhaustiveCheck = event
end
)
end
end
function MapChunkUpdateHandler.prototype.handleMinedTileEvent(self, event)
local surface = game.get_surface(event.surface_index)
if surface == nil then
local eventName = Converters.eventNameString(event.name)
log("[handleMinedTileEvent] undefined surface " .. eventName)
return
end
local tiles = Converters.convertRemovedTiles(surface, event.tiles)
local groupedTiles = MapChunkUpdateHandler:groupTiles(tiles)
for ____, ____value in __TS__Iterator(groupedTiles) do
local chunkPos = ____value[1]
local tiles = ____value[2]
MapChunkUpdateHandler:mapTilesUpdateDebounce(
surface,
chunkPos,
tiles,
event,
function(data)
if isEventType(event, defines.events.on_player_mined_tile) then
data.player = event.player_index
return
end
if isEventType(event, defines.events.on_robot_mined_tile) then
local ____data_5 = data
local ____event_robot_unit_number_3 = event.robot
if ____event_robot_unit_number_3 ~= nil then
____event_robot_unit_number_3 = ____event_robot_unit_number_3.unit_number
end
____data_5.robot = {
unitNumber = ____event_robot_unit_number_3 or nil,
protoId = Converters.prototypeId(event.robot.type, event.robot.name)
}
return
end
local exhaustiveCheck = event
end
)
end
end
function MapChunkUpdateHandler.prototype.handleScriptSetTilesEvent(self, event)
local surface = game.get_surface(event.surface_index)
if surface == nil then
return
end
local groupedTiles = MapChunkUpdateHandler:groupTiles(event.tiles)
for ____, ____value in __TS__Iterator(groupedTiles) do
local chunkPos = ____value[1]
local tiles = ____value[2]
MapChunkUpdateHandler:mapTilesUpdateDebounce(surface, chunkPos, tiles, event)
end
end
function MapChunkUpdateHandler.prototype.handlePreChunkDeleted(self, event)
local surface = game.get_surface(event.surface_index)
if surface == nil then
return
end
for ____, position in ipairs(event.positions) do
local key = {
surfaceIndex = surface.index,
chunkPosition = Converters.chunkPosition(position)
}
EventUpdates:debounce(
key,
KafkatorioPacketData.Type.MapChunkTileUpdate,
function(data)
data.isDeleted = true
return true
end,
0
)
end
end
function MapChunkUpdateHandler.mapTilesUpdateDebounce(self, surface, chunkPosition, tiles, event, updater, expirationDurationTicks)
if surface == nil then
return
end
local eventName = Converters.eventNameString(event.name)
local key = {surfaceIndex = surface.index, chunkPosition = chunkPosition}
EventUpdates:debounce(
key,
KafkatorioPacketData.Type.MapChunkTileUpdate,
function(data)
if data.tileDictionary == nil then
data.tileDictionary = {tilesXY = {}, protos = {}}
end
local protosCount = table_size(data.tileDictionary.protos)
for ____, tile in ipairs(tiles) do
local protoId = Converters.prototypeId("tile", tile.name)
if data.tileDictionary.protos[protoId] == nil then
end
local ____data_tileDictionary_protos_7, ____protoId_8 = data.tileDictionary.protos, protoId
if ____data_tileDictionary_protos_7[____protoId_8] == nil then
local ____protosCount_6 = protosCount
protosCount = ____protosCount_6 + 1
____data_tileDictionary_protos_7[____protoId_8] = ____protosCount_6
end
local protoKey = data.tileDictionary.protos[protoId]
local xString = tostring(tile.position.x)
local yString = tostring(tile.position.y)
local ____data_tileDictionary_tilesXY_9, ____xString_10 = data.tileDictionary.tilesXY, xString
if ____data_tileDictionary_tilesXY_9[____xString_10] == nil then
____data_tileDictionary_tilesXY_9[____xString_10] = {}
end
data.tileDictionary.tilesXY[xString][yString] = protoKey
end
if data.events == nil then
data.events = {}
end
local ____data_events_11, ____eventName_12 = data.events, eventName
if ____data_events_11[____eventName_12] == nil then
____data_events_11[____eventName_12] = {}
end
local ____data_events_eventName_13 = data.events[eventName]
____data_events_eventName_13[#____data_events_eventName_13 + 1] = event.tick
if updater ~= nil then
updater(data)
end
end,
expirationDurationTicks
)
end
function MapChunkUpdateHandler.groupTiles(self, tiles)
local mapChunkPositionToTiles = __TS__New(Map)
for ____, tile in ipairs(tiles) do
local chunkPosition = Converters.tilePositionToChunkPosition(tile.position)
if not mapChunkPositionToTiles:has(chunkPosition) then
mapChunkPositionToTiles:set(chunkPosition, {})
end
local ____mapChunkPositionToTiles_get_result_push_result_14 = mapChunkPositionToTiles:get(chunkPosition)
if ____mapChunkPositionToTiles_get_result_push_result_14 ~= nil then
local ____temp_15 = mapChunkPositionToTiles:get(chunkPosition)
____temp_15[#____temp_15 + 1] = tile
____mapChunkPositionToTiles_get_result_push_result_14 = nil
end
end
return mapChunkPositionToTiles
end
local MapChunkUpdate = __TS__New(MapChunkUpdateHandler)
____exports.default = MapChunkUpdate
return ____exports

View file

@ -1,60 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__New = ____lualib.__TS__New
local ____exports = {}
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local ____converters = require("main.events.converters")
local Converters = ____converters.Converters
local ____EventDataCache = require("main.emitting.EventDataCache")
local EventUpdates = ____EventDataCache.default
____exports.PlayerUpdateHandler = __TS__Class()
local PlayerUpdateHandler = ____exports.PlayerUpdateHandler
PlayerUpdateHandler.name = "PlayerUpdateHandler"
function PlayerUpdateHandler.prototype.____constructor(self)
end
function PlayerUpdateHandler.prototype.handleBannedEvent(self, event)
self:playerUpdateThrottle(
event,
function(player, data)
data.bannedReason = event.reason or nil
Converters.playerOnlineInfo(player, data)
end
)
end
function PlayerUpdateHandler.prototype.playerUpdateThrottle(self, event, mutate, expirationDurationTicks)
if expirationDurationTicks == nil then
expirationDurationTicks = nil
end
local playerIndex = event.player_index
if playerIndex == nil then
return
end
local eventName = Converters.eventNameString(event.name)
EventUpdates:throttle(
{index = playerIndex},
KafkatorioPacketData.Type.PlayerUpdate,
function(data)
local player = game.players[playerIndex]
if player ~= nil then
mutate(player, data)
end
if data.events == nil then
data.events = {}
end
local ____data_events_0, ____eventName_1 = data.events, eventName
if ____data_events_0[____eventName_1] == nil then
____data_events_0[____eventName_1] = {}
end
local ____data_events_eventName_2 = data.events[eventName]
____data_events_eventName_2[#____data_events_eventName_2 + 1] = event.tick
end,
expirationDurationTicks
)
end
function PlayerUpdateHandler.prototype.playerUpdateImmediate(self, event, mutate)
self:playerUpdateThrottle(event, mutate, 0)
end
local PlayerUpdates = __TS__New(____exports.PlayerUpdateHandler)
____exports.default = PlayerUpdates
return ____exports

View file

@ -1,57 +0,0 @@
local ____exports = {}
local ____EntityUpdateHandler = require("main.events.handlers.EntityUpdateHandler")
local EntityUpdates = ____EntityUpdateHandler.default
local ____MapChunkUpdateHandler = require("main.events.handlers.MapChunkUpdateHandler")
local MapChunkUpdate = ____MapChunkUpdateHandler.default
script.on_event(
defines.events.on_chunk_generated,
function(e)
log("on_chunk_generated " .. tostring(e.tick))
MapChunkUpdate:handleChunkGeneratedEvent(e)
EntityUpdates:handleChunkGeneratedEvent(e)
end
)
script.on_event(
defines.events.script_raised_set_tiles,
function(event)
log("script_raised_set_tiles " .. tostring(event.tick))
MapChunkUpdate:handleScriptSetTilesEvent(event)
end
)
script.on_event(
defines.events.on_player_built_tile,
function(e)
log("on_player_built_tile " .. tostring(e.tick))
MapChunkUpdate:handleBuiltTileEvent(e)
end
)
script.on_event(
defines.events.on_robot_built_tile,
function(e)
log("on_robot_built_tile " .. tostring(e.tick))
MapChunkUpdate:handleBuiltTileEvent(e)
end
)
script.on_event(
defines.events.on_player_mined_tile,
function(e)
log("on_player_mined_tile " .. tostring(e.tick))
MapChunkUpdate:handleMinedTileEvent(e)
EntityUpdates:handleMinedTileEvent(e)
end
)
script.on_event(
defines.events.on_robot_mined_tile,
function(e)
log("on_robot_mined_tile " .. tostring(e.tick))
MapChunkUpdate:handleMinedTileEvent(e)
end
)
script.on_event(
defines.events.on_pre_chunk_deleted,
function(e)
log("on_pre_chunk_deleted " .. tostring(e.tick))
MapChunkUpdate:handlePreChunkDeleted(e)
end
)
return ____exports

View file

@ -1,129 +0,0 @@
local ____exports = {}
local disconnectReasons
local ____converters = require("main.events.converters")
local Converters = ____converters.Converters
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local ____PacketEmitter = require("main.emitting.PacketEmitter")
local packetEmitter = ____PacketEmitter.default
local ____PlayerUpdateHandler = require("main.events.handlers.PlayerUpdateHandler")
local PlayerUpdates = ____PlayerUpdateHandler.default
script.on_event(
defines.events.on_player_joined_game,
function(e)
PlayerUpdates:playerUpdateThrottle(
e,
function(player, data)
data.isAdmin = player.admin
local ____data_2 = data
local ____player_character_unit_number_0 = player.character
if ____player_character_unit_number_0 ~= nil then
____player_character_unit_number_0 = ____player_character_unit_number_0.unit_number
end
____data_2.characterUnitNumber = ____player_character_unit_number_0 or nil
data.chatColour = Converters.mapColour(player.chat_color)
data.colour = Converters.mapColour(player.color)
data.forceIndex = player.force.index
data.name = player.name
data.isShowOnMap = player.show_on_map
data.isSpectator = player.spectator
data.surfaceIndex = player.surface.index
data.tag = player.tag
Converters.playerOnlineInfo(player, data)
end
)
end
)
script.on_event(
defines.events.on_player_changed_position,
function(e)
PlayerUpdates:playerUpdateThrottle(
e,
function(player, data)
data.position = {player.position.x, player.position.y}
end
)
end
)
script.on_event(
defines.events.on_player_changed_surface,
function(e)
PlayerUpdates:playerUpdateThrottle(
e,
function(player, data)
data.position = {player.position.x, player.position.y}
data.surfaceIndex = player.surface.index
end
)
end
)
script.on_event(
defines.events.on_player_died,
function(e)
PlayerUpdates:playerUpdateThrottle(
e,
function(player, data)
data.ticksToRespawn = player.ticks_to_respawn or nil
Converters.playerOnlineInfo(player, data)
if e.cause ~= nil then
data.diedCause = {
unitNumber = e.cause.unit_number or nil,
protoId = Converters.prototypeId(e.cause.type, e.cause.name)
}
end
end
)
end
)
script.on_event(
defines.events.on_player_banned,
function(event)
PlayerUpdates:handleBannedEvent(event)
end
)
script.on_event(
defines.events.on_player_unbanned,
function(event)
PlayerUpdates:handleBannedEvent(event)
end
)
script.on_event(
defines.events.on_player_kicked,
function(event)
log((("on_player_kicked " .. tostring(event.tick)) .. " ") .. tostring(event.name))
PlayerUpdates:playerUpdateImmediate(
event,
function(player, data)
data.kickedReason = event.reason or nil
Converters.playerOnlineInfo(player, data)
end
)
end
)
script.on_event(
defines.events.on_pre_player_left_game,
function(event)
log((("on_pre_player_left_game " .. tostring(event.tick)) .. " ") .. tostring(event.name))
local playerUpdateKey = {index = event.player_index}
local playerUpdate = {type = KafkatorioPacketData.Type.PlayerUpdate, key = playerUpdateKey, disconnectReason = disconnectReasons[event.reason]}
packetEmitter:emitKeyedPacket(playerUpdate)
end
)
script.on_event(
defines.events.on_player_removed,
function(event)
log((("on_player_removed " .. tostring(event.tick)) .. " ") .. tostring(event.name))
PlayerUpdates:playerUpdateImmediate(
event,
function(player, data)
data.isRemoved = true
Converters.playerOnlineInfo(player, data)
end
)
end
)
disconnectReasons = {}
for name, disconnectId in pairs(defines.disconnect_reason) do
disconnectReasons[disconnectId] = name
end
return ____exports

View file

@ -1,83 +0,0 @@
local ____exports = {}
local emit, getMapTilePrototypes, getEntityPrototypes, convertItemGroup, convertItemSubgroup
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local FactorioPrototype = ____kafkatorio_2Dschema.FactorioPrototype
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local ____converters = require("main.events.converters")
local Converters = ____converters.Converters
local ____KafkatorioPacketQueue = require("main.emitting.KafkatorioPacketQueue")
local KafkatorioPacketQueue = ____KafkatorioPacketQueue.default
function emit(protosByType)
for ____, protos in pairs(protosByType) do
KafkatorioPacketQueue:enqueue({type = KafkatorioPacketData.Type.PrototypesUpdate, prototypes = protos})
end
end
function getMapTilePrototypes()
local tiles = {}
for ____, tile in pairs(game.tile_prototypes) do
tiles[#tiles + 1] = {
type = FactorioPrototype.Type.MapTile,
protoId = Converters.prototypeId("tile", tile.name),
order = tile.order,
layer = tile.layer,
collisionMasks = Converters.convertCollisionMaskToNames(tile.collision_mask),
mapColour = Converters.mapColour(tile.map_color),
canBeMined = tile.mineable_properties.minable
}
end
return {tiles = tiles}
end
function getEntityPrototypes()
local protos = {}
for ____, entity in pairs(game.entity_prototypes) do
local key = (((tostring(entity.group.name) .. "/") .. tostring(entity.subgroup.name)) .. "/") .. entity.type
if protos[key] == nil then
protos[key] = {}
end
local entityProto = {
type = FactorioPrototype.Type.Entity,
protoId = Converters.prototypeId(entity.type, entity.name),
group = convertItemGroup(entity.group),
subgroup = convertItemSubgroup(entity.subgroup),
isBuilding = entity.is_building,
isEntityWithOwner = entity.is_entity_with_owner,
isMilitaryTarget = entity.is_military_target,
maxHealth = entity.max_health,
collisionBox = Converters.collisionBox(entity.collision_box),
tileWidth = entity.tile_width,
tileHeight = entity.tile_height
}
if entity.map_color ~= nil then
entityProto.mapColour = Converters.mapColour(entity.map_color)
end
if entity.friendly_map_color ~= nil then
entityProto.mapColourFriend = Converters.mapColour(entity.friendly_map_color)
end
if entity.enemy_map_color ~= nil then
entityProto.mapColourEnemy = Converters.mapColour(entity.enemy_map_color)
end
entityProto.miningProperties = Converters.miningProperties(entity.mineable_properties)
local ____protos_key_0 = protos[key]
____protos_key_0[#____protos_key_0 + 1] = entityProto
end
return protos
end
function convertItemGroup(itemGroup)
return {name = itemGroup.name, type = itemGroup.type, parentName = nil}
end
function convertItemSubgroup(itemGroup)
local ____itemGroup_name_3 = itemGroup.name
local ____itemGroup_type_4 = itemGroup.type
local ____itemGroup_group_name_1 = itemGroup.group
if ____itemGroup_group_name_1 ~= nil then
____itemGroup_group_name_1 = ____itemGroup_group_name_1.name
end
return {name = ____itemGroup_name_3, type = ____itemGroup_type_4, parentName = ____itemGroup_group_name_1 or nil}
end
function ____exports.emitPrototypes()
local mapTileProtos = getMapTilePrototypes()
emit(mapTileProtos)
local entityProtos = getEntityPrototypes()
emit(entityProtos)
end
return ____exports

View file

@ -1,57 +0,0 @@
local ____exports = {}
local ____eventTypeCheck = require("main.events.eventTypeCheck")
local isEventType = ____eventTypeCheck.isEventType
local ____converters = require("main.events.converters")
local Converters = ____converters.Converters
local ____surfaceUpdates = require("main.events.surfaceUpdates")
local handleSurfaceUpdate = ____surfaceUpdates.handleSurfaceUpdate
local ____EventDataCache = require("main.emitting.EventDataCache")
local EventCacheService = ____EventDataCache.default
local ____MapChunkUpdateHandler = require("main.events.handlers.MapChunkUpdateHandler")
local MapChunkUpdate = ____MapChunkUpdateHandler.default
local ____KafkatorioPacketQueue = require("main.emitting.KafkatorioPacketQueue")
local KafkatorioPacketQueue = ____KafkatorioPacketQueue.default
local ____PacketEmitter = require("main.emitting.PacketEmitter")
local PacketEmitter = ____PacketEmitter.default
local ____EventDataQueue = require("main.emitting.EventDataQueue")
local EventDataQueue = ____EventDataQueue.default
script.on_event(
defines.events.on_tick,
function(event)
if event.tick % 1000 == 0 then
for ____, surface in pairs(game.surfaces) do
handleSurfaceUpdate(
event,
Converters.eventNameString(event.name),
surface
)
end
end
local kPacket = KafkatorioPacketQueue:dequeue()
if kPacket ~= nil then
PacketEmitter:emitInstantPacket(kPacket)
end
if event.tick % 6 == 0 then
local emittedCount = EventCacheService:extractAndEmitExpiredPackets()
if emittedCount > 0 then
log(((("[on_tick:" .. tostring(event.tick)) .. "] emitted ") .. tostring(emittedCount)) .. " events")
end
end
if event.tick % 7 == 0 then
local events = EventDataQueue:dequeueValues(1)
if #events > 0 then
log((((("[on_tick:" .. tostring(event.tick)) .. "] dequeued ") .. tostring(#events)) .. " events, current size: ") .. tostring(EventDataQueue:size()))
local i = 1
for ____, event in ipairs(events) do
if isEventType(event, defines.events.on_chunk_generated) then
local eName = Converters.eventNameString(event.name)
log((((("[on_tick:" .. tostring(event.tick)) .. "] dequeued event ") .. eName) .. ", delay ") .. tostring(i))
MapChunkUpdate:handleChunkGeneratedEvent(event, i)
i = i + 1
end
end
end
end
end
)
return ____exports

View file

@ -1,6 +0,0 @@
script.on_event(
defines.events.on_runtime_mod_setting_changed,
function(e)
print((((((("Settings changed " .. e.setting_type) .. ", ") .. tostring(e.player_index)) .. ", ") .. e.setting) .. ", ") .. tostring(e.mod_name))
end
)

View file

@ -1,11 +0,0 @@
local ____exports = {}
local ____PacketEmitter = require("main.emitting.PacketEmitter")
local PacketEmitter = ____PacketEmitter.default
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
local Type = KafkatorioPacketData.Type
function ____exports.handleSurfaceUpdate(event, eventType, surface)
local update = {type = Type.SurfaceUpdate, name = surface.name, index = surface.index, daytime = surface.daytime}
PacketEmitter:emitInstantPacket(update)
end
return ____exports

View file

@ -1,17 +0,0 @@
local ____exports = {}
local ____EventDataCache = require("main.emitting.EventDataCache")
local EventUpdates = ____EventDataCache.default
local ____EventDataQueue = require("main.emitting.EventDataQueue")
local EventDataQueueManager = ____EventDataQueue.EventDataQueueManager
function ____exports.initGlobal(force)
if force == nil then
force = false
end
log(("Initialising Kafkatorio Global variables (force=" .. tostring(force)) .. ")...")
global.MOD_VERSION = script.active_mods[script.mod_name]
global.FACTORIO_VERSION = script.active_mods.base
EventDataQueueManager:init(true)
EventUpdates:init(true)
log("Finished initialising Kafkatorio Global variables")
end
return ____exports

View file

@ -1,46 +0,0 @@
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__StringReplaceAll = ____lualib.__TS__StringReplaceAll
local __TS__New = ____lualib.__TS__New
local ____exports = {}
____exports.KafkatorioSettingsConfig = __TS__Class()
local KafkatorioSettingsConfig = ____exports.KafkatorioSettingsConfig
KafkatorioSettingsConfig.name = "KafkatorioSettingsConfig"
function KafkatorioSettingsConfig.prototype.____constructor(self)
end
function KafkatorioSettingsConfig.prototype.getEventCacheExpirationTicks(self, packet)
local settingName = ____exports.KafkatorioSettingsConfig:cacheDurationSettingName(packet.type)
local seconds = settings.global[settingName].value
return seconds * 60
end
function KafkatorioSettingsConfig.prototype.initialiseSettings(self, data)
for ____type in pairs(____exports.KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds) do
data:extend({____exports.KafkatorioSettingsConfig:createDefaultCacheDuration(____type)})
end
end
function KafkatorioSettingsConfig.createDefaultCacheDuration(self, ____type, defaultExpirationSeconds)
if defaultExpirationSeconds == nil then
defaultExpirationSeconds = ____exports.KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[____type]
end
return {
type = "double-setting",
name = ____exports.KafkatorioSettingsConfig:cacheDurationSettingName(____type),
setting_type = "runtime-global",
default_value = defaultExpirationSeconds,
minimum_value = 0.25,
maximum_value = 120
}
end
function KafkatorioSettingsConfig.cacheDurationSettingName(self, ____type)
return "kafkatorio:cache-expiration-seconds_" .. __TS__StringReplaceAll(____type, ".", "-")
end
KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds = {
["kafkatorio.packet.keyed.PlayerUpdate"] = 0.5,
["kafkatorio.packet.keyed.MapChunkTileUpdate"] = 30,
["kafkatorio.packet.keyed.MapChunkEntityUpdate"] = 30,
["kafkatorio.packet.keyed.MapChunkResourceUpdate"] = 30,
["kafkatorio.packet.keyed.EntityUpdate"] = 5
}
local KafkatorioSettings = __TS__New(____exports.KafkatorioSettingsConfig)
____exports.default = KafkatorioSettings
return ____exports

View file

@ -1,5 +0,0 @@
local ____exports = {}
local ____KafkatorioSettings = require("main.settings.KafkatorioSettings")
local KafkatorioSettings = ____KafkatorioSettings.default
KafkatorioSettings:initialiseSettings(data)
return ____exports