Module:DispStructCostList

De Anvil Empires Wiki
Aller à la navigation Aller à la recherche
Template-info.svg Documentation
The above documentation is transcluded from Module:DispStructCostList/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 codeNameData = {}
	local codeNameList = {}
	if(args.BuildCost) then
		--Extract our codename and cost prefix from the format 'CodeNameString:PrefixCost,CodeNameString:PrefixCost', ect
		for item in args.BuildCost:gmatch("[^,]+") do
        	local codeName, quantity = item:match("(%a+):(%d+)")
        	if codeName and quantity then
        		codeNameData[codeName] = codeNameData[codeName] or {}
				codeNameData[codeName].prefix = quantity
				
				table.insert(codeNameList, "'" .. codeName .. "'")
			end
		end
		--If we have valid data parse that and our query through to the DispItemList module to return our build ItemDisp HTML
		if next(codeNameData) ~= nil then
			local itemQuery = {
            	tables = 'itemdata',
            	fields = 'CodeNameString,IsReleasedAndEnabled',
            	optionals = {where = "CodeNameString IN (" .. table.concat(codeNameList, ", ") .. ")"}
        	}
			return require('Module:DispItemList').main({codeNames = codeNameData, query = itemQuery})
		end
	end
end
return p