(added dependencies of resources which use other resources) |
(skip empty arguments) |
||
Line 43: | Line 43: | ||
-- test all given resources and set station to true if needed and station is not already on true |
-- test all given resources and set station to true if needed and station is not already on true |
||
for _,res in ipairs(args) do |
for _,res in ipairs(args) do |
||
+ | if res ~= '' then |
||
− | for station,_ in pairs(dependencies) do |
||
− | + | for station,_ in pairs(dependencies) do |
|
− | stations[station] |
+ | if not stations[station] and p.inTable(dependencies[station], res) then |
+ | stations[station] = true |
||
+ | end |
||
end |
end |
||
end |
end |
Revision as of 11:18, 28 October 2015
Documentation
[purge]
Displays a list of needed crafting stations needed to craft the given resources.
Parameter
craftedin
: station that is needed to craft the item- Resources as list, separated by |
Usage
{{RequiredCraftingStations|<resources>}} {{RequiredCraftingStations|craftedin=<station>|<resources>}}
Example
{{RequiredCraftingStations|Narcotic|Metal Ingot}}
Refining Forge
Mortar And Pestle
{{RequiredCraftingStations|craftedin=Fabricator|Narcotic|Metal Ingot}}
local p = {}
function p.neededstations( f )
local args = f:getParent().args
local stations = {["Campfire"] = false, ["Mortar And Pestle"] = false, ["Refining Forge"] = false, ["Preserving Bin"] = false, ["Smithy"] = false, ["Fabricator"] = false}
local dependencies = {
["Campfire"] = {
"Charcoal",
"Cooked Meat",
"Cooked Prime Meat",
"Gunpowder"
},
["Mortar And Pestle"] = {
"Sparkpowder",
"Narcotic",
"Gunpowder",
"Stimulant",
"Cementing Paste",
"Bug Repellant",
"Polymer"
},
["Refining Forge"] = {
"Metal Ingot",
"Gasoline",
"Electronics"
},
["Preserving Bin"] = {
"Cooked Meat Jerky",
"Prime Meat Jerky"
},
["Smithy"] = {
},
["Fabricator"] = {
"Electronics",
"Polymer"
}
}
-- check if item itself needs a station to be crafted in. if yes, set to true
if args.craftedin ~= nil and stations[args.craftedin] ~= nil then
stations[args.craftedin] = true
end
-- test all given resources and set station to true if needed and station is not already on true
for _,res in ipairs(args) do
if res ~= '' then
for station,_ in pairs(dependencies) do
if not stations[station] and p.inTable(dependencies[station], res) then
stations[station] = true
end
end
end
end
local returnTable = {}
for station, needed in pairs(stations) do
if needed then
table.insert(returnTable,'[[File:'..station..'.png|30px]] [['..station..']]')
end
end
return table.concat(returnTable,'<br/>')
end
function p.inTable(tbl, item)
for _, value in pairs(tbl) do
if string.lower(value) == string.lower(item) then return true end
end
return false
end
return p