Module:Card: Difference between revisions
ReisuDesign (talk | contribs) No edit summary |
No edit summary |
||
| (8 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 185: | Line 181: | ||
value = tostring(value or '') | value = tostring(value or '') | ||
-- Converts "Luca: Myriad Meadows" to "Myriad Meadows" | -- Converts "Luca: Myriad Meadows" to "Myriad Meadows". | ||
return mw.text.trim(value:gsub('^.-:%s*', '', 1)) | return mw.text.trim(value:gsub('^.-:%s*', '', 1)) | ||
end | end | ||
| Line 197: | Line 193: | ||
end | end | ||
-- Generates | -- Generates the second icon for a split card. | ||
local function makeSplitIcon(name, mini) | local function makeSplitIcon(name, mini) | ||
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 208: | Line 203: | ||
' Icon.png|' .. | ' Icon.png|' .. | ||
size .. 'x' .. size .. | size .. 'x' .. size .. | ||
'px|link=' .. name .. | 'px|link=' .. | ||
name .. | |||
']]' | ']]' | ||
end | end | ||
| Line 229: | Line 225: | ||
) | ) | ||
-- Base name for assets | -- Base name for assets. | ||
out.image_name = out.name:gsub('%s*%([^()]*%)$', '') | -- Removes a trailing disambiguation such as "(Currency)". | ||
out.image_name = out.name--:gsub('%s*%([^()]*%)$', '') | |||
-- Boolean parameters | -- Boolean parameters | ||
| Line 268: | 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 319: | Line 308: | ||
end | end | ||
-- Caption | -- Caption defaults | ||
if out.show_caption and lib.isEmpty(out.caption) then | if out.show_caption and lib.isEmpty(out.caption) then | ||
if out.data then | if out.data then | ||
| Line 379: | Line 368: | ||
function p._main(args) | function p._main(args) | ||
local a = p._processArgs(args) | local a = p._processArgs(args) | ||
local isSplit = ne(a.split) | local isSplit = ne(a.split) | ||
-- Outer container | |||
local node_container = mw.html.create('div') | local node_container = mw.html.create('div') | ||
:addClass('card-container') | :addClass('card-container') | ||
if isSplit then | if isSplit then | ||
node_container:addClass('card-split-card') | |||
end | end | ||
| Line 419: | Line 395: | ||
end | end | ||
-- Main image | -- Main image container | ||
local imageContainer = node_card:tag('span') | local imageContainer = node_card:tag('span') | ||
:addClass('card-image-container') | :addClass('card-image-container') | ||
:addClass('card-quality-' .. a.quality) | :addClass('card-quality-' .. a.quality) | ||
-- Split or regular image | |||
if isSplit then | if isSplit then | ||
imageContainer:addClass(' | imageContainer:addClass('card-split-image') | ||
-- 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 | |||
imageContainer:tag('span') | imageContainer:tag('span') | ||
:addClass(' | :addClass('card-split-half') | ||
:addClass(' | :addClass('card-split-half-b') | ||
:wikitext(makeSplitIcon(a.split)) | :wikitext(makeSplitIcon(a.split, a.mini)) | ||
else | else | ||
imageContainer:wikitext(a.image_wikitext) | imageContainer:wikitext(a.image_wikitext) | ||
end | end | ||
| Line 490: | Line 454: | ||
-- Caption | -- Caption | ||
-- Split captions are opt-in and use spans instead of list items. | |||
if a.show_caption and isSplit then | if a.show_caption and isSplit then | ||
local node_caption = node_container:tag('span') | local node_caption = node_container:tag('span') | ||
:addClass('card-caption') | :addClass('card-caption') | ||
:addClass('card-split-caption') | :addClass('card-split-caption') | ||
local list = node_caption:tag('span') | local list = node_caption:tag('span') | ||
:addClass('card-split-caption-list') | :addClass('card-split-caption-list') | ||
list:tag('span') | list:tag('span') | ||
:addClass('card-split-caption-item') | :addClass('card-split-caption-item') | ||
:wikitext('[[' .. a.name .. ']]') | :wikitext('[[' .. a.name .. ']]') | ||
list:tag('span') | list:tag('span') | ||
:addClass('card-split-caption-item') | :addClass('card-split-caption-item') | ||
:wikitext('[[' .. a.split .. ']]') | :wikitext('[[' .. a.split .. ']]') | ||
setCaptionWidth(node_caption, a.caption_width) | setCaptionWidth(node_caption, a.caption_width) | ||
elseif a.show_caption and ne(a.caption) then | elseif a.show_caption and ne(a.caption) then | ||
local node_caption = node_container:tag('span') | local node_caption = node_container:tag('span') | ||
:addClass('card-caption') | :addClass('card-caption') | ||
if a.no_link or lib.isEmpty(a.final_link) then | if a.no_link or lib.isEmpty(a.final_link) then | ||
node_caption:wikitext(a.caption) | node_caption:wikitext(a.caption) | ||
| Line 519: | Line 484: | ||
) | ) | ||
end | end | ||
setCaptionWidth(node_caption, a.caption_width) | setCaptionWidth(node_caption, a.caption_width) | ||
end | end | ||
| Line 528: | Line 493: | ||
function p.templateData(frame) | function p.templateData(frame) | ||
return TemplateData.templateData(CARD_ARGS, { | return TemplateData.templateData(CARD_ARGS, { | ||
description = 'Creates an item-style card with image, quality, label | description = 'Creates an item-style card with image, quality, label, split images, modifiers, and optional data-driven icons.', | ||
format = 'inline' | format = 'inline' | ||
}, frame) | }, frame) | ||