commit generated lua code (I'm not 100% sure it's generated stably - this way I can see changes)
This commit is contained in:
parent
ae0d95b4cb
commit
b0452881bc
22 changed files with 3689 additions and 5 deletions
15
modules/events-mod/src/main/lua/control.lua
Normal file
15
modules/events-mod/src/main/lua/control.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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.registerHandlers")
|
||||
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
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
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.MapChunkUpdate = "kafkatorio.packet.keyed.MapChunkUpdate"
|
||||
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.MinedProductType = MinedProductType or ({})
|
||||
____exports.MinedProductType.item = "item"
|
||||
____exports.MinedProductType.fluid = "fluid"
|
||||
return ____exports
|
||||
2475
modules/events-mod/src/main/lua/lualib_bundle.lua
Normal file
2475
modules/events-mod/src/main/lua/lualib_bundle.lua
Normal file
File diff suppressed because it is too large
Load diff
22
modules/events-mod/src/main/lua/main/PacketEmitter.lua
Normal file
22
modules/events-mod/src/main/lua/main/PacketEmitter.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__Class = ____lualib.__TS__Class
|
||||
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)
|
||||
localised_print("KafkatorioPacket: " .. data)
|
||||
end
|
||||
local PacketEmitter = __TS__New(____exports.KafkatorioPacketEmitter)
|
||||
____exports.default = PacketEmitter
|
||||
return ____exports
|
||||
145
modules/events-mod/src/main/lua/main/cache/EventDataCache.lua
vendored
Normal file
145
modules/events-mod/src/main/lua/main/cache/EventDataCache.lua
vendored
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__Class = ____lualib.__TS__Class
|
||||
local __TS__New = ____lualib.__TS__New
|
||||
local ____exports = {}
|
||||
local ____KafkatorioSettings = require("main.settings.KafkatorioSettings")
|
||||
local KafkatorioSettings = ____KafkatorioSettings.default
|
||||
local ____PacketEmitter = require("main.PacketEmitter")
|
||||
local packetEmitter = ____PacketEmitter.default
|
||||
____exports.EventUpdates = {}
|
||||
local EventUpdates = ____exports.EventUpdates
|
||||
do
|
||||
local CacheEntry
|
||||
EventUpdates.Manager = __TS__Class()
|
||||
local Manager = EventUpdates.Manager
|
||||
Manager.name = "Manager"
|
||||
function Manager.prototype.____constructor(self)
|
||||
end
|
||||
function Manager.prototype.init(self, force)
|
||||
local isAnythingUndefined = global.cache == nil
|
||||
log(((("Initialising EventDataCache (force=" .. tostring(force)) .. ", isAnythingUndefined=") .. tostring(isAnythingUndefined)) .. ")...")
|
||||
if force == true or isAnythingUndefined then
|
||||
log("Initialising global.cache")
|
||||
global.cache = {}
|
||||
end
|
||||
log("Finished initialising EventDataCache")
|
||||
end
|
||||
function Manager.prototype.throttle(self, key, ____type, mutate, expirationDurationTicks)
|
||||
self:update(
|
||||
key,
|
||||
____type,
|
||||
mutate,
|
||||
false,
|
||||
expirationDurationTicks
|
||||
)
|
||||
end
|
||||
function Manager.prototype.debounce(self, key, ____type, mutate, expirationDurationTicks)
|
||||
self:update(
|
||||
key,
|
||||
____type,
|
||||
mutate,
|
||||
true,
|
||||
expirationDurationTicks
|
||||
)
|
||||
end
|
||||
function Manager.prototype.update(self, key, ____type, mutate, resetLastUpdated, expirationDurationTicks)
|
||||
local entry = self:getCacheEntry(key, ____type) or EventUpdates.Manager: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 Manager.prototype.setExpiration(self, key, ____type, expirationDurationTicks)
|
||||
local entry = self:getCacheEntry(key, ____type)
|
||||
if entry ~= nil then
|
||||
entry.expirationDurationTicks = expirationDurationTicks
|
||||
end
|
||||
end
|
||||
function Manager.prototype.extractExpired(self)
|
||||
local countExpired = 0
|
||||
local countTotal = 0
|
||||
local expiredData = {}
|
||||
for key, entry in pairs(global.cache) do
|
||||
countTotal = countTotal + 1
|
||||
if self:isExpired(entry) then
|
||||
countExpired = countExpired + 1
|
||||
expiredData[#expiredData + 1] = entry.packet
|
||||
global.cache[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 Manager.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 Manager.prototype.getCacheEntry(self, key, ____type)
|
||||
local hash = EventUpdates.Manager:hashKey(key)
|
||||
if not (global.cache[hash] ~= nil) then
|
||||
return nil
|
||||
end
|
||||
local value = global.cache[hash]
|
||||
if self:isEntryInstanceOf(value, ____type) then
|
||||
return value
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
function Manager.createCacheEntry(self, key, ____type)
|
||||
local data = {type = ____type, key = key}
|
||||
local entry = __TS__New(CacheEntry, data)
|
||||
local hash = EventUpdates.Manager:hashKey(key)
|
||||
global.cache[hash] = entry
|
||||
return entry
|
||||
end
|
||||
function Manager.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 Manager.prototype.isEntryInstanceOf(self, entry, ____type)
|
||||
local ____self_2 = self
|
||||
local ____self_isDataInstanceOf_3 = self.isDataInstanceOf
|
||||
local ____entry_packet_0 = entry
|
||||
if ____entry_packet_0 ~= nil then
|
||||
____entry_packet_0 = ____entry_packet_0.packet
|
||||
end
|
||||
return ____self_isDataInstanceOf_3(____self_2, ____entry_packet_0, ____type)
|
||||
end
|
||||
function Manager.prototype.isDataInstanceOf(self, packet, ____type)
|
||||
return packet ~= nil and packet.type == ____type
|
||||
end
|
||||
function Manager.hashKey(self, key)
|
||||
return game.encode_string(game.table_to_json(key))
|
||||
end
|
||||
CacheEntry = __TS__Class()
|
||||
CacheEntry.name = "CacheEntry"
|
||||
function CacheEntry.prototype.____constructor(self, packet, expirationDurationTicks)
|
||||
self.lastUpdatedTick = game.tick
|
||||
self.packet = packet
|
||||
self.expirationDurationTicks = expirationDurationTicks
|
||||
end
|
||||
end
|
||||
local EventUpdatesManager = __TS__New(____exports.EventUpdates.Manager)
|
||||
____exports.default = EventUpdatesManager
|
||||
return ____exports
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
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 ____queue = require("main.queue.queue")
|
||||
local Queue = ____queue.Queue
|
||||
local ____prototypeUpdates = require("main.events.prototypeUpdates")
|
||||
local emitPrototypes = ____prototypeUpdates.emitPrototypes
|
||||
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
|
||||
}
|
||||
Queue.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
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
local ____lualib = require("lualib_bundle")
|
||||
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 emitConfigurationUpdate, factorioData, allMods, Type
|
||||
local ____PacketEmitter = require("main.PacketEmitter")
|
||||
local PacketEmitter = ____PacketEmitter.default
|
||||
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
|
||||
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
|
||||
local ____global_2Dinit = require("main.global-init")
|
||||
local initGlobal = ____global_2Dinit.initGlobal
|
||||
local ____prototypeUpdates = require("main.events.prototypeUpdates")
|
||||
local emitPrototypes = ____prototypeUpdates.emitPrototypes
|
||||
function emitConfigurationUpdate(changeData)
|
||||
local configUpdateData = {
|
||||
type = Type.ConfigurationUpdate,
|
||||
migrationApplied = changeData.migration_applied,
|
||||
modStartupSettingsChange = changeData.mod_startup_settings_changed,
|
||||
allMods = allMods(changeData),
|
||||
factorioData = factorioData(changeData)
|
||||
}
|
||||
PacketEmitter:emitInstantPacket(configUpdateData)
|
||||
end
|
||||
function factorioData(changeData)
|
||||
return {oldVersion = changeData.old_version or nil, newVersion = changeData.new_version or nil}
|
||||
end
|
||||
function allMods(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
|
||||
Type = KafkatorioPacketData.Type
|
||||
script.on_configuration_changed(function(data)
|
||||
initGlobal(true)
|
||||
emitConfigurationUpdate(data)
|
||||
emitPrototypes()
|
||||
end)
|
||||
return ____exports
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
local ____exports = {}
|
||||
local ____PacketEmitter = require("main.PacketEmitter")
|
||||
local PacketEmitter = ____PacketEmitter.default
|
||||
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
|
||||
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
|
||||
local Type = KafkatorioPacketData.Type
|
||||
script.on_event(
|
||||
defines.events.on_console_chat,
|
||||
function(event)
|
||||
local update = {type = Type.ConsoleChatUpdate, authorPlayerIndex = event.player_index or nil, content = event.message}
|
||||
PacketEmitter:emitInstantPacket(update)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_console_command,
|
||||
function(event)
|
||||
local update = {type = Type.ConsoleCommandUpdate, authorPlayerIndex = event.player_index or nil, command = event.command, parameters = event.parameters}
|
||||
PacketEmitter:emitInstantPacket(update)
|
||||
end
|
||||
)
|
||||
return ____exports
|
||||
40
modules/events-mod/src/main/lua/main/events/converters.lua
Normal file
40
modules/events-mod/src/main/lua/main/events/converters.lua
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
local ____exports = {}
|
||||
____exports.Converters = {}
|
||||
local Converters = ____exports.Converters
|
||||
do
|
||||
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.convertMapTablePosition(position)
|
||||
return {position.x, position.y}
|
||||
end
|
||||
function Converters.convertCollisionMaskToNames(cm)
|
||||
local masks = {}
|
||||
for name in pairs(cm) do
|
||||
masks[#masks + 1] = name
|
||||
end
|
||||
return masks
|
||||
end
|
||||
end
|
||||
return ____exports
|
||||
105
modules/events-mod/src/main/lua/main/events/entityUpdates.lua
Normal file
105
modules/events-mod/src/main/lua/main/events/entityUpdates.lua
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
local ____exports = {}
|
||||
local handleBuiltEntityEvent, handleMinedEntityEvent
|
||||
local ____converters = require("main.events.converters")
|
||||
local Converters = ____converters.Converters
|
||||
local ____EventDataCache = require("main.cache.EventDataCache")
|
||||
local EventDataCache = ____EventDataCache.default
|
||||
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
|
||||
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
|
||||
function handleBuiltEntityEvent(event)
|
||||
local eventName = Converters.eventNameString(event.name)
|
||||
if event.created_entity.unit_number == nil then
|
||||
return
|
||||
end
|
||||
local key = {name = event.created_entity.name, protoType = event.created_entity.prototype.name, unitNumber = event.created_entity.unit_number}
|
||||
EventDataCache:debounce(
|
||||
key,
|
||||
KafkatorioPacketData.Type.EntityUpdate,
|
||||
function(data)
|
||||
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
|
||||
data.chunkPosition = Converters.convertMapTablePosition(event.created_entity.position)
|
||||
data.graphicsVariation = event.created_entity.graphics_variation
|
||||
data.health = event.created_entity.health
|
||||
data.isActive = event.created_entity.active
|
||||
data.isRotatable = event.created_entity.rotatable
|
||||
local ____data_5 = data
|
||||
local ____event_created_entity_last_user_index_3 = event.created_entity.last_user
|
||||
if ____event_created_entity_last_user_index_3 ~= nil then
|
||||
____event_created_entity_last_user_index_3 = ____event_created_entity_last_user_index_3.index
|
||||
end
|
||||
____data_5.lastUser = ____event_created_entity_last_user_index_3
|
||||
data.prototype = event.created_entity.prototype.name
|
||||
end
|
||||
)
|
||||
end
|
||||
function handleMinedEntityEvent(event)
|
||||
local eventName = Converters.eventNameString(event.name)
|
||||
if event.entity.unit_number == nil then
|
||||
return
|
||||
end
|
||||
local key = {name = event.entity.name, protoType = event.entity.prototype.name, unitNumber = event.entity.unit_number}
|
||||
EventDataCache:debounce(
|
||||
key,
|
||||
KafkatorioPacketData.Type.EntityUpdate,
|
||||
function(data)
|
||||
if data.events == nil then
|
||||
data.events = {}
|
||||
end
|
||||
local ____data_events_6, ____eventName_7 = data.events, eventName
|
||||
if ____data_events_6[____eventName_7] == nil then
|
||||
____data_events_6[____eventName_7] = {}
|
||||
end
|
||||
local ____data_events_eventName_8 = data.events[eventName]
|
||||
____data_events_eventName_8[#____data_events_eventName_8 + 1] = event.tick
|
||||
data.chunkPosition = Converters.convertMapTablePosition(event.entity.position)
|
||||
data.graphicsVariation = event.entity.graphics_variation
|
||||
data.health = event.entity.health
|
||||
data.isActive = event.entity.active
|
||||
data.isRotatable = event.entity.rotatable
|
||||
local ____data_11 = data
|
||||
local ____event_entity_last_user_index_9 = event.entity.last_user
|
||||
if ____event_entity_last_user_index_9 ~= nil then
|
||||
____event_entity_last_user_index_9 = ____event_entity_last_user_index_9.index
|
||||
end
|
||||
____data_11.lastUser = ____event_entity_last_user_index_9
|
||||
data.prototype = event.entity.prototype.name
|
||||
end
|
||||
)
|
||||
end
|
||||
script.on_event(
|
||||
defines.events.on_built_entity,
|
||||
function(e)
|
||||
log("on_built_entity " .. tostring(e.tick))
|
||||
handleBuiltEntityEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_robot_built_entity,
|
||||
function(e)
|
||||
log("on_robot_built_entity " .. tostring(e.tick))
|
||||
handleBuiltEntityEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_player_mined_entity,
|
||||
function(e)
|
||||
log("on_player_mined_entity " .. tostring(e.tick))
|
||||
handleMinedEntityEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_robot_mined_entity,
|
||||
function(e)
|
||||
log("on_robot_mined_entity " .. tostring(e.tick))
|
||||
handleMinedEntityEvent(e)
|
||||
end
|
||||
)
|
||||
return ____exports
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
local ____exports = {}
|
||||
function ____exports.isEventType(eventData, ____type)
|
||||
local id = eventData.name
|
||||
return id == ____type
|
||||
end
|
||||
return ____exports
|
||||
248
modules/events-mod/src/main/lua/main/events/mapChunkUpdates.lua
Normal file
248
modules/events-mod/src/main/lua/main/events/mapChunkUpdates.lua
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
local ____lualib = require("lualib_bundle")
|
||||
local Map = ____lualib.Map
|
||||
local __TS__Iterator = ____lualib.__TS__Iterator
|
||||
local __TS__New = ____lualib.__TS__New
|
||||
local ____exports = {}
|
||||
local mapTilesUpdateDebounce, getTiles, getSurface, groupTiles, handleBuiltTileEvent, handleMinedTileEvent, Type
|
||||
local ____eventTypeCheck = require("main.events.eventTypeCheck")
|
||||
local isEventType = ____eventTypeCheck.isEventType
|
||||
local ____converters = require("main.events.converters")
|
||||
local Converters = ____converters.Converters
|
||||
local ____EventDataCache = require("main.cache.EventDataCache")
|
||||
local EventUpdatesManager = ____EventDataCache.default
|
||||
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
|
||||
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
|
||||
function mapTilesUpdateDebounce(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}
|
||||
EventUpdatesManager:debounce(
|
||||
key,
|
||||
Type.MapChunkUpdate,
|
||||
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 ____data_tileDictionary_protos_1, ____tile_name_2 = data.tileDictionary.protos, tile.name
|
||||
if ____data_tileDictionary_protos_1[____tile_name_2] == nil then
|
||||
local ____protosCount_0 = protosCount
|
||||
protosCount = ____protosCount_0 + 1
|
||||
____data_tileDictionary_protos_1[____tile_name_2] = ____protosCount_0
|
||||
end
|
||||
local protoKey = data.tileDictionary.protos[tile.name]
|
||||
local xString = tostring(tile.position.x)
|
||||
local yString = tostring(tile.position.y)
|
||||
local ____data_tileDictionary_tilesXY_3, ____xString_4 = data.tileDictionary.tilesXY, xString
|
||||
if ____data_tileDictionary_tilesXY_3[____xString_4] == nil then
|
||||
____data_tileDictionary_tilesXY_3[____xString_4] = {}
|
||||
end
|
||||
data.tileDictionary.tilesXY[xString][yString] = protoKey
|
||||
end
|
||||
if data.events == nil then
|
||||
data.events = {}
|
||||
end
|
||||
local ____data_events_5, ____eventName_6 = data.events, eventName
|
||||
if ____data_events_5[____eventName_6] == nil then
|
||||
____data_events_5[____eventName_6] = {}
|
||||
end
|
||||
local ____data_events_eventName_7 = data.events[eventName]
|
||||
____data_events_eventName_7[#____data_events_eventName_7 + 1] = event.tick
|
||||
if updater ~= nil then
|
||||
updater(data)
|
||||
end
|
||||
end,
|
||||
expirationDurationTicks
|
||||
)
|
||||
end
|
||||
function getTiles(surface, area)
|
||||
local ____surface_find_tiles_filtered_result_8 = surface
|
||||
if ____surface_find_tiles_filtered_result_8 ~= nil then
|
||||
____surface_find_tiles_filtered_result_8 = ____surface_find_tiles_filtered_result_8.find_tiles_filtered({area = area})
|
||||
end
|
||||
return ____surface_find_tiles_filtered_result_8 or ({})
|
||||
end
|
||||
function getSurface(surfaceIndex)
|
||||
return game.surfaces[surfaceIndex]
|
||||
end
|
||||
function ____exports.handleChunkGeneratedEvent(event, expirationDurationTicks)
|
||||
local tiles = getTiles(event.surface, event.area)
|
||||
mapTilesUpdateDebounce(
|
||||
event.surface,
|
||||
Converters.convertMapTablePosition(event.position),
|
||||
tiles,
|
||||
event,
|
||||
nil,
|
||||
expirationDurationTicks
|
||||
)
|
||||
end
|
||||
function groupTiles(tiles)
|
||||
local mapChunkPositionToTiles = __TS__New(Map)
|
||||
for ____, tile in ipairs(tiles) do
|
||||
local chunkPosition = {
|
||||
math.floor(tile.position.x / 32),
|
||||
math.floor(tile.position.y / 32)
|
||||
}
|
||||
if not mapChunkPositionToTiles:has(chunkPosition) then
|
||||
mapChunkPositionToTiles:set(chunkPosition, {})
|
||||
end
|
||||
local ____mapChunkPositionToTiles_get_result_push_result_10 = mapChunkPositionToTiles:get(chunkPosition)
|
||||
if ____mapChunkPositionToTiles_get_result_push_result_10 ~= nil then
|
||||
local ____temp_11 = mapChunkPositionToTiles:get(chunkPosition)
|
||||
____temp_11[#____temp_11 + 1] = tile
|
||||
____mapChunkPositionToTiles_get_result_push_result_10 = nil
|
||||
end
|
||||
end
|
||||
return mapChunkPositionToTiles
|
||||
end
|
||||
function handleBuiltTileEvent(event)
|
||||
local surface = getSurface(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 = groupTiles(tiles)
|
||||
for ____, ____value in __TS__Iterator(groupedTiles) do
|
||||
local chunkPos = ____value[1]
|
||||
local tiles = ____value[2]
|
||||
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_15 = data
|
||||
local ____event_robot_unit_number_13 = event.robot
|
||||
if ____event_robot_unit_number_13 ~= nil then
|
||||
____event_robot_unit_number_13 = ____event_robot_unit_number_13.unit_number
|
||||
end
|
||||
____data_15.robot = {unitNumber = ____event_robot_unit_number_13 or nil, name = event.robot.name, protoType = event.robot.type}
|
||||
return
|
||||
end
|
||||
local exhaustiveCheck = event
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
function handleMinedTileEvent(event)
|
||||
local surface = getSurface(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 = groupTiles(tiles)
|
||||
for ____, ____value in __TS__Iterator(groupedTiles) do
|
||||
local chunkPos = ____value[1]
|
||||
local tiles = ____value[2]
|
||||
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_18 = data
|
||||
local ____event_robot_unit_number_16 = event.robot
|
||||
if ____event_robot_unit_number_16 ~= nil then
|
||||
____event_robot_unit_number_16 = ____event_robot_unit_number_16.unit_number
|
||||
end
|
||||
____data_18.robot = {unitNumber = ____event_robot_unit_number_16 or nil, name = event.robot.name, protoType = event.robot.type}
|
||||
return
|
||||
end
|
||||
local exhaustiveCheck = event
|
||||
end
|
||||
)
|
||||
end
|
||||
end
|
||||
Type = KafkatorioPacketData.Type
|
||||
script.on_event(
|
||||
defines.events.on_chunk_generated,
|
||||
function(e)
|
||||
log("on_chunk_generated " .. tostring(e.tick))
|
||||
____exports.handleChunkGeneratedEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.script_raised_set_tiles,
|
||||
function(event)
|
||||
log("script_raised_set_tiles " .. tostring(event.tick))
|
||||
local surface = getSurface(event.surface_index)
|
||||
if surface == nil then
|
||||
return
|
||||
end
|
||||
local groupedTiles = groupTiles(event.tiles)
|
||||
for ____, ____value in __TS__Iterator(groupedTiles) do
|
||||
local chunkPos = ____value[1]
|
||||
local tiles = ____value[2]
|
||||
mapTilesUpdateDebounce(surface, chunkPos, tiles, event)
|
||||
end
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_player_built_tile,
|
||||
function(e)
|
||||
log("on_player_built_tile " .. tostring(e.tick))
|
||||
handleBuiltTileEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_robot_built_tile,
|
||||
function(e)
|
||||
log("on_robot_built_tile " .. tostring(e.tick))
|
||||
handleBuiltTileEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_player_mined_tile,
|
||||
function(e)
|
||||
log("on_player_mined_tile " .. tostring(e.tick))
|
||||
handleMinedTileEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_robot_mined_tile,
|
||||
function(e)
|
||||
log("on_robot_mined_tile " .. tostring(e.tick))
|
||||
handleMinedTileEvent(e)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_pre_chunk_deleted,
|
||||
function(e)
|
||||
log("on_pre_chunk_deleted " .. tostring(e.tick))
|
||||
local surface = getSurface(e.surface_index)
|
||||
if surface == nil then
|
||||
return
|
||||
end
|
||||
for ____, position in ipairs(e.positions) do
|
||||
local key = {surfaceIndex = surface.index, chunkPosition = {position.x, position.y}}
|
||||
EventUpdatesManager:debounce(
|
||||
key,
|
||||
Type.MapChunkUpdate,
|
||||
function(data)
|
||||
local ____temp_19 = true
|
||||
data.isDeleted = ____temp_19
|
||||
return ____temp_19
|
||||
end,
|
||||
0
|
||||
)
|
||||
end
|
||||
end
|
||||
)
|
||||
return ____exports
|
||||
165
modules/events-mod/src/main/lua/main/events/playerUpdates.lua
Normal file
165
modules/events-mod/src/main/lua/main/events/playerUpdates.lua
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
local ____exports = {}
|
||||
local playerUpdateThrottle, playerOnlineInfo, handleBannedEvent, Type
|
||||
local ____converters = require("main.events.converters")
|
||||
local Converters = ____converters.Converters
|
||||
local ____EventDataCache = require("main.cache.EventDataCache")
|
||||
local EventUpdatesManager = ____EventDataCache.default
|
||||
local ____kafkatorio_2Dschema = require("generated.kafkatorio-schema")
|
||||
local KafkatorioPacketData = ____kafkatorio_2Dschema.KafkatorioPacketData
|
||||
local ____PacketEmitter = require("main.PacketEmitter")
|
||||
local packetEmitter = ____PacketEmitter.default
|
||||
function playerUpdateThrottle(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)
|
||||
EventUpdatesManager:throttle(
|
||||
{index = playerIndex},
|
||||
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 playerOnlineInfo(player, data)
|
||||
data.lastOnline = player.last_online
|
||||
data.onlineTime = player.online_time
|
||||
data.afkTime = player.afk_time
|
||||
data.isConnected = player.connected
|
||||
end
|
||||
function handleBannedEvent(event)
|
||||
playerUpdateThrottle(
|
||||
event,
|
||||
function(player, data)
|
||||
data.bannedReason = event.reason or nil
|
||||
playerOnlineInfo(player, data)
|
||||
end
|
||||
)
|
||||
end
|
||||
Type = KafkatorioPacketData.Type
|
||||
local function playerUpdateImmediate(event, mutate)
|
||||
playerUpdateThrottle(event, mutate, 0)
|
||||
end
|
||||
script.on_event(
|
||||
defines.events.on_player_joined_game,
|
||||
function(e)
|
||||
playerUpdateThrottle(
|
||||
e,
|
||||
function(player, data)
|
||||
data.isAdmin = player.admin
|
||||
local ____data_5 = data
|
||||
local ____player_character_unit_number_3 = player.character
|
||||
if ____player_character_unit_number_3 ~= nil then
|
||||
____player_character_unit_number_3 = ____player_character_unit_number_3.unit_number
|
||||
end
|
||||
____data_5.characterUnitNumber = ____player_character_unit_number_3 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
|
||||
playerOnlineInfo(player, data)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
script.on_event(
|
||||
defines.events.on_player_changed_position,
|
||||
function(e)
|
||||
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)
|
||||
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)
|
||||
playerUpdateThrottle(
|
||||
e,
|
||||
function(player, data)
|
||||
data.ticksToRespawn = player.ticks_to_respawn or nil
|
||||
playerOnlineInfo(player, data)
|
||||
if e.cause ~= nil then
|
||||
data.diedCause = {unitNumber = e.cause.unit_number or nil, name = e.cause.name, protoType = e.cause.type}
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
script.on_event(defines.events.on_player_banned, handleBannedEvent)
|
||||
script.on_event(defines.events.on_player_unbanned, handleBannedEvent)
|
||||
script.on_event(
|
||||
defines.events.on_player_kicked,
|
||||
function(event)
|
||||
log((("on_player_kicked " .. tostring(event.tick)) .. " ") .. tostring(event.name))
|
||||
playerUpdateImmediate(
|
||||
event,
|
||||
function(player, data)
|
||||
data.kickedReason = event.reason or nil
|
||||
playerOnlineInfo(player, data)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
local disconnectReasons = {}
|
||||
for name, disconnectId in pairs(defines.disconnect_reason) do
|
||||
disconnectReasons[disconnectId] = name
|
||||
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))
|
||||
playerUpdateImmediate(
|
||||
event,
|
||||
function(player, data)
|
||||
data.isRemoved = true
|
||||
playerOnlineInfo(player, data)
|
||||
end
|
||||
)
|
||||
end
|
||||
)
|
||||
return ____exports
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__ArrayPushArray = ____lualib.__TS__ArrayPushArray
|
||||
local ____exports = {}
|
||||
local prototypeUpdates, getMapTilePrototypes
|
||||
local ____PacketEmitter = require("main.PacketEmitter")
|
||||
local PacketEmitter = ____PacketEmitter.default
|
||||
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
|
||||
function prototypeUpdates()
|
||||
local prototypes = {}
|
||||
__TS__ArrayPushArray(
|
||||
prototypes,
|
||||
getMapTilePrototypes()
|
||||
)
|
||||
return prototypes
|
||||
end
|
||||
function getMapTilePrototypes()
|
||||
local tiles = {}
|
||||
for ____, tile in pairs(game.tile_prototypes) do
|
||||
tiles[#tiles + 1] = {
|
||||
type = FactorioPrototype.Type.MapTile,
|
||||
name = 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
|
||||
end
|
||||
function ____exports.emitPrototypes()
|
||||
local data = {
|
||||
prototypes = prototypeUpdates(),
|
||||
type = KafkatorioPacketData.Type.PrototypesUpdate
|
||||
}
|
||||
PacketEmitter:emitInstantPacket(data)
|
||||
end
|
||||
return ____exports
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
local ____exports = {}
|
||||
local ____queue = require("main.queue.queue")
|
||||
local Queue = ____queue.Queue
|
||||
local ____eventTypeCheck = require("main.events.eventTypeCheck")
|
||||
local isEventType = ____eventTypeCheck.isEventType
|
||||
local ____converters = require("main.events.converters")
|
||||
local Converters = ____converters.Converters
|
||||
local ____mapChunkUpdates = require("main.events.mapChunkUpdates")
|
||||
local handleChunkGeneratedEvent = ____mapChunkUpdates.handleChunkGeneratedEvent
|
||||
local ____surfaceUpdates = require("main.events.surfaceUpdates")
|
||||
local handleSurfaceUpdate = ____surfaceUpdates.handleSurfaceUpdate
|
||||
local ____EventDataCache = require("main.cache.EventDataCache")
|
||||
local EventCacheService = ____EventDataCache.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
|
||||
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 = Queue.dequeueValues(1)
|
||||
if #events > 0 then
|
||||
log((((("[on_tick:" .. tostring(event.tick)) .. "] dequeued ") .. tostring(#events)) .. " events, current size: ") .. tostring(Queue.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)) .. "] dequed event ") .. eName) .. ", delay ") .. tostring(i))
|
||||
handleChunkGeneratedEvent(event, i)
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
return ____exports
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
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
|
||||
)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
local ____exports = {}
|
||||
local ____PacketEmitter = require("main.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
|
||||
17
modules/events-mod/src/main/lua/main/global-init.lua
Normal file
17
modules/events-mod/src/main/lua/main/global-init.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
local ____exports = {}
|
||||
local ____queue = require("main.queue.queue")
|
||||
local Queue = ____queue.Queue
|
||||
local ____EventDataCache = require("main.cache.EventDataCache")
|
||||
local EventUpdatesManager = ____EventDataCache.default
|
||||
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
|
||||
Queue.init(true)
|
||||
EventUpdatesManager:init(true)
|
||||
log("Finished initialising Kafkatorio Global variables")
|
||||
end
|
||||
return ____exports
|
||||
84
modules/events-mod/src/main/lua/main/queue/queue.lua
Normal file
84
modules/events-mod/src/main/lua/main/queue/queue.lua
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__New = ____lualib.__TS__New
|
||||
local __TS__Class = ____lualib.__TS__Class
|
||||
local ____exports = {}
|
||||
____exports.Queue = {}
|
||||
local Queue = ____exports.Queue
|
||||
do
|
||||
local Node
|
||||
function Queue.init(force)
|
||||
local isAnythingUndefined = global.store == nil or global.size == nil or global.head == nil or global.tail == nil
|
||||
log(((("Initialising EventQueue 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 EventQueue")
|
||||
end
|
||||
function Queue.size()
|
||||
return global.size
|
||||
end
|
||||
function Queue.enqueue(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 Queue.dequeue()
|
||||
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 Queue.dequeueValues(targetWeight)
|
||||
if targetWeight == nil then
|
||||
targetWeight = 50
|
||||
end
|
||||
local values = {}
|
||||
local weight = 0
|
||||
repeat
|
||||
do
|
||||
local packet = Queue.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
|
||||
Node = __TS__Class()
|
||||
Node.name = "Node"
|
||||
function Node.prototype.____constructor(self, storeKey, weight)
|
||||
self.next = nil
|
||||
self.storeKey = storeKey
|
||||
self.weight = weight
|
||||
end
|
||||
end
|
||||
return ____exports
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
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.MapChunkUpdate"] = 30, ["kafkatorio.packet.keyed.EntityUpdate"] = 5}
|
||||
local KafkatorioSettings = __TS__New(____exports.KafkatorioSettingsConfig)
|
||||
____exports.default = KafkatorioSettings
|
||||
return ____exports
|
||||
5
modules/events-mod/src/main/lua/settings.lua
Normal file
5
modules/events-mod/src/main/lua/settings.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
local ____exports = {}
|
||||
local ____KafkatorioSettings = require("main.settings.KafkatorioSettings")
|
||||
local KafkatorioSettings = ____KafkatorioSettings.default
|
||||
KafkatorioSettings:initialiseSettings(data)
|
||||
return ____exports
|
||||
Loading…
Add table
Add a link
Reference in a new issue