Private
Public Access
1
0

Fixed options

This commit is contained in:
Jan Grießhaber
2026-01-02 00:50:58 +01:00
parent 9256d2d317
commit d803bce9d3
7 changed files with 201 additions and 31 deletions

View File

@@ -10,6 +10,19 @@ udpAddress = tonumber(settings.startup["factorio-prometheus-exporter-udp-address
isInitialized = false
sendIndex = 0
options = {
enableMod = false,
enablePlayers = false,
enableProduction = false,
enableFluid = false,
enableKills = false,
enablePollution = false,
enableRobots = false,
enableResearch = false,
enablePower = false,
enableTrains = false
}
script.on_init(function ()
storage.electricGrids = {}
@@ -18,38 +31,101 @@ script.on_init(function ()
storage.totalLabCount = 0
storage.totalResearchSpeed = 0
storage.totalReseachProductivity = 0
storage.labs = {}
sendIndex = 0
options.enableMod = settings.global["factorio-prometheus-exporter-exporter_enable"].value
options.enableProduction = settings.global["factorio-prometheus-exporter-export_production_stats"].value
options.enablePollution = settings.global["factorio-prometheus-exporter-export_pollution_stats"].value
options.enableFluid = settings.global["factorio-prometheus-exporter-export_fluid_stats"].value
options.enablePlayers = settings.global["factorio-prometheus-exporter-export_player_stats"].value
options.enableKills = settings.global["factorio-prometheus-exporter-export_kill_stats"].value
options.enablePower = settings.global["factorio-prometheus-exporter-export_power_stats"].value
options.enableResearch = settings.global["factorio-prometheus-exporter-export_research_stats"].value
options.enableRobots = settings.global["factorio-prometheus-exporter_export_logistic_stats"].value
end)
script.on_load(function ()
log("factorio-prometheus-exporter: on_load")
log("tickInterval: "..tickInterval)
log("udpAddress: "..udpAddress)
options.enableMod = settings.global["factorio-prometheus-exporter-exporter_enable"].value
options.enableProduction = settings.global["factorio-prometheus-exporter-export_production_stats"].value
options.enablePollution = settings.global["factorio-prometheus-exporter-export_pollution_stats"].value
options.enableFluid = settings.global["factorio-prometheus-exporter-export_fluid_stats"].value
options.enablePlayers = settings.global["factorio-prometheus-exporter-export_player_stats"].value
options.enableKills = settings.global["factorio-prometheus-exporter-export_kill_stats"].value
options.enablePower = settings.global["factorio-prometheus-exporter-export_power_stats"].value
options.enableResearch = settings.global["factorio-prometheus-exporter-export_research_stats"].value
options.enableRobots = settings.global["factorio-prometheus-exporter_export_logistic_stats"].value
end)
script.on_configuration_changed(function()
storage.electricGrids = storage.electricGrids or {}
storage.labs = storage.labs or {}
storage.playerDeathCount = storage.playerDeathCount or {}
storage.researchedTechnologies = storage.researchedTechnologies or {}
storage.totalLabCount = storage.totalLabCount or 0
storage.totalReseachProductivity = storage.totalReseachProductivity or 0
storage.totalResearchSpeed = storage.totalResearchSpeed or 0
end
)
-- Register the handler for the player movement event
script.on_event(defines.events.on_player_died, function(event)
local player = game.get_player(event.player_index)
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
end)
script.on_event(defines.events.on_runtime_mod_setting_changed, function(event)
log("Mod setting changed: "..event.setting)
if event.setting == "factorio-prometheus-exporter-tick-interval" then
tickInterval = settings.global["factorio-prometheus-exporter-tick-interval"].value
end
end
if event.setting == "factorio-prometheus-exporter-enable" then
options.enableMod = settings.global["factorio-prometheus-exporter-enable"].value
end
if event.setting == "factorio-prometheus-exporter-export_production_stats" then
options.enableProduction = settings.global["factorio-prometheus-exporter-export_production_stats"].value
end
if event.setting == "factorio-prometheus-exporter-export_fluid_stats" then
options.enableFluid = settings.global["factorio-prometheus-exporter-export_fluid_stats"].value
end
if event.setting == "factorio-prometheus-exporter-export_pollution_stats" then
options.enablePollution = settings.global["factorio-prometheus-exporter-export_pollution_stats"].value
end
if event.setting == "factorio-prometheus-exporter-export_power_stats" then
options.enablePower = settings.global["factorio-prometheus-exporter-export_power_stats"].value
end
if event.setting == "factorio-prometheus-exporter-export_logistic_stats" then
options.enableRobots = settings.global["factorio-prometheus-exporter-export_logistic_stats"].value
end
if event.setting == "factorio-prometheus-exporter-export_player_stats" then
options.enablePlayers = settings.global["factorio-prometheus-exporter-export_player_stats"].value
end
if event.setting == "factorio-prometheus-exporter-export_kill_stats" then
options.enableKills = settings.global["factorio-prometheus-exporter-export_kill_stats"].value
end
if event.setting == "factorio-prometheus-exporter-export_research_stats" then
options.enableResearch = settings.global["factorio-prometheus-exporter-export_research_stats"].value
end
end)
function SendStats(event)
SendProductionStats()
SendFluidProductionStats()
SendPollutionStats()
SendKillStats()
end
script.on_event(defines.events.on_player_died, function(event)
--local player = game.get_player(event.player_index)
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
end)
function SendGameStats(event)
local returnParts = {}
@@ -62,6 +138,7 @@ function SendGameStats(event)
end
function SendAll(event)
if(isInitialized == false) then
if game.is_multiplayer() then
serverIndex = 0
@@ -71,21 +148,42 @@ function SendAll(event)
end
isInitialized = true
if PowerGridScanned == false then
GenerateNetworks()
end
if (event.tick % math.floor(tickInterval/6) ~= 0) then return end
if LabsScanned == false then
GenerateLabInfo()
end
sendIndex = (sendIndex % 6) + 1
if options.enableMod==true then
if (event.tick % math.floor(tickInterval/7) ~= 0) then return end
sendIndex = (sendIndex % 7) + 1
if sendIndex == 1 then SendProductionStats() end
if sendIndex == 2 then SendPollutionStats() end
if sendIndex == 3 then SendKillStats() end
if sendIndex == 4 then SendFluidProductionStats() end
if sendIndex == 5 then SendBuildStats() end
if sendIndex == 6 then SendResearchStats() end
if sendIndex == 7 then SendLogisticStats() end
if(event.tick % tickInterval*2 == 0) then SendGameStats(event) end
if(event.tick % tickInterval*2 == 0) then
if options.enablePlayers then
SendGameStats(event) end
end
end
end
script.on_event(defines.events.on_tick, SendAll)
--Script hooks for power stats
script.on_event(defines.events.on_built_entity,UpdateGrids,{{filter = "type", type = "electric-pole"}})
script.on_event(defines.events.on_player_mined_entity, PurgeNetworks,{{filter = "type", type = "electric-pole"}})
script.on_event(defines.events.on_robot_built_entity,UpdateGrids,{{filter = "type", type = "electric-pole"}})
script.on_event(defines.events.on_robot_mined_entity,PurgeNetworks,{{filter = "type", type = "electric-pole"}})