Module:DispItemList

From Anvil Empires Wiki
Jump to navigation Jump to search
Template-info.svg Documentation
The above documentation is transcluded from Module:DispItemList/doc.[edit | history | purge]

local p = {}
function p.main(frame)
	local args = frame
	if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end
	
	local itemDisps = {}
	
	--Check we have our existing codeNames and query tables input
	if(args.codeNames and args.query) then
		local result = mw.ext.cargo.query(args.query.tables, args.query.fields, args.query.optionals)
		if(#result == 0) then
        	return 'No matching items'
		end
    
         --Loop through our query results 
        for i, row in ipairs(result) do
        	local codeName = row['CodeNameString']
        	local prefix = args.codeNames[codeName].prefix
        	
        	if row['IsReleasedAndEnabled'] ~= '0' then 
        		local itemDisp = frame:expandTemplate{
                    title = 'ItemDisp',
                    args = {codeName, prefix}
                }
            	if itemDisp ~= '' then
            		itemDisps[#itemDisps + 1] = itemDisp
            	end
        	end
        end
        
        --Export our HTML elements for the ItemDisp
        if #itemDisps > 0 then
        	return table.concat(itemDisps, "<br>")
        else
        	return 'Failed to format items'
        end
	end
end
return p