Модуль:Nav creatures: различия между версиями
Перейти к навигации
Перейти к поиску
HvitCrow (обсуждение | вклад) Нет описания правки |
SuperYwx9 (обсуждение | вклад) Нет описания правки |
||
(не показано 9 промежуточных версий 1 участника) | |||
Строка 2: | Строка 2: | ||
local Utility = require( 'Module:Utility' ) |
local Utility = require( 'Module:Utility' ) |
||
local Arkitecture = require( 'Module:Arkitecture' ) |
|||
local Strings = require( 'Module:Nav creatures/i18n' ) |
local Strings = require( 'Module:Nav creatures/i18n' ) |
||
local ROW_TEMPLATE = '<li class="navbox-creature-item nav-%s" data-name="%s" data-diet="%s" ' |
local ROW_TEMPLATE = '<li class="navbox-creature-item nav-%s" data-name="%s" data-diet="%s" ' |
||
.. 'data-group="%s" data-map="%s"> |
.. 'data-group="%s" data-map="%s">%s</li>' |
||
local MAP_TO_COLOUR = { |
local MAP_TO_COLOUR = { |
||
['The Island'] = 'white', |
['The Island'] = 'white', |
||
Строка 27: | Строка 28: | ||
function p.icons( frame ) |
function p.icons( frame ) |
||
local records = |
local records = Utility.runCachedCargoQuery( 'NavCreatures', { |
||
expiryTime = 60 * 15, |
|||
⚫ | |||
tableName = 'Creatures', |
|||
⚫ | |||
options = { |
|||
where = '(ReleasedMobile IS NULL OR Released IS NOT NULL) AND IsVariant IS FALSE', |
where = '(ReleasedMobile IS NULL OR Released IS NOT NULL) AND IsVariant IS FALSE', |
||
limit = 9999, -- needed or we'll be reading only 50 records |
limit = 9999, -- needed or we'll be reading only 50 records |
||
} |
} |
||
) |
} ) |
||
local cells = {} |
local cells = {} |
||
Строка 49: | Строка 53: | ||
if record.Name then |
if record.Name then |
||
table.insert( cells, string.format( |
table.insert( cells, string.format( |
||
ROW_TEMPLATE, |
|||
record.TaxonomicGroup or '', table.concat( maps, ', ' ), fileName, record.Name, record.Name ) ) |
|||
getColourFromMaps( maps ), |
|||
record.Name, |
|||
record.Diet or '', |
|||
record.TaxonomicGroup or '', |
|||
table.concat( maps, ', ' ), |
|||
Arkitecture.File{ |
|||
name = fileName .. '.png', |
|||
altText = record.Name, |
|||
link = record.Name, |
|||
width = 48, |
|||
fallback = 'Missing.png', |
|||
} |
|||
) ) |
|||
else |
else |
||
-- So... this is kind of f...d but there's a non-variant record with no creature name associated, that's |
-- So... this is kind of f...d but there's a non-variant record with no creature name associated, that's |
Текущая версия от 15:51, 22 апреля 2024
Для документации этого модуля может быть создана страница Модуль:Nav creatures/doc
local p = {}
local Utility = require( 'Module:Utility' )
local Arkitecture = require( 'Module:Arkitecture' )
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">%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, ', ' ),
Arkitecture.File{
name = fileName .. '.png',
altText = record.Name,
link = record.Name,
width = 48,
fallback = 'Missing.png',
}
) )
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