Module:Infobox tekgram boss list

De ARK Wiki
Aller à la navigation Aller à la recherche
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, "Le premier paramètre doit être un objet permettant de lister les Bosses")
	local itemToFind = f.args[1]:lower()
	
	local creatures = {}
	local creatureNames = {}
    for _, row in ipairs(mw.ext.cargo.query('Tekgrams', '_pageName, Difficulty, Items', {
        limit = 50,
    })) do
    	for item, _ in mw.ustring.gmatch(row.Items..',', "(.-),%s*") do
    		if item:lower() == itemToFind then
    			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
    			break
    		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