Module:Infobox tekgram boss list

From ARK Wiki
Jump to navigation Jump to search
Template-info.png Documentation

local p = {}

local DifficultyLevels = {
	Gamma = 1, Beta = 2, Alpha = 3,
}
local AnyUnrolled = {'Gamma', 'Beta', 'Alpha'}


local function sortByStaticOrder(a, b)
	return DifficultyLevels[a] < DifficultyLevels[b]
end


function p.render(f)
	assert(f.args[1] ~= nil, "First parameter must be an item name to list bosses for")
	local itemToFind = f.args[1]
	
	local creatures = {}
	local creatureNames = {}
    for _, row in ipairs(mw.ext.cargo.query('Tekgrams', '_pageName, Difficulty', {
    	where = 'Items HOLDS \''..itemToFind..'\'',
        limit = 50,
    })) do
    	if creatures[row._pageName] == nil then
    		creatures[row._pageName] = {}
    		creatureNames[#creatureNames+1] = row._pageName
    	end
    	local rowDifficulty = row.Difficulty or ""
    	for difficulty, _ in mw.ustring.gmatch(rowDifficulty..',', "(.-),%s*") do
    		if difficulty == "" then
    			creatures[row._pageName] = {}
    		elseif difficulty == "Any" then
    			creatures[row._pageName] = AnyUnrolled
    		elseif DifficultyLevels[difficulty] then
	    		table.insert(creatures[row._pageName], difficulty)
	    	end
    	end
    end
    
    if #creatureNames > 0 then
	    local out = {}
	    table.sort(creatureNames)
	    for _, creature in ipairs(creatureNames) do
	    	local difficulties = creatures[creature]
	    	table.sort(difficulties, sortByStaticOrder)
	    	out[#out+1] = '<li>'
	    	out[#out+1] = f:expandTemplate{ title = 'ItemLink', args = {creature} }
	    	if #difficulties > 0 and #difficulties ~= #AnyUnrolled then
		    	out[#out+1] = " ''("
		    	out[#out+1] = table.concat(difficulties, ', ')
		    	out[#out+1] = ")''"
	    	end
	    	out[#out+1] = '</li>'
	    end
    	return '<ul class="itemlist">' .. table.concat(out) .. '</ul>'
    end
    
    return nil
end


return p