diff --git a/FS25_ADSmartPickup/adCpBridge.lua b/FS25_ADSmartPickup/adCpBridge.lua index ebeb5a7..6297865 100644 --- a/FS25_ADSmartPickup/adCpBridge.lua +++ b/FS25_ADSmartPickup/adCpBridge.lua @@ -32,10 +32,25 @@ function ADCpBridge.getSpecs(vehicle) return specs end +-- Variabel bredde (Unrealistic Pack m.fl.) først, som Courseplays WorkWidthUtil: AI-markørerne står på +-- grundbredden (læssevogn 2,4 m selv om den er sat til 40,8 m). +local function variableWidth(object) + if object.getVariableWorkWidth == nil then return nil end + local okLeft, left, _, leftValid = pcall(object.getVariableWorkWidth, object, true) + local okRight, right, _, rightValid = pcall(object.getVariableWorkWidth, object) + if okLeft and okRight and leftValid and rightValid and type(left) == "number" and type(right) == "number" then + return math.abs(left) + math.abs(right) + end + return nil +end + function ADCpBridge.getWorkWidth(vehicle) local best = 0 for _, object in ipairs(collect(vehicle)) do - if object.getAIMarkers ~= nil then + local variable = variableWidth(object) + if variable ~= nil then + best = math.max(best, variable) + elseif object.getAIMarkers ~= nil then pcall(function() if object.updateAIMarkerWidth ~= nil then object:updateAIMarkerWidth() end end) local ok, _, _, _, _, width = pcall(object.getAIMarkers, object) if ok and type(width) == "number" and width > best then best = width end diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 7e92ad7..4e9a5d9 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.21.0.0 + 1.21.1.0 <en>AD Smart Pickup</en> diff --git a/docs/BRUGERMANUAL.md b/docs/BRUGERMANUAL.md index 8961369..91b302c 100644 --- a/docs/BRUGERMANUAL.md +++ b/docs/BRUGERMANUAL.md @@ -1,6 +1,6 @@ # AD Smart Pickup — brugermanual -Version 1.21.0 · Farming Simulator 25 · tillæg til AutoDrive +Version 1.21.1 · Farming Simulator 25 · tillæg til AutoDrive *English version: [USER_MANUAL.md](USER_MANUAL.md)* diff --git a/docs/USER_MANUAL.md b/docs/USER_MANUAL.md index 8a1ef87..15f99a8 100644 --- a/docs/USER_MANUAL.md +++ b/docs/USER_MANUAL.md @@ -1,6 +1,6 @@ # AD Smart Pickup — user manual -Version 1.21.0 · Farming Simulator 25 · add-on for AutoDrive +Version 1.21.1 · Farming Simulator 25 · add-on for AutoDrive *Dansk version: [BRUGERMANUAL.md](BRUGERMANUAL.md)* diff --git a/tests/test_adCpBridge.lua b/tests/test_adCpBridge.lua new file mode 100644 index 0000000..002250d --- /dev/null +++ b/tests/test_adCpBridge.lua @@ -0,0 +1,30 @@ +-- Kør: luajit tests/test_adCpBridge.lua (fra repo-roden) +-- Kun getWorkWidth: variabel bredde (Unrealistic Pack) vinder over AI-markørernes grundbredde. +dofile("FS25_ADSmartPickup/adCpBridge.lua") +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 function withMarkers(width) + return {getAIMarkers = function() return 1, 2, 3, 4, width end} +end + +-- W1: læssevogn med variabel bredde 20,4 + 20,4 = 40,8 m, AI-markører siger 2,4 m +local wagon = withMarkers(2.4) +wagon.getVariableWorkWidth = function(_, isLeft) return isLeft and 20.4 or -20.4, nil, true end +local tractor = {getAttachedImplements = function() return {{object = wagon}} end} +check("W1 variabel bredde", ADCpBridge.getWorkWidth(tractor), 40.8) +-- W2: ugyldig variabel bredde -> AI-markører +local plain = withMarkers(9.5) +plain.getVariableWorkWidth = function() return 0, nil, false end +check("W2 AI-markører", ADCpBridge.getWorkWidth(plain), 9.5) +-- W3: selvkørende slåmaskine uden redskaber, kun variabel bredde +local mower = {getVariableWorkWidth = function(_, isLeft) return isLeft and 20.4 or -20.4, nil, true end} +check("W3 selvkørende", ADCpBridge.getWorkWidth(mower), 40.8) + +print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) +os.exit(failures == 0 and 0 or 1)