Module:TrapRecipe

From Outward Wiki
Jump to navigation Jump to search
Template-info.svg Documentation

Module used by Template:TrapRecipe.


local p = {}

function p.main(frame)
    if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end
	
	local items = ''
	for i,arg in ipairs(args) do
		items = items .. arg .. ','
	end
	
	-- store in cargo table
	
	frame:callParserFunction{ 
		name='#cargo_store', 
		args = 
		{
			'_table=TrapRecipes',
			trapname = args.trapname,
			basetrap = args.basetrap,
			effects = args.effects,
			ingredients = items
		}
	}
	
	local out = ''
	
	-- "Armed With" table
	
	out = out .. '==Arming==\n'
	out = out .. '{| class="wikitable sortable"\n'
	out = out .. '|+Armed With\n'
	
	for i,arg in ipairs(args) do
		out = out .. '|[[File:' .. arg .. '.png|frameless|53x53px]]\n'
		out = out .. '|[[' .. arg .. ']]\n'
		out = out .. '|-\n'
	end
    
    out = out .. '|}\n\n'
    
    -- "Effects"
    
    out = out .. '==Effects==\n'
    out = out .. args.effects
    
    return frame:preprocess(out)
end

function p.addIfNotNil(obj,valueToAdd)
    if (valueToAdd ~= nil and valueToAdd ~= "") then 
        obj = obj + tonumber(valueToAdd) 
    end
    return obj
end

function p.valueOrEmpty(val,emptyVal)
	if (val == nil) then
		return ""
	else
    	return (val ~= 0 and string.format("%.0f",val) or (emptyVal ~= nil and emptyVal or ""))
	end
end

return p