Skip to content

Commit c4e70b4

Browse files
py.global_prerequisite_replacer (#151)
1 parent 0a3e32e commit c4e70b4

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Date: ????
99
- Fix a crash with Schall Machine Scaling
1010
- Fixed a crash when cleaning up recycling recipes created by quality that had no results. Resolves https://github.com/pyanodon/pybugreports/issues/1284
1111
- Added process to automatically set spoil level of spoilable items. Resolves https://github.com/pyanodon/pybugreports/issues/1260
12+
- Added py.global_prerequisite_replacer
13+
- Updated metas LuaLS
1214
---------------------------------------------------------------------------------------------------
1315
Version: 3.0.39
1416
Date: 2025-09-15

lib/data-stage.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,34 @@ py.global_item_replacer = function(old, new, blackrecipe)
328328
end
329329
end
330330

331+
---replaces every instance of the old prerequesite with the new one. if the new one is omitted, removes the old prerequesite instead
332+
---@param old string
333+
---@param new? string
334+
py.global_prerequisite_replacer = function(old, new)
335+
if not data.raw.technology[old] then
336+
log("WARNING @ py.global_prerequisite_replacer(): Technology " .. old .. " does not exist")
337+
return
338+
end
339+
if new and not data.raw.technology[new] then
340+
log("WARNING @ py.global_prerequisite_replacer(): Technology " .. new .. " does not exist")
341+
return
342+
end
343+
if new then
344+
for _, tech in pairs(data.raw.technology) do
345+
for i, prereq in pairs(tech.prerequisites or {}) do
346+
if prereq == old then
347+
tech.prerequisites[i] = new
348+
break
349+
end
350+
end
351+
end
352+
else -- no need to do fancy checks, just remove it
353+
for tech in pairs(data.raw.technology) do
354+
TECHNOLOGY(tech):remove_prereq(old)
355+
end
356+
end
357+
end
358+
331359
---adds a small icon to the top right corner of a recipe
332360
---@param recipe data.RecipePrototype
333361
---@param corner table

0 commit comments

Comments
 (0)