From cdc2bc2a0f8828d3487413f2afa661797537e243 Mon Sep 17 00:00:00 2001 From: Timmeey86 Date: Sat, 6 Jul 2024 17:07:21 +0200 Subject: [PATCH] properly fix #37 the previous revision would only work if roller crimping data had been initialized before triggering weed suppression for the first time. --- .vscode/settings.json | 1 + modDesc.xml | 6 +++--- scripts/settings/RollerCrimpingData.lua | 19 ++++++++++++------- scripts/specializations/CoverCropUtils.lua | 9 +++++---- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e7395f3..2a6edaa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,5 @@ { + "editor.renderWhitespace": "all", "Lua.diagnostics.globals": [ "g_currentMission", "FieldDensityMap", diff --git a/modDesc.xml b/modDesc.xml index 6890bc1..61fc6a9 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -1,7 +1,7 @@ Farmsim Tim (timmeey86) - 1.0.1.6 + 1.0.1.7 <en>Conservation Agriculture</en> <de>Regenerative Landwirschaft</de> @@ -46,7 +46,7 @@ If you do find issues or weird behaviour, please create an issue at https://gith Special thanks to Matthias, FS Gentleman and Cookie Cat for help and ideas provided to make this mod possible. Changelog: -v1.0.1.6: +v1.0.1.7: - Fixed an issue where weed suppression would cause lua errors on mod maps with incomplete fruit types v1.0.1.4: @@ -116,7 +116,7 @@ Wenn du Probleme oder seltsames Verhalten feststellst, berichte das Problem bitt Besonderen Dank an Matthias, FS Gentleman und Cookie Cat für Tips und Ideen, durch die diese Mod möglich wurde. Changelog: -v1.0.1.6: +v1.0.1.7: - Ein Problem wurde behoben, bei dem die Unkrautunterdrückung auf Karten mit unvollständigen Fruchtdefinitionen zu Lua Fehlern führte. v1.0.1.4: diff --git a/scripts/settings/RollerCrimpingData.lua b/scripts/settings/RollerCrimpingData.lua index cee2618..87597e0 100644 --- a/scripts/settings/RollerCrimpingData.lua +++ b/scripts/settings/RollerCrimpingData.lua @@ -11,9 +11,9 @@ function RollerCrimpingData.new() return self end ----Initializes forage data based on the provided table of fruit types +---Initializes forage data based on the provided table of fruit types. This is an internal function, do not call it outside of this class ---@param fruitTypes table @Provides information about growth states of fruit types -function RollerCrimpingData:init(fruitTypes) +function RollerCrimpingData:internalInit(fruitTypes) self.forageableStatesPerFruit = {} for index, fruitDescription in pairs(fruitTypes) do -- For grains and anything else not specially handled: allow from "half grown" (rounded down) to the last state before "ready to harvest" @@ -43,15 +43,20 @@ function RollerCrimpingData:init(fruitTypes) end end ----Provides fast lookup of the growth states which allow roller crimping ----@param fruitTypeIndex integer @The index of the fruit type in the global list of fruit types ----@return table @A pair of minimum and maximum growth states indexed by "min" and "max" -function RollerCrimpingData:getForageableStates(fruitTypeIndex) +---Performs a one time initialization of this class. It is safe to call this method more than once +function RollerCrimpingData:initializeIfNecessary() if not self.isInitialized then -- Perform a one-time initialization the first time it is required. This makes sure mods which come much later in the alphabet have -- already registered all their fruit types - self:init(g_fruitTypeManager:getFruitTypes()) + self:internalInit(g_fruitTypeManager:getFruitTypes()) self.isInitialized = true end +end + +---Provides fast lookup of the growth states which allow roller crimping +---@param fruitTypeIndex integer @The index of the fruit type in the global list of fruit types +---@return table @A pair of minimum and maximum growth states indexed by "min" and "max" +function RollerCrimpingData:getForageableStates(fruitTypeIndex) + self:initializeIfNecessary() return self.forageableStatesPerFruit[fruitTypeIndex] or { min = nil, max = nil } end \ No newline at end of file diff --git a/scripts/specializations/CoverCropUtils.lua b/scripts/specializations/CoverCropUtils.lua index 29fd09a..afb96e4 100644 --- a/scripts/specializations/CoverCropUtils.lua +++ b/scripts/specializations/CoverCropUtils.lua @@ -241,12 +241,13 @@ function CoverCropUtils.mulchAndFertilizeCoverCrops(implement, workArea, groundS FruitType.POPLAR } -- Avoid mod conflicts with mods which add fruit types without adding density maps - local wheatFruitType = g_fruitTypeManager:getFruitTypeByName("WHEAT") + g_rollerCrimpingData:initializeIfNecessary() + local wheatFruitType = g_fruitTypeManager:getFruitTypeByName("WHEAT") for _, desc in pairs(g_fruitTypeManager:getFruitTypes()) do - -- Note about the fourth check: SwathingAddon sets the wheat density map for all fruit types which don't have a density map, but we still need to ignore such fruit types - -- => We ignore them if they use the wheat density map but are in fact a different fruit type + -- Note about the fourth check: SwathingAddon sets the wheat density map for all fruit types which don't have a density map, but we still need to ignore such fruit types + -- => We ignore them if they use the wheat density map but are in fact a different fruit type if desc.terrainDataPlaneId == nil or desc.startStateChannel == nil or desc.numStateChannels == nil - or (desc.terrainDataPlaneId == wheatFruitType.terrainDataPlaneId and desc.index ~= wheatFruitType.index) then + or (desc.terrainDataPlaneId == wheatFruitType.terrainDataPlaneId and desc.index ~= wheatFruitType.index) then excludedFruitTypes[desc.index] = true end