Module:Card: Difference between revisions
ReisuDesign (talk | contribs) No edit summary |
No edit summary |
||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 6: | Line 6: | ||
local TemplateData = require('Module:TemplateData') | local TemplateData = require('Module:TemplateData') | ||
local array = require('Module:Array') | local array = require('Module:Array') | ||
local CentralData = require('Module:CentralData') | |||
local allData = | local allData = CentralData.dataSheets | ||
local CARD_ARGS = { | local CARD_ARGS = { | ||
| Line 56: | Line 28: | ||
name = 'quality', | name = 'quality', | ||
alias = 'rarity', | alias = 'rarity', | ||
default = ' | default = 'Common', | ||
}, | }, | ||
{ | { | ||
| Line 114: | Line 86: | ||
alias = 'UP', | alias = 'UP', | ||
type = '1', | type = '1', | ||
}, | }, | ||
{ | { | ||
| Line 130: | Line 99: | ||
return p._main(args) | return p._main(args) | ||
end | |||
local function getDataByName(dataType, dataTable, name) | |||
local data = dataTable[name] | |||
if data then | |||
return data | |||
end | |||
local normalizedType = tostring(dataType or ''):lower() | |||
if normalizedType == 'neighbor' or normalizedType == 'neighbors' then | |||
return nil | |||
end | |||
for quality, names in pairs(dataTable) do | |||
if type(names) == 'table' then | |||
for _, itemName in ipairs(names) do | |||
if itemName == name then | |||
return { | |||
quality = quality | |||
} | |||
end | |||
end | |||
end | |||
end | |||
return nil | |||
end | end | ||
| Line 141: | Line 137: | ||
if lib.isEmpty(requestedType) or dataType == requestedType then | if lib.isEmpty(requestedType) or dataType == requestedType then | ||
local data = dataTable | local data = getDataByName(dataType, dataTable, name) | ||
if data then | if data then | ||
| Line 176: | Line 172: | ||
if lib.isEmpty(quality) then | if lib.isEmpty(quality) then | ||
quality = ' | quality = 'Common' | ||
end | end | ||
| Line 201: | Line 197: | ||
name = tostring(name or '') | name = tostring(name or '') | ||
local size = mini and 56 | local size = mini and 74 or 56 | ||
return '[[File:' .. | return '[[File:' .. | ||
| Line 231: | Line 227: | ||
-- Base name for assets. | -- Base name for assets. | ||
-- Removes a trailing disambiguation such as "(Currency)". | -- Removes a trailing disambiguation such as "(Currency)". | ||
out.image_name = out.name:gsub('%s*%([^()]*%)$', '') | out.image_name = out.name--:gsub('%s*%([^()]*%)$', '') | ||
-- Boolean parameters | -- Boolean parameters | ||
| Line 269: | Line 265: | ||
if not (out.nonDefaults and out.nonDefaults.quality) then | if not (out.nonDefaults and out.nonDefaults.quality) then | ||
out.quality = out.data.quality | out.quality = out.data.quality | ||
end | end | ||
end | end | ||
| Line 387: | Line 375: | ||
if isSplit then | if isSplit then | ||
node_container:addClass(' | node_container:addClass('card-split-card') | ||
end | end | ||
| Line 414: | Line 402: | ||
-- Split or regular image | -- Split or regular image | ||
if isSplit then | if isSplit then | ||
imageContainer:addClass(' | imageContainer:addClass('card-split-image') | ||
-- First item: top-left half | -- First item: top-left half | ||
imageContainer:tag('span') | imageContainer:tag('span') | ||
:addClass(' | :addClass('card-split-half') | ||
:addClass(' | :addClass('card-split-half-a') | ||
:wikitext(a.image_wikitext) | :wikitext(a.image_wikitext) | ||
-- Second item: bottom-right half | -- Second item: bottom-right half | ||
imageContainer:tag('span') | imageContainer:tag('span') | ||
:addClass(' | :addClass('card-split-half') | ||
:addClass(' | :addClass('card-split-half-b') | ||
:wikitext(makeSplitIcon(a.split, a.mini)) | :wikitext(makeSplitIcon(a.split, a.mini)) | ||
else | else | ||
imageContainer:wikitext(a.image_wikitext) | imageContainer:wikitext(a.image_wikitext) | ||
end | end | ||