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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user