From fe101ccd2673298f1225c72dd97f6469ba1fabb3 Mon Sep 17 00:00:00 2001 From: notnotmelon Date: Tue, 28 May 2024 12:02:03 -0500 Subject: [PATCH] Frozen (#50) * pyPP better error messaging * Fix crash * Error handling v2 * Disable dev & cache mode that was accidentally enabled * Error handling v3 * Error handling v4 * Stop ftmk compaining * volcanoes --------- Co-authored-by: Alex ten Brink --- changelog.txt | 3 ++- data-final-fixes.lua | 34 ++++++++++++++---------- data.lua | 2 +- prototypes/config.lua | 2 ++ prototypes/functions/auto_tech.lua | 37 +++++++++++++-------------- prototypes/functions/fz_topo_sort.lua | 16 ++++++++---- 6 files changed, 55 insertions(+), 39 deletions(-) diff --git a/changelog.txt b/changelog.txt index 8411e0b..b90e913 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,8 @@ --------------------------------------------------------------------------------------------------- Version: 0.2.24 Date: 2024-??-?? - Bugfixes: + Changes: + - Whenever pyPP encounters a dependency cycle, it will now print the items involved in the cycle to the logs. - Fix productivity blacklist being overly general and including recipes like empty barrels --------------------------------------------------------------------------------------------------- Version: 0.2.23 diff --git a/data-final-fixes.lua b/data-final-fixes.lua index 5cf300e..270ce35 100644 --- a/data-final-fixes.lua +++ b/data-final-fixes.lua @@ -240,18 +240,26 @@ if dev_mode then science_packs[pack.name or pack[1]] = true end - add_science_pack_dep(tech, 'utility-science-pack', 'military-science-pack') - - if mods['pyalienlife'] then - add_science_pack_dep(tech, 'utility-science-pack', 'py-science-pack-4') - add_science_pack_dep(tech, 'production-science-pack', 'py-science-pack-3') - add_science_pack_dep(tech, 'chemical-science-pack', 'py-science-pack-2') - add_science_pack_dep(tech, 'logistic-science-pack', 'py-science-pack-1') - add_science_pack_dep(tech, 'py-science-pack-4', 'military-science-pack') - end - - if mods['pyalternativeenergy'] then - add_science_pack_dep(tech, 'production-science-pack', 'military-science-pack') + if mods.pystellarexpedition then + for i = 1, #config.SCIENCE_PACKS - 1 do + local pack = config.SCIENCE_PACKS[i] + local next = config.SCIENCE_PACKS[i + 1] + add_science_pack_dep(tech, next, pack) + end + else + add_science_pack_dep(tech, 'utility-science-pack', 'military-science-pack') + + if mods['pyalienlife'] then + add_science_pack_dep(tech, 'utility-science-pack', 'py-science-pack-4') + add_science_pack_dep(tech, 'production-science-pack', 'py-science-pack-3') + add_science_pack_dep(tech, 'chemical-science-pack', 'py-science-pack-2') + add_science_pack_dep(tech, 'logistic-science-pack', 'py-science-pack-1') + add_science_pack_dep(tech, 'py-science-pack-4', 'military-science-pack') + end + + if mods['pyalternativeenergy'] then + add_science_pack_dep(tech, 'production-science-pack', 'military-science-pack') + end end end @@ -298,7 +306,7 @@ for _, tech in pairs(data.raw.technology) do tech_ingredients_to_use[pack] = ingredient.amount or ingredient[2] end end - + -- Add any missing ingredients that we want present for _, ingredient in pairs(config.TC_TECH_INGREDIENTS_PER_LEVEL[highest_science_pack]) do tech_ingredients_to_use[ingredient.name or ingredient[1]] = ingredient.amount or ingredient[2] diff --git a/data.lua b/data.lua index 5d991af..f2fc12a 100644 --- a/data.lua +++ b/data.lua @@ -1,4 +1,4 @@ -pypp_registered_cache_files = {} +_G.pypp_registered_cache_files = {} -- Usage example (add in data-updates phase): -- register_cache_file({"pycoalprocessing", "pyfusionenergy"}, "__pyfusionenergy__/cached-configs/pycoalprocessing+pyfusionenergy.lua") diff --git a/prototypes/config.lua b/prototypes/config.lua index f5dba15..81e5b9b 100644 --- a/prototypes/config.lua +++ b/prototypes/config.lua @@ -113,6 +113,8 @@ if mods.pystellarexpedition then end config.STARTING_ITEMS:add('ice') config.STARTING_ITEMS:add('silicate-stone') + config.STARTING_ITEMS:add('cobalt-ore') + config.STARTING_ITEMS:add('organic-nexelit') end if mods['pyalternativeenergy'] then diff --git a/prototypes/functions/auto_tech.lua b/prototypes/functions/auto_tech.lua index aeef8e5..469d1ba 100644 --- a/prototypes/functions/auto_tech.lua +++ b/prototypes/functions/auto_tech.lua @@ -121,30 +121,30 @@ function auto_tech:run() sp_ts:run() local fg2 = fg:copy() - local error_found + local error_message - error_found, ts = self:topo_sort_with_sp(fg, spg, parser.science_packs) + error_message, ts = self:topo_sort_with_sp(fg, spg, parser.science_packs) if error_message then - local msg = '\n\nERROR: Dependency loop detected\n' .. error_message + local msg = "\n\nERROR: Dependency loop detected\n" .. error_message error(msg) end self:add_original_prerequisites(fg, fg2, ts.level) - error_found, ts = self:topo_sort_with_sp(fg2, spg, parser.science_packs) + error_message, ts = self:topo_sort_with_sp(fg2, spg, parser.science_packs) if error_message then - local msg = '\n\nERROR: Dependency loop detected\n' .. error_message + local msg = "\n\nERROR: Dependency loop detected\n" .. error_message error(msg) end local tg = self:extract_tech_graph(fg2) local tech_ts = fz_topo.create(tg) - error_found = tech_ts:run(false, false) + error_message = tech_ts:run(false, false) if error_message then - local msg = '\n\nERROR: Dependency loop detected\n' .. error_message + local msg = "\n\nERROR: Dependency loop detected\n" .. error_message error(msg) end @@ -154,11 +154,11 @@ function auto_tech:run() -- Set science pack order for _, node in pairs(spg.nodes) do - science_pack_order(node.name, string.format('%03d-%06d', sp_ts.level[node.key] or 0, ts.level[node.key])) + science_pack_order(node.name, string.format("%03d-%06d", sp_ts.level[node.key] or 0, ts.level[node.key])) local sp = data.raw.tool[node.name] - sp.subgroup = 'science-pack' - sp.order = string.format('%03d-%06d', sp_ts.level[node.key] or 0, ts.level[node.key]) + sp.subgroup = "science-pack" + sp.order = string.format("%03d-%06d", sp_ts.level[node.key] or 0, ts.level[node.key]) sp_level[node.name] = sp_ts.level[node.key] or 0 if sp_level[sp.name] > max_level then @@ -305,23 +305,22 @@ function auto_tech:topo_sort_with_sp(fg, sp_graph, science_packs) end local ts = fz_topo.create(fg) - local error_found = ts:run(false, self.verbose_logging) - - for _, link in pairs(sp_links) do - fg:remove_link(link.from, link.to, link.from.name) - end + local error_found, errors = ts:run(false, self.verbose_logging) if error_found then - log("RESTARTING without SP links") + log('RESTARTING WITHOUT SP LINKS') + for _, link in pairs(sp_links) do + fg:remove_link(link.from, link.to, link.from.name) + end ts = fz_topo.create(fg) - error_found = ts:run(false, self.verbose_logging) + error_found, errors = ts:run(false, self.verbose_logging) end local error_message if error_found then - error_message = '' + error_message = "" for key, _ in pairs(errors) do - error_message = error_message .. key .. '\n' + error_message = error_message .. key .. "\n" end end diff --git a/prototypes/functions/fz_topo_sort.lua b/prototypes/functions/fz_topo_sort.lua index ac487c8..aa03a8a 100644 --- a/prototypes/functions/fz_topo_sort.lua +++ b/prototypes/functions/fz_topo_sort.lua @@ -24,6 +24,7 @@ end function fz_topo:run(check_ancestry, logging) self.queue(self.work_graph.start_node) self.level[self.work_graph.start_node.key] = 1 + local recipes_with_issues = {} while not queue.is_empty(self.queue) do local node = self.queue() @@ -88,16 +89,21 @@ function fz_topo:run(check_ancestry, logging) self.queue(to_node) self.level[to_node.key] = self.level[node.key] + 1 if logging then log(" - Queued: " .. to_key) end - elseif logging then - log(" - Not queued: " .. to_key) - for _, e in self.work_graph:iter_links_to(to_node) do - log(" - " .. e:from() .. " : " .. e.label) + recipes_with_issues[to_key] = nil + else + recipes_with_issues[to_key] = true + if logging then + log(" - Not queued: " .. to_key) + for _, e in self.work_graph:iter_links_to(to_node) do + log(" - " .. e:from() .. " : " .. e.label) + end end end end end - return table.any(self.graph.nodes, function (n) return not n.ignore_for_dependencies and not self.sorted[n.key] end) + local has_error = table.any(self.graph.nodes, function (n) return not n.ignore_for_dependencies and not self.sorted[n.key] end) + return has_error, recipes_with_issues end