Editing Module:Card
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| Line 6: | Line 5: | ||
local TemplateData = require('Module:TemplateData') | local TemplateData = require('Module:TemplateData') | ||
local array = require('Module:Array') | local array = require('Module:Array') | ||
local allData = CentralData. | local allData = { | ||
-- {'Neighbor', mw.loadData('Module:CentralData/Neighbors')}, | |||
{'Fish', mw.loadData('Module:CentralData/Fish')}, | |||
{'Insect', mw.loadData('Module:CentralData/Insects')}, | |||
{'Shore-Dweller', mw.loadData('Module:CentralData/Shore-Dwellers')}, | |||
-- {'Furniture', mw.loadData('Module:CentralData/Furniture')}, | |||
{'Item', mw.loadData('Module:CentralData/Items')}, | |||
} | |||
local CARD_ARGS = { | local CARD_ARGS = { | ||
| Line 28: | Line 33: | ||
name = 'quality', | name = 'quality', | ||
alias = 'rarity', | alias = 'rarity', | ||
default = ' | default = 'Gray', | ||
}, | }, | ||
{ | { | ||
name = 'type', | name = 'type', | ||
}, | }, | ||
{ | { | ||
| Line 45: | Line 47: | ||
{ | { | ||
name = 'image_size', | name = 'image_size', | ||
alias = | alias = 'imageSize', | ||
}, | }, | ||
{ | { | ||
name = 'image_ext', | name = 'image_ext', | ||
alias = {'imageExt | alias = {'imageExt', 'extension'}, | ||
default = 'png', | default = 'png', | ||
}, | }, | ||
| Line 60: | Line 62: | ||
}, | }, | ||
{ | { | ||
name = ' | name = 'nolink', | ||
type = '1', | type = '1', | ||
}, | }, | ||
| Line 86: | Line 88: | ||
alias = 'UP', | alias = 'UP', | ||
type = '1', | type = '1', | ||
}, | |||
{ | |||
name = 'galaxy', | |||
}, | }, | ||
{ | { | ||
| Line 94: | Line 99: | ||
function p.main(frame) | function p.main(frame) | ||
local args = require('Module:Arguments').getArgs(frame, { | local args = require('Module:Arguments').getArgs(frame, { | ||
wrapper = {'Template:Card'}, | wrapper = { 'Template:Card' }, | ||
parentOnly = false | parentOnly = false | ||
}) | }) | ||
return p._main(args) | return p._main(args) | ||
end | end | ||
| Line 137: | Line 115: | ||
if lib.isEmpty(requestedType) or dataType == requestedType then | if lib.isEmpty(requestedType) or dataType == requestedType then | ||
local data = | local data = dataTable[name] | ||
if data then | if data then | ||
| Line 172: | Line 150: | ||
if lib.isEmpty(quality) then | if lib.isEmpty(quality) then | ||
quality = ' | quality = 'Gray' | ||
end | end | ||
| Line 181: | Line 159: | ||
value = tostring(value or '') | value = tostring(value or '') | ||
-- Converts "Luca: Myriad Meadows" to "Myriad Meadows". | -- Converts "Luca: Myriad Meadows" to "Myriad Meadows" | ||
-- Only affects the link target, not the displayed card name. | |||
return mw.text.trim(value:gsub('^.-:%s*', '', 1)) | return mw.text.trim(value:gsub('^.-:%s*', '', 1)) | ||
end | end | ||
| Line 191: | Line 170: | ||
node:css('width', width) | node:css('width', width) | ||
end | end | ||
end | end | ||
| Line 213: | Line 177: | ||
-- Basic identity | -- Basic identity | ||
out.name = out.name or 'Unknown' | out.name = out.name or 'Unknown' | ||
-- Use only a manually supplied type for lookup. | -- Use only a manually supplied type for lookup. | ||
local requestedType = out.nonDefaults | -- This allows {{Card|Sockeye Salmon}} to search Creature, Item, etc. | ||
local requestedType = out.nonDefaults and out.nonDefaults.type or nil | |||
out.type, out.data = p.getTypeAndData(out.name, requestedType) | |||
out.type, out.data = p.getTypeAndData( | |||
-- Boolean params | |||
-- Boolean | |||
out.mini = normalizeBool(out.mini) | out.mini = normalizeBool(out.mini) | ||
out.first = normalizeBool(out.first) | out.first = normalizeBool(out.first) | ||
out.up = normalizeBool(out.up) | out.up = normalizeBool(out.up) | ||
out. | out.nolink = normalizeBool(out.nolink) | ||
out.show_label = normalizeBool(out.show_label) | out.show_label = normalizeBool(out.show_label) | ||
out.show_caption = normalizeBool(out.show_caption) | out.show_caption = normalizeBool(out.show_caption) | ||
| Line 263: | Line 217: | ||
out.defaults.quality = out.data.quality | out.defaults.quality = out.data.quality | ||
-- Safety fallback in case TemplateData does not re-resolve | |||
-- defaults after processArgs. | |||
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 | |||
if out.data.galaxy then | |||
out.defaults.galaxy = out.data.galaxy | |||
if not (out.nonDefaults and out.nonDefaults.galaxy) then | |||
out.galaxy = out.data.galaxy | |||
end | end | ||
end | end | ||
| Line 272: | Line 236: | ||
out.quality = normalizeQuality(out.quality) | out.quality = normalizeQuality(out.quality) | ||
-- Label handling | -- Label/text handling | ||
if out.show_label then | if out.show_label then | ||
out.label = out.data | out.label = out.data and (out.data.name or out.data.title) or out.name | ||
end | end | ||
| Line 285: | Line 247: | ||
-- Type-specific behavior | -- Type-specific behavior | ||
local lcType = tostring(out.type or ''):lower() | local lcType = tostring(out.type or ''):lower() | ||
if lcType == 'neighbor' then | if lcType == 'neighbor' then | ||
if lib.isEmpty(out.label) then | if lib.isEmpty(out.label) then | ||
| Line 294: | Line 256: | ||
end | end | ||
end | end | ||
if tonumber(out.image_size) then | if tonumber(out.image_size) then | ||
out.image_size = tonumber(out.image_size) + 2 | out.image_size = tonumber(out.image_size) + 2 | ||
end | end | ||
end | end | ||
if lcType == 'redirect' then | if lcType == 'redirect' then | ||
out.defaults.link = stripLinkPrefix(out.name) | out.defaults.link = stripLinkPrefix(out.name) | ||
-- Safety fallback in case TemplateData does not re-resolve defaults. | |||
if not (out.nonDefaults and out.nonDefaults.link) then | if not (out.nonDefaults and out.nonDefaults.link) then | ||
out.link = stripLinkPrefix(out.name) | out.link = stripLinkPrefix(out.name) | ||
| Line 308: | Line 271: | ||
end | end | ||
-- Caption | -- Caption handling | ||
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 | ||
out.caption = out.data.title | out.caption = out.data.title or out.data.name or out.name | ||
else | else | ||
out.caption = out.name | out.caption = out.name | ||
| Line 321: | Line 282: | ||
-- Link handling | -- Link handling | ||
if out.link == nil then | if out.link == nil then | ||
out.link = lib.ternary( | out.link = lib.ternary(out.name == 'Unknown', '', out.name) | ||
end | end | ||
| Line 331: | Line 288: | ||
out.final_link = out.link .. out.link_suffix | out.final_link = out.link .. out.link_suffix | ||
if out. | if out.nolink then | ||
out.final_link = '' | out.final_link = '' | ||
end | end | ||
-- | -- File name | ||
if ne(out.image) then | if ne(out.image) then | ||
out.final_file = out.image | out.final_file = out.image | ||
else | else | ||
out.final_file = | out.final_file = lib.sanitizeFileName(out.name) .. out.suffix .. '.' .. out.image_ext | ||
end | end | ||
-- Main image wikitext | -- Main image wikitext | ||
local linkPart = out. | local linkPart = out.nolink and '|link=' or ('|link=' .. out.final_link) | ||
out.image_wikitext = table.concat({ | out.image_wikitext = table.concat({ | ||
| Line 357: | Line 308: | ||
out.image_size, | out.image_size, | ||
'px|alt=', | 'px|alt=', | ||
out.name, | |||
linkPart, | linkPart, | ||
']]' | ']]' | ||
| Line 368: | Line 318: | ||
function p._main(args) | function p._main(args) | ||
local a = p._processArgs(args) | local a = p._processArgs(args) | ||
local node_container = mw.html.create('div') | local node_container = mw.html.create('div') | ||
:addClass('card-container') | :addClass('card-container') | ||
if a.mini then | if a.mini then | ||
| Line 382: | Line 326: | ||
end | end | ||
-- | -- Old-style wrapper/body structure | ||
local node_card = node_container:tag('span') | local node_card = node_container:tag('span') | ||
:addClass('card-wrapper') | :addClass('card-wrapper') | ||
| Line 390: | Line 334: | ||
-- Galaxy class on body | -- Galaxy class on body | ||
if not a.mini and ne(a.galaxy) then | if not a.mini and ne(a.galaxy) then | ||
node_card:addClass( | node_card:addClass('card-galaxy-' .. normalizeClassName(a.galaxy)) | ||
end | end | ||
-- Main image | -- Main image | ||
node_card:tag('span') | |||
:addClass('card-image-container') | :addClass('card-image-container') | ||
:addClass('card-quality-' .. a.quality) | :addClass('card-quality-' .. a.quality) | ||
:wikitext(a.image_wikitext) | |||
-- | -- Galaxy icon | ||
if | if not a.mini and ne(a.galaxy) then | ||
node_card:tag('span') | |||
:addClass('card-icon-galaxy') | |||
:wikitext( | |||
'[[File:Icon ' .. | |||
:addClass('card- | a.galaxy .. | ||
: | '.png|alt=' .. | ||
a.galaxy .. | |||
'|link=' .. | |||
a.galaxy .. | |||
'|20px]]' | |||
) | |||
end | end | ||
| Line 431: | Line 370: | ||
:addClass('card-modifier') | :addClass('card-modifier') | ||
:addClass('card-modifier-first') | :addClass('card-modifier-first') | ||
:wikitext( | :wikitext('[[File:Icon Item First.png|x25px|link=|alt=First]]') | ||
end | end | ||
| Line 441: | Line 378: | ||
:addClass('card-modifier') | :addClass('card-modifier') | ||
:addClass('card-modifier-up') | :addClass('card-modifier-up') | ||
:wikitext( | :wikitext('[[File:Icon Item UP.png|x25px|link=|alt=UP]]') | ||
end | end | ||
-- Label below | -- Label/text below card image | ||
if ne(a.label) then | if ne(a.label) then | ||
node_container:tag('span') | node_container:tag('span') | ||
| Line 453: | Line 388: | ||
end | end | ||
-- Caption | -- Caption below card | ||
if a.show_caption and ne(a.caption) then | |||
if | |||
local node_caption = node_container:tag('span') | local node_caption = node_container:tag('span') | ||
:addClass('card-caption') | :addClass('card-caption') | ||
if a. | if a.nolink or lib.isEmpty(a.final_link) then | ||
node_caption:wikitext(a.caption) | node_caption:wikitext(a.caption) | ||
else | else | ||
node_caption:wikitext( | node_caption:wikitext('[[', a.final_link, '|', a.caption, ']]') | ||
end | end | ||
| Line 493: | Line 407: | ||
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, caption, modifiers, and optional data-driven icons.', | ||
format = 'inline' | format = 'inline' | ||
}, frame) | }, frame) | ||