Module:Crafting cost: Difference between revisions

From The Cycle: Frontier Wiki
m (add attachment handling)
m (Add support for nesting)
 
Line 27: Line 27:
     return;
     return;
     end
     end
     -- create a list with our data in the format: ["Sample Container", 5, "K-Marks", 4,000]
     -- create a list with our data in the format: {"Sample Container", 5, "K-Marks", 4,000}
     local data = {}
     local data = {}
     local langObject = mw.language.new( 'en' )
     local langObject = mw.language.new( 'en' )
Line 35: Line 35:
     end
     end
-- add the crafting time to the end and return it
-- add the crafting time to the end and return it
     local timeString = '\n*' .. frame:expandTemplate{ title = 'Time', args = { craftCost['time'] } }
local listStars = '*'
-- add nesting if frame.args.nested is true
if frame.args['nested'] == 'true' then
listStars = '**'
data.nested = 'yes'
end
     local timeString = '\n' .. listStars .. frame:expandTemplate{ title = 'Time', args = { craftCost['time'] } }
    --return mw.dumpObject(data)
     return  frame:expandTemplate{ title = 'Item list', args = data } .. timeString
     return  frame:expandTemplate{ title = 'Item list', args = data } .. timeString
end
end


return p
return p

Latest revision as of 15:27, 1 June 2023

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:

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

-- find the item data for our input arg
for k, v in pairs(p.loadedData) do
    if args[1] == v["inGameName"] then
    	if args[2] == nil or args[2] == '' then
        	p.data = p.loadedData[k]
        	break
    	end
    	if args[2] == v["rarity"] then
    		p.data = p.loadedData[k]
        	break
        end
    end
end

function p.main( frame )
	--return mw.dumpObject(args)
	-- fetch our craft data
    local cost = p.data['cost']
    local craftCost = cost['CraftingStation']
	-- verify if this item has this recipe
    if cost == nil or craftCost == nil then
    	error('This item does not have a crafting cost', 0)
    	return;
    end
    -- create a list with our data in the format: {"Sample Container", 5, "K-Marks", 4,000}
    local data = {}
    local langObject = mw.language.new( 'en' )
    for c, d in pairs(craftCost['items']) do
    	table.insert(data, d['inGameName'])
    	table.insert(data, langObject:formatNum(d['amount'] ))
    end
	-- add the crafting time to the end and return it
	local listStars = '*'
	-- add nesting if frame.args.nested is true
	if frame.args['nested'] == 'true' then
		listStars = '**'
		data.nested = 'yes'
	end
    local timeString = '\n' .. listStars .. frame:expandTemplate{ title = 'Time', args = { craftCost['time'] } }
    --return mw.dumpObject(data)
    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.