Module:Crafting cost

From The Cycle: Frontier Wiki
Revision as of 21:50, 31 May 2023 by VeryGreatFrog (talk | contribs) (Initial module)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This module returns a formatted (using Template:Item list) list of an item's crafting cost, if any.

Use the wrapper template Template:Crafting cost to use this module.

Usage

Pass the item you want the list for as the first argument, like so:

 {{Crafting cost|Combat Helmet}} 

Which gives:

If an item does not have a crafting recipe, it will look like this:

Lua error: This item does not have a crafting cost.

Attachments

Since attachments share their in game name, you must pass the rarity as the second argument if that attachment has multiple variants. Attachments without multiple variants do not require this argument.

{{Crafting cost|Medium Extended|Uncommon}}

Which gives, as expected: Lua error: This item does not have a crafting cost.

Nesting

It is possible to make the resulting Item list nested one level deep. To do so, add nested=yes to the template parameters.


local p = {} --p stands for package

p.loadedData = mw.loadJsonData( "Module:Item infobox/itemData.json" )

local args = mw.getCurrentFrame().args

for k, v in pairs(p.loadedData) do
    if args[1] == v["inGameName"] then
        p.data = p.loadedData[k]
        break
    end
end

function p.main( frame )
     local div = mw.html.create( "div" )
     
     local cost = p.data['cost']
     if cost == nil then
     	error('This item does not have a crafting cost', 0)
     	return;
     end
     local craftCost = cost['CraftingStation']
     if craftCost == nil then
     	error('This item does not have a crafting cost', 0)
		return
     end
     
    local data = {}
    for c, d in pairs(craftCost['items']) do
    	table.insert(data, d['inGameName'])
    	table.insert(data, d['amount'])
    end

    local timeString = '\n*' .. frame:expandTemplate{ title = 'Time', args = { craftCost['time'] } }
    return  frame:expandTemplate{ title = 'Item list', args = data } .. timeString
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.