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
-- 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 56: Line 28:
name = 'quality',
name = 'quality',
alias = 'rarity',
alias = 'rarity',
default = 'Gray',
default = 'Common',
},
},
{
{
Line 114: Line 86:
alias = 'UP',
alias = 'UP',
type = '1',
type = '1',
},
{
name = 'galaxy',
},
},
{
{
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[name]
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 = 'Gray'
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 an icon for the second item in a split card.
-- Generates the second icon for a split card.
-- Uses the same filename convention as Recipe.
local function makeSplitIcon(name, mini)
local function makeSplitIcon(name, mini)
name = tostring(name or '')
name = tostring(name or '')


local size = mini and 56 or 74
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
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 319: Line 308:
end
end


-- Caption handling
-- 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')


-- Required by existing Recipe CSS
if isSplit then
if isSplit then
imageContainer:addClass('recipe-type-split-image')
node_container:addClass('card-split-card')
imageContainer:tag('span')
:addClass('recipe-type-split-half')
:addClass('recipe-type-split-half-a')
:wikitext(a.image_wikitext)
imageContainer:tag('span')
:addClass('recipe-type-split-half')
:addClass('recipe-type-split-half-b')
:wikitext(makeSplitIcon(a.split, a.mini))
else
imageContainer:wikitext(a.image_wikitext)
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('recipe-type-split-image')
imageContainer:addClass('card-split-image')


-- First item: top-left half
imageContainer:tag('span')
imageContainer:tag('span')
:addClass('recipe-type-split-half')
:addClass('card-split-half')
:addClass('recipe-type-split-half-a')
: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('recipe-type-split-half')
:addClass('card-split-half')
:addClass('recipe-type-split-half-b')
: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
-- 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 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, caption, split images, modifiers, and optional data-driven icons.',
description = 'Creates an item-style card with image, quality, label, split images, modifiers, and optional data-driven icons.',
format = 'inline'
format = 'inline'
}, frame)
}, frame)