Private
Public Access
1
0

Added logistics, small fixes and cleanup

This commit is contained in:
Jan Grießhaber
2025-12-30 00:15:38 +01:00
parent dc3aea982e
commit 0facba95d6
6 changed files with 73 additions and 44 deletions

View File

@@ -3,13 +3,17 @@ require("production-stats")
require("pollution-stats")
require("research-stats")
require("power-stats")
require("logistic-network-stats")
require("storage")
tickInterval = tonumber(settings.global["factorio-prometheus-exporter-tick-interval"].value) or 300
udpAddress = tonumber(settings.startup["factorio-prometheus-exporter-udp-address"].value) or 52555
serverIndex = 1
isInitialized = false
sendIndex = 0
script.on_init(function ()
storage.electricGrids = {}
storage.researchedTechnologies = {}
storage.playerDeathCount = {}
end)
@@ -18,36 +22,25 @@ script.on_load(function ()
log("factorio-prometheus-exporter: on_load")
log("tickInterval: "..tickInterval)
log("udpAddress: "..udpAddress)
end)
-- Register the handler for the player movement event
--script.on_event(defines.events.on_player_changed_position, on_player_moved)
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_player_joined_game, function(event)
local player = game.get_player(event.player_index)
if not player then return end
local index = event.player_index
helpers.send_udp(udpAddress, ("player-join %s %d"):format(player.name, player.index),index)
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)
function SendStats(event)
if(event.tick % (tickInterval) ~= 0) then
return
end
SendProductionStats()
SendFluidProductionStats()
SendPollutionStats()
@@ -56,9 +49,6 @@ end
function SendGameStats(event)
if(event.tick % (tickInterval*2) ~= 0) then
return
end
local returnParts = {}
returnParts[#returnParts+1] = GetMods()
returnParts[#returnParts+1] = GetMapSeed()
@@ -69,15 +59,29 @@ function SendGameStats(event)
end
function SendAll(event)
SendStats(event)
SendGameStats(event)
if(isInitialized == false) then
if game.is_multiplayer() then
serverIndex = 0
end
else
serverIndex = 1
end
isInitialized = true
if (event.tick % math.floor(tickInterval/4) ~= 0) then return end
sendIndex = (sendIndex % 5) + 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(event.tick % tickInterval*2 == 0) then SendGameStats(event) end
end
--script.on_event(defines.events.on_player_joined_game, on_player_joined)
--script.on_nth_tick(300, SendSurfaceStats)
--script.on_event(defines.events.on_tick, SendSurfaceStats)
script.on_event(defines.events.on_tick, SendAll)
--script.on_nth_tick(tickInterval*2, SendGameStats)