Private
Public Access
1
0

Update version to 0.1.22 and improve train name retrieval in GetTrainName function

This commit is contained in:
Jan Grießhaber
2026-01-03 19:49:00 +01:00
parent f25adfcaa3
commit 7dc542e448
2 changed files with 5 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "factorio-metrics-exporter", "name": "factorio-metrics-exporter",
"version": "0.1.21", "version": "0.1.22",
"title": "Prometheus Metrics Exporter", "title": "Prometheus Metrics Exporter",
"author": "Jan Grießhaber", "author": "Jan Grießhaber",
"contact": "jan@griesshaber.systems", "contact": "jan@griesshaber.systems",

View File

@@ -9,10 +9,9 @@ end
---@param train LuaTrain ---@param train LuaTrain
function GetTrainName(train) function GetTrainName(train)
if train.locomotives.front_movers[1] then if train.locomotives.front_movers[1] then
return train.locomotives.front_movers[1].backer_name return train.locomotives.front_movers[1].backer_name or ""
elseif train.locomotives.back_movers[1] then elseif train.locomotives.back_movers[1] then
return train.locomotives.back_movers[1].backer_name return train.locomotives.back_movers[1].backer_name or ""
end
end end
return "" return ""
end end
@@ -167,7 +166,7 @@ function GetTrainStatistics()
local trainParts = {} local trainParts = {}
trainParts[#trainParts+1] = "---train-total-statistics---\n" trainParts[#trainParts+1] = "---train-total-statistics---\n"
for trainID, stat in pairs(storage.trainStats) do for trainID, stat in pairs(storage.trainStats) do
trainParts[#trainParts+1] = ("%s:%s:%d"):format(trainID,GetTrainName(storage.trains[trainID]),stat.totalCargoCount) trainParts[#trainParts+1] = ("%d:%s:%d"):format(trainID,GetTrainName(storage.trains[trainID]),stat.totalCargoCount or 0)
end end
return table.concat(trainParts,"\n") return table.concat(trainParts,"\n")
end end