Editing Module:Card
Appearance
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 6: | Line 6: | ||
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 | |||
{'Neighbor', mw.loadData('Module:CentralData/Neighbors')}, | |||
-- Creatures | |||
{'Fish', mw.loadData('Module:CentralData/Aquatic Creatures')}, | |||
{'Insect', mw.loadData('Module:CentralData/Land Creatures')}, | |||
{'Shore-Dweller', mw.loadData('Module:CentralData/Shore-Dwellers')}, | |||
-- Furniture | |||
{'Furniture', mw.loadData('Module:CentralData/Furniture')}, | |||
-- Items | |||
{'Item', mw.loadData('Module:CentralData/Items')}, | |||
{'Dish', mw.loadData('Module:CentralData/Dishes')}, | |||
{'Crop', mw.loadData('Module:CentralData/Crops')}, | |||
{'Tool', mw.loadData('Module:CentralData/Tools')}, | |||
-- Clothing | |||
{'Clothing', mw.loadData('Module:CentralData/Clothing')}, | |||
{'Styling', mw.loadData('Module:CentralData/Styling')}, | |||
-- Other | |||
{'Title', mw.loadData('Module:CentralData/Titles')}, | |||
{'Reaction', mw.loadData('Module:CentralData/Reactions')}, | |||
{'Set', mw.loadData('Module:CentralData/Sets')}, | |||
-- Redirects | |||
{'Redirect', mw.loadData('Module:CentralData/Redirects')}, | |||
} | |||
local CARD_ARGS = { | local CARD_ARGS = { | ||
| Line 28: | Line 56: | ||
name = 'quality', | name = 'quality', | ||
alias = 'rarity', | alias = 'rarity', | ||
default = ' | default = 'Gray', | ||
}, | }, | ||
{ | { | ||
| Line 86: | Line 114: | ||
alias = 'UP', | alias = 'UP', | ||
type = '1', | type = '1', | ||
}, | |||
{ | |||
name = 'galaxy', | |||
}, | }, | ||
{ | { | ||
| Line 99: | Line 130: | ||
return p._main(args) | return p._main(args) | ||
end | end | ||
| Line 137: | Line 141: | ||
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 176: | ||
if lib.isEmpty(quality) then | if lib.isEmpty(quality) then | ||
quality = ' | quality = 'Gray' | ||
end | end | ||
| Line 181: | Line 185: | ||
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 193: | Line 197: | ||
end | end | ||
-- Generates the second | -- Generates an icon for the second item in a split card. | ||
local function makeSplitIcon(name | -- Uses the same filename convention as Recipe. | ||
local function makeSplitIcon(name) | |||
name = tostring(name or '') | name = tostring(name or '') | ||
local safeName = lib.sanitizeFileName(name) | |||
local | |||
return '[[File:' .. | return '[[File:' .. | ||
safeName .. | |||
' Icon.png| | ' Icon.png|74x74px|link=' .. | ||
name .. | name .. | ||
']]' | ']]' | ||
| Line 225: | Line 227: | ||
) | ) | ||
-- Base name for assets | -- Base name for assets | ||
out.image_name = out.name:gsub('%s*%([^()]*%)$', '') | |||
out.image_name = out.name | |||
-- Boolean parameters | -- Boolean parameters | ||
| Line 265: | Line 266: | ||
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 308: | Line 317: | ||
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 | ||
| Line 368: | Line 377: | ||
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) | ||
local node_container = mw.html.create('div') | local node_container = mw.html.create('div') | ||
:addClass('card-container') | :addClass('card-container') | ||
-- Required by existing Recipe CSS | |||
if isSplit then | if isSplit then | ||
node_container:addClass(' | node_container:addClass('recipe-type-split-card') | ||
end | end | ||
| Line 395: | Line 405: | ||
end | end | ||
-- Main image | -- Main image | ||
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) | ||
if isSplit then | if isSplit then | ||
imageContainer:addClass(' | imageContainer:addClass('recipe-type-split-image') | ||
imageContainer:tag('span') | imageContainer:tag('span') | ||
:addClass(' | :addClass('recipe-type-split-half') | ||
:addClass(' | :addClass('recipe-type-split-half-a') | ||
:wikitext(a.image_wikitext) | :wikitext(a.image_wikitext) | ||
imageContainer:tag('span') | imageContainer:tag('span') | ||
:addClass(' | :addClass('recipe-type-split-half') | ||
:addClass(' | :addClass('recipe-type-split-half-b') | ||
:wikitext(makeSplitIcon(a.split | :wikitext(makeSplitIcon(a.split)) | ||
else | else | ||
imageContainer:wikitext(a.image_wikitext) | imageContainer:wikitext(a.image_wikitext) | ||
end | |||
-- Galaxy icon | |||
if not a.mini and ne(a.galaxy) then | |||
node_card:tag('span') | |||
:addClass('card-icon-galaxy') | |||
:wikitext( | |||
'[[File:' .. | |||
a.galaxy .. | |||
' Icon.png|alt=' .. | |||
a.galaxy .. | |||
'|link=' .. | |||
a.galaxy .. | |||
'|20px]]' | |||
) | |||
end | end | ||
| Line 454: | Line 476: | ||
-- Caption | -- Caption | ||
if isSplit then | |||
if | |||
local node_caption = node_container:tag('span') | local node_caption = node_container:tag('span') | ||
:addClass('card-caption') | :addClass('card-caption') | ||
node_caption:wikitext( | |||
'[[:' .. a.name .. ']] / [[:' .. a.split .. ']]' | |||
) | |||
setCaptionWidth(node_caption, a.caption_width) | setCaptionWidth(node_caption, a.caption_width) | ||
| Line 493: | Line 506: | ||
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, split images, modifiers, and optional data-driven icons.', | description = 'Creates an item-style card with image, quality, label, caption, split images, modifiers, and optional data-driven icons.', | ||
format = 'inline' | format = 'inline' | ||
}, frame) | }, frame) | ||