Refactor send logic to use senderPlayerIndex and optimize content chunking
This commit is contained in:
38
control.lua
38
control.lua
@@ -9,23 +9,21 @@ require("metrics-combinator")
|
||||
require("player-statistics")
|
||||
require("send-utils")
|
||||
|
||||
--tickInterval = tonumber(settings.global["factorio-metrics-exporter-tick-interval"].value) or 300
|
||||
--options.udpPort = 52555
|
||||
|
||||
isInitialized = false
|
||||
--options.sendIndex = 0
|
||||
--serverIndex = 0
|
||||
scannedGrids = false
|
||||
scannedLabs = false
|
||||
scannedGenerators = false
|
||||
autotrainGroupName = ""
|
||||
autotrainDepotName = ""
|
||||
sendIndex = 0
|
||||
|
||||
|
||||
options = {
|
||||
---@type integer
|
||||
udpPort = 52555,
|
||||
---@type integer
|
||||
senderIndex = 0,
|
||||
senderPlayerIndex = 0,
|
||||
---@type integer
|
||||
tickInterval = 300,
|
||||
enableMod = false,
|
||||
@@ -69,10 +67,10 @@ script.on_init(function()
|
||||
|
||||
storage.scannedGrids = false
|
||||
storage.scannedLabs = false
|
||||
options.senderIndex = 0
|
||||
options.senderPlayerIndex = 0
|
||||
|
||||
options.enableMod = settings.global["factorio-metrics-exporter-enable"].value
|
||||
options.senderIndex = settings.global["factorio-metrics-exporter-sending-player-index"].value
|
||||
options.senderPlayerIndex = settings.global["factorio-metrics-exporter-sending-player-index"].value
|
||||
options.udpPort = settings.global["factorio-metrics-exporter-udp-port"].value
|
||||
options.enableProduction = settings.global["factorio-metrics-exporter-export_production_stats"].value
|
||||
options.enablePollution = settings.global["factorio-metrics-exporter-export_pollution_stats"].value
|
||||
@@ -94,7 +92,7 @@ script.on_load(function()
|
||||
log("udpAddress: " .. options.udpPort)
|
||||
|
||||
options.enableMod = settings.global["factorio-metrics-exporter-enable"].value
|
||||
options.senderIndex = settings.global["factorio-metrics-exporter-sending-player-index"].value
|
||||
options.senderPlayerIndex = settings.global["factorio-metrics-exporter-sending-player-index"].value
|
||||
options.udpPort = settings.global["factorio-metrics-exporter-udp-port"].value
|
||||
options.enableProduction = settings.global["factorio-metrics-exporter-export_production_stats"].value
|
||||
options.enablePollution = settings.global["factorio-metrics-exporter-export_pollution_stats"].value
|
||||
@@ -154,7 +152,7 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
|
||||
end
|
||||
|
||||
if event.setting == "factorio-metrics-exporter-sending-player-index" then
|
||||
options.senderIndex = settings.global["factorio-metrics-exporter-sending-player-index"].value
|
||||
options.senderPlayerIndex = settings.global["factorio-metrics-exporter-sending-player-index"].value
|
||||
end
|
||||
|
||||
if event.setting == "factorio-metrics-exporter-udp-port" then
|
||||
@@ -266,23 +264,23 @@ function SendAll(event)
|
||||
if options.enableMod == true then
|
||||
local interval = math.max(1, math.floor(options.tickInterval / 10))
|
||||
if event.tick % interval ~= 0 then return end
|
||||
options.senderIndex = (options.senderIndex % 10) + 1
|
||||
if options.senderIndex == 1 then SendProductionStats() end
|
||||
if options.senderIndex == 2 then SendPollutionStats() end
|
||||
if options.senderIndex == 3 then
|
||||
sendIndex = (sendIndex % 10) + 1
|
||||
if sendIndex == 1 then SendProductionStats() end
|
||||
if sendIndex == 2 then SendPollutionStats() end
|
||||
if sendIndex == 3 then
|
||||
SendKillStats()
|
||||
SendPlayerEntityStats()
|
||||
end
|
||||
if options.senderIndex == 4 then SendFluidProductionStats() end
|
||||
if options.senderIndex == 5 then SendBuildStats() end
|
||||
if options.senderIndex == 6 then
|
||||
if sendIndex == 4 then SendFluidProductionStats() end
|
||||
if sendIndex == 5 then SendBuildStats() end
|
||||
if sendIndex == 6 then
|
||||
SendResearchStats()
|
||||
SendCombinatorMetrics()
|
||||
end
|
||||
if options.senderIndex == 7 then SendLogisticStats() end
|
||||
if options.senderIndex == 8 then SendPowerStats() end
|
||||
if options.senderIndex == 9 then SendGameStats() end
|
||||
if options.senderIndex == 10 then SendTrainStats() end
|
||||
if sendIndex == 7 then SendLogisticStats() end
|
||||
if sendIndex == 8 then SendPowerStats() end
|
||||
if sendIndex == 9 then SendGameStats() end
|
||||
if sendIndex == 10 then SendTrainStats() end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user