Модуль:Nav creatures

Материал из ARK Wiki
Перейти к навигации Перейти к поиску

Для документации этого модуля может быть создана страница Модуль:Nav creatures/doc

local p = {}

local Utility = require( 'Module:Utility' )
local Strings = require( 'Module:Nav creatures/i18n' )

local ROW_TEMPLATE = '<li class="navbox-creature-item nav-%s" data-name="%s" data-diet="%s" '
				  .. 'data-group="%s" data-map="%s">[[File:%s.png|48px|alt=%s|link=%s]]</li>'
local MAP_TO_COLOUR = {
    ['The Island']          = 'white',
    ['Scorched Earth']      = 'yellow',
    ['Ragnarok']            = 'green',
    ['Aberration']          = 'purple',
    ['Extinction']          = 'orange',
    ['Valguero']            = 'brown',
    ['Genesis: Part 1']     = 'cyan',
    ['Crystal Isles']       = 'pink',
    ['Genesis: Part 2']     = 'red',
    ['Lost Island']         = 'lime',
    ['Fjordur']             = 'yellowish'
}


local function getColourFromMaps( maps )
    return MAP_TO_COLOUR[maps[1]] or 'grey'
end


function p.icons( frame )
    local records = Utility.runCachedCargoQuery( 'NavCreatures', {
    	expiryTime = 60 * 15,
    	tableName = 'Creatures',
    	fields = 'Name, Released, TaxonomicGroup, Diet, DLCs, WildMaps, ' .. table.concat( Strings.HABITAT_FLAGS, ', ' ),
    	options = {
            where = '(ReleasedMobile IS NULL OR Released IS NOT NULL) AND IsVariant IS FALSE',
            limit = 9999, -- needed or we'll be reading only 50 records
        }
    } )

	local cells = {}
    for index = 1, #records do
        local record = records[index]
        local colour = 'white'
        local fileName = record.Name or 'Blank'

        local maps = {}
        for map in string.gmatch( record.DLCs or '', '([^,]+),*' ) do
            maps[#maps+1] = map
        end
        if #maps == 0 then
            maps[1] = 'The Island'
        end

		if record.Name then
        	table.insert( cells, string.format( ROW_TEMPLATE, getColourFromMaps( maps ), record.Name, record.Diet or '',
        	    record.TaxonomicGroup or '', table.concat( maps, ', ' ), fileName, record.Name, record.Name ) )
    	else
    		-- So... this is kind of f...d but there's a non-variant record with no creature name associated, that's
    		-- not exactly a problem /from/ this template but it is a problem elsewhere. Skipping here, but it MUST be
    		-- fixed if you don't want Alex to scream at you at 3am.
    		-- If you landed here cause there's missing creatures that you have articles for, grab a Special:Drilldown
    		-- on the Creatures table and look for missing names, or check the "Creature articles with likely broken
    		-- Dv linkage" maintenance category.
    	end
    end

    return table.concat( cells )
end


return p