Skip to content

Commit ec809a5

Browse files
committed
Recipe loader now prints less errors into the console
1 parent ab58579 commit ec809a5

1 file changed

Lines changed: 69 additions & 34 deletions

File tree

Scripts/RecipeLoader.lua

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
dofile("$CONTENT_40639a2c-bb9f-4d4f-b88c-41bfe264ffa8/Scripts/ModDatabase.lua")
2-
ModDatabase.unloadDescriptions()
3-
ModDatabase.loadDescriptions()
42

53
if not cmi_hideout_trader_storage then
64
cmi_hideout_trader_storage = {}
@@ -86,42 +84,79 @@ function cmi_update_all_crafters()
8684
cmi_update_crafters(cmi_crafter_object_storage, "cl_updateRecipeGrid")
8785
end
8886

89-
local _json_file_exists = sm.json.fileExists
87+
local function cmi_get_all_loaded_mods()
88+
--Unload everything in case the function is called again
89+
ModDatabase.unloadDescriptions()
90+
ModDatabase.unloadShapesets()
91+
ModDatabase.unloadToolsets()
92+
93+
ModDatabase.loadDescriptions()
94+
ModDatabase.loadShapesets()
95+
ModDatabase.loadToolsets()
96+
97+
local v_loaded = {}
98+
99+
for localId, shapesets in pairs(ModDatabase.databases.shapesets) do
100+
if ModDatabase.isModLoaded(localId) then
101+
v_loaded[localId] = true
102+
end
103+
end
104+
105+
--Add tool mods into the list of loaded mods
106+
for localId, toolsets in pairs(ModDatabase.databases.toolsets) do
107+
if v_loaded[localId] == nil then
108+
if ModDatabase.isModLoaded(localId) then
109+
v_loaded[localId] = true
110+
end
111+
end
112+
end
113+
114+
--Exclude custom games from the list
115+
for localId, _ in pairs(v_loaded) do
116+
if ModDatabase.databases.descriptions[localId].type == "Custom Game" then
117+
v_loaded[localId] = nil
118+
end
119+
end
120+
121+
return v_loaded
122+
end
123+
90124
function initialize_crafting_recipes()
91125
local l_craftbot_recipes = { "$SURVIVAL_DATA/CraftingRecipes/craftbot.json" }
92126
local l_workbench_recipes = { "$SURVIVAL_DATA/CraftingRecipes/workbench.json" }
93127
local l_hideout_recipes = { "$SURVIVAL_DATA/CraftingRecipes/hideout.json" }
94-
95-
for mod_uuid, v in pairs(ModDatabase.databases.descriptions) do
96-
if v.type ~= "Custom Game" then
97-
local mod_key = "$CONTENT_"..mod_uuid
98-
99-
local success, fileExists = pcall(_json_file_exists, mod_key)
100-
if success == true and fileExists == true then
101-
local cur_exception = mod_exception_list[mod_uuid]
102-
103-
if cur_exception == nil then
104-
local recipe_folder = mod_key.."/CraftingRecipes/"
105-
106-
is_recipe_file_valid(recipe_folder.."craftbot.json" , l_craftbot_recipes )
107-
is_recipe_file_valid(recipe_folder.."workbench.json", l_workbench_recipes)
108-
is_recipe_file_valid(recipe_folder.."hideout.json" , l_hideout_recipes )
109-
else
110-
local exc_craftbot = cur_exception.craftbot
111-
local exc_workbench = cur_exception.workbench
112-
local exc_hideout = cur_exception.hideout
113-
114-
if exc_craftbot then
115-
is_recipe_file_valid(mod_key..exc_craftbot, l_craftbot_recipes)
116-
end
117-
118-
if exc_workbench then
119-
is_recipe_file_valid(mod_key..exc_workbench, l_workbench_recipes)
120-
end
121-
122-
if exc_hideout then
123-
is_recipe_file_valid(mod_key..exc_hideout, l_hideout_recipes)
124-
end
128+
129+
local _json_file_exists = sm.json.fileExists
130+
131+
local v_loaded_mods = cmi_get_all_loaded_mods()
132+
for localId, _ in pairs(v_loaded_mods) do
133+
local v_mod_key = "$CONTENT_"..localId
134+
135+
local success, fileExists = pcall(_json_file_exists, v_mod_key)
136+
if success == true and fileExists == true then
137+
local v_cur_exception = mod_exception_list[localId]
138+
139+
if v_cur_exception == nil then
140+
local v_recipe_folder = v_mod_key.."/CraftingRecipes/"
141+
142+
is_recipe_file_valid(v_recipe_folder.."craftbot.json" , l_craftbot_recipes )
143+
is_recipe_file_valid(v_recipe_folder.."workbench.json", l_workbench_recipes)
144+
is_recipe_file_valid(v_recipe_folder.."hideout.json" , l_hideout_recipes )
145+
else
146+
local v_exc_craftbot = v_cur_exception.craftbot
147+
local v_exc_workbench = v_cur_exception.workbench
148+
local v_exc_hideout = v_cur_exception.hideout
149+
150+
if v_exc_craftbot then
151+
is_recipe_file_valid(v_mod_key..v_exc_craftbot, l_craftbot_recipes)
152+
end
153+
154+
if v_exc_workbench then
155+
is_recipe_file_valid(v_mod_key..v_exc_workbench, l_workbench_recipes)
156+
end
157+
158+
if v_exc_hideout then
159+
is_recipe_file_valid(v_mod_key..v_exc_hideout, l_hideout_recipes)
125160
end
126161
end
127162
end

0 commit comments

Comments
 (0)