From 76f51c7be7390240d5b5539972a6318976244e32 Mon Sep 17 00:00:00 2001 From: masterdraco Date: Tue, 29 Sep 2026 21:02:10 +0200 Subject: [PATCH] =?UTF-8?q?fix(flows):=20udk=C3=B8rselsregler=20vises=20ku?= =?UTF-8?q?n=20n=C3=A5r=20en=20vare=20bruger=20dem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rent lager-flow viste 'sælg fra 90 %' / 'pris >= 90 %' selv om det aldrig sælger. Guidens Regler-trin, resuméet og statuslinjen viser nu kun salgsgrænser ved salg og lagergrænsen ved lager (v1.60.11.0). --- FS25_ADSmartPickup/adFlowGuide.lua | 27 +++++++++++++------ FS25_ADSmartPickup/adFlowView.lua | 12 +++++++++ FS25_ADSmartPickup/gui/SmartPickupFlowTab.lua | 6 ++++- FS25_ADSmartPickup/l10n/l10n_da.xml | 2 ++ FS25_ADSmartPickup/l10n/l10n_en.xml | 2 ++ FS25_ADSmartPickup/modDesc.xml | 2 +- tests/test_adFlowGuide.lua | 20 ++++++++++++-- tests/test_adFlowView.lua | 14 ++++++++++ 8 files changed, 73 insertions(+), 12 deletions(-) diff --git a/FS25_ADSmartPickup/adFlowGuide.lua b/FS25_ADSmartPickup/adFlowGuide.lua index 7f0f5f7..393be4c 100644 --- a/FS25_ADSmartPickup/adFlowGuide.lua +++ b/FS25_ADSmartPickup/adFlowGuide.lua @@ -327,15 +327,23 @@ local function rowsStore(guide) return rows end +local function productPolicies(draft) + local policies = {} + for _, product in ipairs(draft.products or {}) do table.insert(policies, product.policy) end + return policies +end + +-- Kun regler varernes politik bruger: rent lager-flow viser ikke salgsgrænser og omvendt (in-game 29/9). local function rowsRules(guide) local draft = guide.draft if isOut(guide) then - return { - choice("sellAtPercent", L("spu_sellAt"), percentOptions(ADRuns.MIN_SELL_AT_PERCENT, ADRuns.MAX_SELL_AT_PERCENT, 5), draft.sellAtPercent), - choice("storeAbovePercent", L("spu_storeAbove"), percentOptions(ADRuns.MIN_STORE_ABOVE_PERCENT, ADRuns.MAX_STORE_ABOVE_PERCENT, 5), draft.storeAbovePercent), - choice("sellAbovePercent", L("spu_sellAbove"), sellAboveOptions(), draft.sellAbovePercent), - toggle("collectRound", L("spu_collectRound"), draft.collectRound), - } + local sells, stores = ADFlowView.policyUse(productPolicies(draft)) + local rows = {} + if sells then table.insert(rows, choice("sellAtPercent", L("spu_sellAt"), percentOptions(ADRuns.MIN_SELL_AT_PERCENT, ADRuns.MAX_SELL_AT_PERCENT, 5), draft.sellAtPercent)) end + if stores then table.insert(rows, choice("storeAbovePercent", L("spu_storeAbove"), percentOptions(ADRuns.MIN_STORE_ABOVE_PERCENT, ADRuns.MAX_STORE_ABOVE_PERCENT, 5), draft.storeAbovePercent)) end + if sells then table.insert(rows, choice("sellAbovePercent", L("spu_sellAbove"), sellAboveOptions(), draft.sellAbovePercent)) end + table.insert(rows, toggle("collectRound", L("spu_collectRound"), draft.collectRound)) + return rows end local loops = {{label = L("spu_loops_infinite"), value = 0}} for count = 1, ADRuns.MAX_LOOPS do table.insert(loops, {label = T(tostring(count)), value = count}) end @@ -479,8 +487,11 @@ local SUMMARY = { rules = function(guide) local draft = guide.draft if isOut(guide) then - local parts = {L("spu_guide_flow_sumSellAt", {draft.sellAtPercent}), L("spu_guide_flow_sumStoreAbove", {draft.storeAbovePercent})} - if (draft.sellAbovePercent or 0) > 0 then table.insert(parts, L("spu_guide_flow_sumSellAbove", {draft.sellAbovePercent})) end + local sells, stores = ADFlowView.policyUse(productPolicies(draft)) + local parts = {} + if sells then table.insert(parts, L("spu_guide_flow_sumSellAt", {draft.sellAtPercent})) end + if stores then table.insert(parts, L("spu_guide_flow_sumStoreAbove", {draft.storeAbovePercent})) end + if sells and (draft.sellAbovePercent or 0) > 0 then table.insert(parts, L("spu_guide_flow_sumSellAbove", {draft.sellAbovePercent})) end if draft.collectRound then table.insert(parts, L("spu_guide_flow_sumRound")) end return parts end diff --git a/FS25_ADSmartPickup/adFlowView.lua b/FS25_ADSmartPickup/adFlowView.lua index dceed79..0894119 100644 --- a/FS25_ADSmartPickup/adFlowView.lua +++ b/FS25_ADSmartPickup/adFlowView.lua @@ -177,6 +177,18 @@ ADFlowView.LEVEL_COLORS = { } -- s = {running, total, stopped, canStop, warning, reason, lastStartFailed} -> "running"|"waiting"|"error"|"stopped" +-- Hvilke udkørselsregler betyder noget for varernes politik? policies = {"store"|"sell"|"sellElseStore"|"off"} +-- -> sells, stores. Ingen varer med salg/lager endnu = begge (reglerne kan sættes før varerne vælges). +function ADFlowView.policyUse(policies) + local sells, stores = false, false + for _, policy in ipairs(policies or {}) do + if policy == "sell" or policy == "sellElseStore" then sells = true end + if policy == "store" or policy == "sellElseStore" then stores = true end + end + if not sells and not stores then return true, true end + return sells, stores +end + function ADFlowView.flowStatus(s) if s.stopped then return "stopped" end if s.warning ~= nil then return "error" end diff --git a/FS25_ADSmartPickup/gui/SmartPickupFlowTab.lua b/FS25_ADSmartPickup/gui/SmartPickupFlowTab.lua index a663e5f..fee4e0f 100644 --- a/FS25_ADSmartPickup/gui/SmartPickupFlowTab.lua +++ b/FS25_ADSmartPickup/gui/SmartPickupFlowTab.lua @@ -49,7 +49,11 @@ function SmartPickupFrame:flowCells(adEnv, run) end local rule if row.kind == "outbound" then - rule = string.format(i18n:getText("spu_flow_ruleOut"), row.sellAtPercent or 90, row.storeAbovePercent or 80) + local sells, stores = ADFlowView.policyUse(row.policies) + local parts = {} + if sells then table.insert(parts, string.format(i18n:getText("spu_flow_ruleSell"), row.sellAtPercent or 90)) end + if stores then table.insert(parts, string.format(i18n:getText("spu_flow_ruleStore"), row.storeAbovePercent or 80)) end + rule = table.concat(parts, ", ") if row.collectRound then rule = rule .. ", " .. i18n:getText("spu_flow_round") end else rule = row.loops ~= nil and row.loops > 0 and string.format(i18n:getText("spu_flow_ruleInLoops"), row.loops) or i18n:getText("spu_flow_ruleIn") diff --git a/FS25_ADSmartPickup/l10n/l10n_da.xml b/FS25_ADSmartPickup/l10n/l10n_da.xml index 7f0a983..21cd4fa 100644 --- a/FS25_ADSmartPickup/l10n/l10n_da.xml +++ b/FS25_ADSmartPickup/l10n/l10n_da.xml @@ -349,6 +349,8 @@ + + diff --git a/FS25_ADSmartPickup/l10n/l10n_en.xml b/FS25_ADSmartPickup/l10n/l10n_en.xml index 52baf98..aacf6bc 100644 --- a/FS25_ADSmartPickup/l10n/l10n_en.xml +++ b/FS25_ADSmartPickup/l10n/l10n_en.xml @@ -349,6 +349,8 @@ + + diff --git a/FS25_ADSmartPickup/modDesc.xml b/FS25_ADSmartPickup/modDesc.xml index 349ec19..e024abf 100644 --- a/FS25_ADSmartPickup/modDesc.xml +++ b/FS25_ADSmartPickup/modDesc.xml @@ -1,7 +1,7 @@ masterdraco - 1.60.10.0 + 1.60.11.0 <en>AD Smart Pickup</en> diff --git a/tests/test_adFlowGuide.lua b/tests/test_adFlowGuide.lua index 25decc4..7fe3e1a 100644 --- a/tests/test_adFlowGuide.lua +++ b/tests/test_adFlowGuide.lua @@ -214,8 +214,9 @@ check("FL11 fra tom", partText(lineFor(sumOut, "buildings")), "spu_guide_flow_no check("FL11 varer", partText(lineFor(sumOut, "goods")), "spu_policy_store") check("FL11 varenavn foran", lineFor(sumOut, "goods").parts[1].prefix, "Mælk: ") check("FL11 lager auto", partText(lineFor(sumOut, "store")), "spu_guide_sum_auto") -check("FL11 regler", partText(lineFor(sumOut, "rules")), "spu_guide_flow_sumSellAt,spu_guide_flow_sumStoreAbove,spu_guide_flow_sumRound") -check("FL11 sælg 95", lineFor(sumOut, "rules").parts[1].args[1], 95) +-- varen er kun "lager": salgsgrænsen vises ikke (in-game 29/9) +check("FL11 regler (kun lager)", partText(lineFor(sumOut, "rules")), "spu_guide_flow_sumStoreAbove,spu_guide_flow_sumRound") +check("FL11 lager over", lineFor(sumOut, "rules").parts[1].args[1], 80) check("FL11 ingen traktorer", partText(lineFor(sumOut, "tractors")), "spu_guide_flow_sumNoTractors") local manyGoods = FG.summary(FG.choose(FG.choose(FG.choose(supply, "ingredientMode", "manual"), "ingredients", {item = "HAY", on = true}), "ingredients", {item = "STRAW", on = true})) check("FL12 valgte varer", partText(lineFor(manyGoods, "goods")), "=Hø + Halm") @@ -294,5 +295,20 @@ check("WG9 husket vogn i kladden", reopened.draft.wagons.s2, "w2") check("WG9 ny solo tager ikke den huskede", FG.choose(reopened, "vehicleIds", {item = "s1", on = true}).draft.wagons.s1, "w1") check("WG9 kladden kopierer (run urørt)", (function() local g = FG.choose(reopened, "wagon", {item = "s2", value = "w1"}); return remembered.wagons.s2 end)(), "w2") + +-- regler: kun de relevante for varernes politik +local storeOnly = FG.open(newRun("outbound", {products = {{fillType = "MILK", policy = "store"}}}), ctx()) +local function keys(rows) local r = {} for _, row in ipairs(rows) do if row.id then table.insert(r, row.id) end end return table.concat(r, ",") end +check("RL1 kun lager: ingen salgsvalg", keys(FG.rows(at(storeOnly, "rules"))), "storeAbovePercent,collectRound") +local sellOnly = FG.open(newRun("outbound", {products = {{fillType = "MILK", policy = "sell"}}}), ctx()) +check("RL2 kun salg: ingen lagervalg", keys(FG.rows(at(sellOnly, "rules"))), "sellAtPercent,sellAbovePercent,collectRound") +local function ruleKeys(guide) + for _, line in ipairs(FG.summary(guide)) do + if line.step == "rules" then local r = {} for _, p in ipairs(line.parts) do table.insert(r, p.key) end return table.concat(r, ",") end + end +end +check("RL3 resumé kun lager", ruleKeys(storeOnly), "spu_guide_flow_sumStoreAbove") +check("RL4 resumé kun salg", ruleKeys(sellOnly), "spu_guide_flow_sumSellAt") + print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1) diff --git a/tests/test_adFlowView.lua b/tests/test_adFlowView.lua index ba92bb5..3dab2b1 100644 --- a/tests/test_adFlowView.lua +++ b/tests/test_adFlowView.lua @@ -87,5 +87,19 @@ check("FVwrap intet ord tabt", table.concat(wrapped, " "):gsub("%s+", " "):gsub( check("FVwrap kort tekst", V.wrapText("Kort", 30)[1], "Kort") check("FVwrap langt ord deles ikke", V.wrapText("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 10)[1], "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") + +-- salgs-/lagerregler vises kun når en vare bruger dem (in-game 29/9: 'sell from 90 %' på et rent lager-flow) +local sells, stores = ADFlowView.policyUse({"store"}) +check("politik: kun lager -> sælger ikke", sells, false) +check("politik: kun lager -> lagrer", stores, true) +sells, stores = ADFlowView.policyUse({"sell"}) +check("politik: kun salg", tostring(sells) .. tostring(stores), "truefalse") +sells, stores = ADFlowView.policyUse({"sellElseStore", "off"}) +check("politik: sælg ellers lager -> begge", tostring(sells) .. tostring(stores), "truetrue") +sells, stores = ADFlowView.policyUse({}) +check("politik: ingen varer endnu -> vis begge", tostring(sells) .. tostring(stores), "truetrue") +sells, stores = ADFlowView.policyUse({"off"}) +check("politik: kun fra -> vis begge", tostring(sells) .. tostring(stores), "truetrue") + print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1)