feat(gui): markens lagervalg viser markørnavn og afstand, marksilo/gæringssilo først, kun de 8 nærmeste (34 ens Farma-rækker) (v1.29.5.0)

This commit is contained in:
2026-09-26 17:37:10 +02:00
parent 1b0a2c152b
commit 77253b5d2b
6 changed files with 83 additions and 8 deletions
+33
View File
@@ -46,3 +46,36 @@ function ADFieldView.cropText(info, getText)
if info.kind == "bare" then return getText("spu_field_bare") end
return tostring(info.cropTitle or "-")
end
-- Lagervalget for en mark: marksilo først, så gæringssiloer, så efter afstand. Valgte, marksiloer og
-- gæringssiloer vises altid; af resten kun de `limit` nærmeste (34 ens "Farma 500"-rækker var ulæselige).
-- entries = {{id, distance, fieldSilo, fermenter, chosen}}.
function ADFieldView.storeRows(entries, limit)
local sorted = {}
for _, entry in ipairs(entries or {}) do table.insert(sorted, entry) end
local function rank(e) return e.fieldSilo and 0 or (e.fermenter and 1 or 2) end
table.sort(sorted, function(a, b)
if rank(a) ~= rank(b) then return rank(a) < rank(b) end
if (a.distance or math.huge) ~= (b.distance or math.huge) then return (a.distance or math.huge) < (b.distance or math.huge) end
return tostring(a.id) < tostring(b.id)
end)
local rows, others, hidden = {}, 0, 0
for _, entry in ipairs(sorted) do
if entry.chosen or entry.fieldSilo or entry.fermenter then
table.insert(rows, entry)
elseif others < limit then
others = others + 1
table.insert(rows, entry)
else
hidden = hidden + 1
end
end
return rows, hidden
end
-- "90 m" / "1,4 km"
function ADFieldView.distanceText(meters)
if meters == nil then return "?" end
if meters < 1000 then return string.format("%d m", math.floor(meters + 0.5)) end
return (string.gsub(string.format("%.1f km", meters / 1000), "%.", ","))
end