Jump to content

Editing Module:Card

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
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 CentralData = require('Module:CentralData')


local allData = CentralData.dataSheets
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 = 'Common',
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
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 137: Line 141:


if lib.isEmpty(requestedType) or dataType == requestedType then
if lib.isEmpty(requestedType) or dataType == requestedType then
local data = getDataByName(dataType, dataTable, name)
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 = 'Common'
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 icon for a split card.
-- Generates an icon for the second item in a split card.
local function makeSplitIcon(name, mini)
-- 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 size = mini and 74 or 56


return '[[File:' ..
return '[[File:' ..
lib.sanitizeFileName(name) ..
safeName ..
' Icon.png|' ..
' Icon.png|74x74px|link=' ..
size .. 'x' .. size ..
'px|link=' ..
name ..
name ..
']]'
']]'
Line 225: Line 227:
)
)


-- Base name for assets.
-- Base name for assets
-- Removes a trailing disambiguation such as "(Currency)".
out.image_name = out.name:gsub('%s*%([^()]*%)$', '')
out.image_name = out.name--:gsub('%s*%([^()]*%)$', '')


-- 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 defaults
-- 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)


-- 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
node_container:addClass('card-split-card')
node_container:addClass('recipe-type-split-card')
end
end


Line 395: Line 405:
end
end


-- Main image container
-- 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)


-- Split or regular image
if isSplit then
if isSplit then
imageContainer:addClass('card-split-image')
imageContainer:addClass('recipe-type-split-image')


-- First item: top-left half
imageContainer:tag('span')
imageContainer:tag('span')
:addClass('card-split-half')
:addClass('recipe-type-split-half')
:addClass('card-split-half-a')
:addClass('recipe-type-split-half-a')
:wikitext(a.image_wikitext)
:wikitext(a.image_wikitext)


-- Second item: bottom-right half
imageContainer:tag('span')
imageContainer:tag('span')
:addClass('card-split-half')
:addClass('recipe-type-split-half')
:addClass('card-split-half-b')
:addClass('recipe-type-split-half-b')
:wikitext(makeSplitIcon(a.split, a.mini))
: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
-- Split captions are opt-in and use spans instead of list items.
if 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')


local list = node_caption:tag('span')
node_caption:wikitext(
:addClass('card-split-caption-list')
'[[:' .. a.name .. ']] / [[:' .. a.split .. ']]'
 
)
list:tag('span')
:addClass('card-split-caption-item')
:wikitext('[[' .. a.name .. ']]')
 
list:tag('span')
:addClass('card-split-caption-item')
:wikitext('[[' .. 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)
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Petit Planet Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template
Below are commonly used wikitext from MediaWiki:Edittools. Click on any to insert them in the edit box.
File Pages==Summary====Licensing=={{Fairuse}}{{File|}}
Dynamic Page List¦²«»²{¦}²«»«/»«!----»
Array in DPL¹^2{}^2^2{¹}^2
Parser Functions{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}
Markup{{}}|[][[]][[Category:]]#REDIRECT [[]] [[Category:Redirect Pages]]<code></code><includeonly></includeonly><noinclude></noinclude><nowiki></nowiki><!----><br>§
Notices{{Stub|}}{{Stub Dialogue}}{{Upcoming}}{{Under Construction}}{{Placeholder|}}
Magic Words{{!}}{{formatnum:}}{{lc:}}{{uc:}}{{PAGENAME}}{{FULLPAGENAME}}{{ROOTPAGENAME}}{{BASEPAGENAME}}{{SUBPAGENAME}}{{DISPLAYTITLE:|noreplace}}__TOC____NOTOC____EXPECTUNUSEDCATEGORY____HIDDENCAT__
HTML Entities&mdash;&nbsp;&comma;&shy;