feat(marker): visningsregler for fanen Marker

This commit is contained in:
2026-09-25 21:49:53 +02:00
parent 1aecc382e3
commit f39dbe249b
2 changed files with 68 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
-- AD Field View
-- Rene regler for fanen Marker: hvilke marker vises (slåafgrøder som standard), rækkefølge og
-- statusord. GUI'et oversætter nøglerne.
ADFieldView = {}
function ADFieldView.rows(infos, fieldsById, showAll)
local rows = {}
for _, info in ipairs(infos or {}) do
if showAll or info.mowable then
table.insert(rows, {info = info, field = fieldsById[info.id] or ADFieldModel.newField(info.id)})
end
end
table.sort(rows, function(a, b) return a.info.id < b.info.id end)
return rows
end
function ADFieldView.hiddenCount(infos, showAll)
if showAll then return 0 end
local hidden = 0
for _, info in ipairs(infos or {}) do
if not info.mowable then hidden = hidden + 1 end
end
return hidden
end
function ADFieldView.statusKey(field, info)
if info.markerId == nil then
return "spu_field_noMarker"
end
return "spu_field_stage_" .. tostring(field.stage)
end
+36
View File
@@ -0,0 +1,36 @@
-- Kør: luajit tests/test_adFieldView.lua (fra repo-roden)
dofile("FS25_ADSmartPickup/adFieldModel.lua")
dofile("FS25_ADSmartPickup/adFieldView.lua")
local V = ADFieldView
local failures = 0
local function check(name, actual, expected)
if actual == expected then print("OK " .. name) else
failures = failures + 1
print(string.format("FAIL %s: forventede %s, fik %s", name, tostring(expected), tostring(actual)))
end
end
local infos = {
{id = 109, mowable = true, markerId = 5},
{id = 12, mowable = true, markerId = nil},
{id = 90, mowable = false, markerId = 7},
}
local fields = {[109] = ADFieldModel.newField(109), [12] = ADFieldModel.newField(12)}
-- V1: kun slåafgrøder, sorteret efter nummer
local rows = V.rows(infos, fields, false)
check("V1 to rækker", #rows, 2)
check("V1 sorteret", rows[1].info.id, 12)
check("V1 model med", rows[2].field.id, 109)
-- V2: vis alle tager resten med; mangler model -> ny standardmark
local all = V.rows(infos, fields, true)
check("V2 tre rækker", #all, 3)
check("V2 standardmodel", all[2].field.stage, "idle")
check("V2 skjulte", V.hiddenCount(infos, false), 1)
check("V2 vis alle skjuler intet", V.hiddenCount(infos, true), 0)
-- V3: status — manglende markør vinder over trin
check("V3 mangler markør", V.statusKey(fields[12], infos[2]), "spu_field_noMarker")
check("V3 trin", V.statusKey(fields[109], infos[1]), "spu_field_stage_idle")
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1)