Module:Card: Difference between revisions

No edit summary
i can't make this fully ZZZ or old-style without screwing up CSS.
Line 13: Line 13:
}
}


-- Minimal TemplateData args.
-- This does not need to be huge unless you want full documentation for every parameter.
local CARD_ARGS = {
local CARD_ARGS = {
{
{
Line 37: Line 35:
{
{
name = 'type',
name = 'type',
default = 'Item',
},
},
{
{
Line 171: Line 168:
out.name = out.name or 'Unknown'
out.name = out.name or 'Unknown'


-- Data lookup
-- Use only a manually supplied type for lookup.
out.type, out.data = p.getTypeAndData(out.name, out.type)
-- 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)


-- Boolean-ish params
-- Boolean params
out.mini = normalizeBool(out.mini)
out.mini = normalizeBool(out.mini)
out.first = normalizeBool(out.first)
out.first = normalizeBool(out.first)
Line 194: Line 193:
end
end


-- Data-driven name
-- Data-driven defaults
out.data_name = out.data and out.data.name or nil
if out.data then
if out.data.name then
out.defaults.label = out.data.name
out.defaults.caption = out.data.name
end
 
if out.data.title then
out.defaults.caption = out.data.title
end
 
if out.data.quality then
out.defaults.quality = out.data.quality


-- Quality / rarity
-- Safety fallback in case TemplateData does not re-resolve
if lib.isEmpty(out.quality) and out.data and out.data.quality then
-- defaults after processArgs.
out.quality = out.data.quality
if not (out.nonDefaults and out.nonDefaults.quality) then
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


-- Quality / rarity
out.quality = normalizeQuality(out.quality)
out.quality = normalizeQuality(out.quality)
-- Galaxy
if lib.isEmpty(out.galaxy) and out.data and out.data.galaxy then
out.galaxy = out.data.galaxy
end


-- Label/text handling
-- Label/text handling
if out.show_label then
if out.show_label then
out.label = out.data_name or out.name
out.label = out.data and (out.data.name or out.data.title) or out.name
end
end


Line 238: Line 255:
-- Caption handling
-- Caption handling
if out.show_caption and lib.isEmpty(out.caption) then
if out.show_caption and lib.isEmpty(out.caption) then
out.caption = out.data_name or out.name
if out.data then
out.caption = out.data.title or out.data.name or out.name
else
out.caption = out.name
end
end
end


Line 282: Line 303:
local node_container = mw.html.create('div')
local node_container = mw.html.create('div')
:addClass('card-container')
:addClass('card-container')
:addClass('card-quality-' .. a.quality)


if a.mini then
if a.mini then
Line 287: Line 309:
end
end


-- Old-style wrapper/body structure.
-- Old-style wrapper/body structure
-- This is usually important if your existing CSS was written for the old Card module.
local node_card = node_container:tag('span')
local node_card = node_container:tag('span')
:addClass('card-wrapper')
:addClass('card-wrapper')
Line 294: Line 315:
:addClass('card-body')
:addClass('card-body')


-- Main image container
-- Galaxy class on body
if not a.mini and ne(a.galaxy) then
node_card:addClass('card-galaxy-' .. normalizeClassName(a.galaxy))
end
 
-- Main image
node_card:tag('span')
node_card:tag('span')
:addClass('card-image-container')
:addClass('card-image-container')
Line 302: Line 328:
-- Galaxy icon
-- Galaxy icon
if not a.mini and ne(a.galaxy) then
if not a.mini and ne(a.galaxy) then
node_card:addClass('card-galaxy-' .. normalizeClassName(a.galaxy))
node_card:tag('span')
node_card:tag('span')
:addClass('card-icon-galaxy')
:addClass('card-icon-galaxy')