feat(navne): egne bygningsnavne fra ADSmartPickup_names.xml bruges overalt (FS25 kan ikke omdøbe bygninger); marksilo: siloer i samme klynge som et gårdlager er gårdens (v1.39.0.0)

This commit is contained in:
2026-09-27 15:05:14 +02:00
parent 7e0a991ce6
commit 9a284c875e
9 changed files with 114 additions and 3 deletions
+45
View File
@@ -0,0 +1,45 @@
-- AD Names
-- Egne bygningsnavne (FS25 kan ikke omdøbe bygninger): ADSmartPickup_names.xml i savegame-mappen,
-- <ADSmartPickupNames><building id="placeable…" name="Gårdsilo 10"/></ADSmartPickupNames>.
-- Moden læser filen og skriver den aldrig — spillerens/Claudes navne overlever. Bruges af alle navneopslag.
ADNames = {}
ADNames.FILE_NAME = "ADSmartPickup_names.xml"
ADNames.ROOT = "ADSmartPickupNames"
ADNames.byId = nil
-- records = {{id, name}} -> {[id] = name}; tomme/ugyldige springes over
function ADNames.fromRecords(records)
local byId = {}
for _, record in ipairs(records or {}) do
local id, name = record.id, record.name
if type(id) == "string" and id ~= "" and type(name) == "string" and name:match("%S") then byId[id] = name end
end
return byId
end
function ADNames.load()
ADNames.byId = {}
local path = ADRunsStorage ~= nil and ADRunsStorage.getPath() or nil
if path == nil then return end
path = path:gsub(ADRunsStorage.FILE_NAME .. "$", ADNames.FILE_NAME)
if not fileExists(path) then return end
local xmlFile = XMLFile.load("ADSmartPickupNames", path)
if xmlFile == nil then return end
local records = {}
xmlFile:iterate(ADNames.ROOT .. ".building", function(_, key)
table.insert(records, {id = xmlFile:getString(key .. "#id"), name = xmlFile:getString(key .. "#name")})
end)
xmlFile:delete()
ADNames.byId = ADNames.fromRecords(records)
local count = 0
for _ in pairs(ADNames.byId) do count = count + 1 end
Logging.info("ADSmartPickup: %d egne bygningsnavne indlæst", count)
end
-- Eget navn for bygningen (placeable), ellers nil.
function ADNames.forPlaceable(placeable)
if placeable == nil or placeable.uniqueId == nil then return nil end
if ADNames.byId == nil then pcall(ADNames.load) end
return (ADNames.byId or {})[tostring(placeable.uniqueId)]
end