Private
Public Access
1
0

Update version to 0.2.1, add player color retrieval, and enhance train trip statistics

Performance improvments for power stats
This commit is contained in:
Jan Grießhaber
2026-01-04 01:37:25 +01:00
parent 9b608fc412
commit f40e219a2e
8 changed files with 108 additions and 15 deletions

View File

@@ -1,7 +1,11 @@
function AddPowerPole(event)
local e = event.entity
if e and e.valid and e.type == "electric-pole" then
if e then
storage.representativePoles[e.unit_number] = e
-- Update cache with new network
if e.electric_network_id then
storage.networkCache[e.electric_network_id] = e
end
end
end
@@ -9,31 +13,40 @@ function RemovePowerPole(event)
local e = event.entity
if e then
storage.representativePoles[e.unit_number] = nil
-- Invalidate cache - force rebuild to find new representative if needed
storage.networkCache = nil
end
end
function GetNetworks()
-- Return cached networks if available, otherwise rebuild
if storage.networkCache then
return storage.networkCache
end
local networks = {}
for _, pole in pairs(storage.representativePoles) do
if pole.valid then
local net = pole.electric_network_id
if net then
networks[net] = pole
local netID = pole.electric_network_id
if netID then
networks[netID] = pole
end
end
end
storage.networkCache = networks
return networks
end
function ScanNetworks()
storage.representativePoles = {}
storage.networkCache = {}
for _, surface in pairs(game.surfaces) do
for _, pole in pairs(surface.find_entities_filtered{type = "electric-pole"}) do
if pole.valid and pole.electric_network_id then
storage.representativePoles[pole.unit_number] = pole
storage.networkCache[pole.electric_network_id] = pole
end
end
end