|
|
| Line 1: |
Line 1: |
| local p = {} | | local p = {} |
| local lib = require('Module:Feature') | | local lib = require('Module:Feature') |
| local TemplateData = require('Module:TemplateData') | | local ne = lib.isNotEmpty |
| local Icon = require('Module:Icon') | | local link_label = require('Module:Link_Label')._main |
| | local namespace = require('Module:Namespace_detect')._main |
| | local getTemplateArgs = require('Module:Parser').getTemplateArgs |
| | local array = require('Module:Array') |
|
| |
|
| | | local allData = { |
| local QUALITY_STARS = { | | {'Agent', mw.loadData('Module:CentralData/Agents')}, |
| ['1'] = '[[File:1 Star Icon.png|x16px|link=|alt=Quality 1]]', | | {'W-Engine', mw.loadData('Module:CentralData/W-Engines')}, |
| ['2'] = '[[File:2 Stars Icon.png|x16px|link=|alt=Quality 2]]',
| | {'Drive Disc', mw.loadData('Module:CentralData/Drive Discs')}, |
| ['3'] = '[[File:3 Stars Icon.png|x16px|link=|alt=Quality 3]]',
| | {'Bangboo', mw.loadData('Module:CentralData/Bangboo')}, |
| ['4'] = '[[File:4 Stars Icon.png|x16px|link=|alt=Quality 4]]',
| | {'Enemy', mw.loadData('Module:CentralData/Enemies')}, |
| ['5'] = '[[File:5 Stars Icon.png|x16px|link=|alt=Quality 5]]'
| | {'Resonium', mw.loadData('Module:CentralData/Resonia')}, |
| }
| | {'Item', mw.loadData('Module:CentralData/Items')}, |
| local PREFIX_ICONS = {
| | {'Companion', mw.loadData('Module:CentralData/Companions')}, |
| ['Instructions: '] = {name='Instructions', type='Item'},
| | {'Outfit', mw.loadData('Module:CentralData/Outfits')}, |
| ['Diagram: '] = {name='Diagram', type='Item'},
| |
| ['Recipe: '] = {name='Recipe', type='Item'},
| |
| ['Formula: '] = {name='Formula', type='Item'},
| |
| ['Blueprint: '] = {name='Furnishing Blueprint', type='Icon'},
| |
| }
| |
| | |
| -- main template/module parameters
| |
| local CARD_ARGS = {
| |
| {
| |
| name='name', alias={1,'character'}, displayName=1,
| |
| status='suggested',
| |
| label='Name',
| |
| description='The name of the image (without the prefix or extension).',
| |
| default='Unknown',
| |
| example={'Mora', 'Primogem', 'Amber'},
| |
| },
| |
| { | |
| name='text', alias=2, displayName=2,
| |
| label='Card Text',
| |
| description='The text below the image.',
| |
| example={'100', 'Lv. 1', 'Set'},
| |
| },
| |
| {
| |
| name='multiline_text', type='1',
| |
| label='Allow Multiple Lines of Card Text',
| |
| trueDescription='allow card text to wrap to a new line if necessary.',
| |
| },
| |
| {
| |
| name='text_size', type='string',
| |
| label='Size of Card Text',
| |
| description='Adds the "card-text-<text_size>" class, including "small", "smaller".',
| |
| },
| |
| {
| |
| name='quality', displayType='number',
| |
| label='Card Quality',
| |
| description='The Quality of the item. For light background, add 10. Use 0 for white version. Use multiple numbers for split rarities.',
| |
| default='0',
| |
| displayDefault='determined based on Image Name; "0" if unknown',
| |
| example={'1', '2', '3', '4', '5', '123', '23', '34', '45'},
| |
| },
| |
| {
| |
| name='type', placeholderFor='Module:Icon',
| |
| },
| |
| {
| |
| name='suffix', placeholderFor='Module:Icon',
| |
| },
| |
| {
| |
| name='extension', placeholderFor='Module:Icon',
| |
| },
| |
| {
| |
| name='link', displayType='wiki-page-name',
| |
| label='Card Link',
| |
| description='The page to link to when image or caption text is clicked.',
| |
| displayDefault='same as Image Name',
| |
| defaultFrom='name',
| |
| example={'Mora', 'Dressing Room', 'Shops', 'Amber'},
| |
| },
| |
| {
| |
| name='link_suffix',
| |
| label='Page Link Suffix',
| |
| description='Text to append to the Page Link. (Usually used to link to page sections.)',
| |
| default='',
| |
| example='#Trivia',
| |
| },
| |
| { | |
| name='nolink', type='1',
| |
| label='No Link',
| |
| trueDescription='remove default links from card image, icons, and caption.',
| |
| displayDefault='"1" if Image Name is default ("Unknown")',
| |
| },
| |
| {
| |
| name='icon', displayType='content',
| |
| label='Icon',
| |
| description='The icon at the top left of the card.',
| |
| example={'{{Icon/Element|Pyro|25}}', '[[File:Item Primogem.png|25px]]'},
| |
| },
| |
| { | |
| name='icon_style', displayType='string',
| |
| label='Icon Style',
| |
| description='The custom style of the icon at the top left of the card. Omit the \'\' used for CSS.',
| |
| example='background: red;',
| |
| },
| |
| {
| |
| name='icon_right', displayType='content',
| |
| label='Top-Right Icon',
| |
| description='Icon on the top right of the card.',
| |
| example='{{Icon/Element|Pyro|25}}',
| |
| },
| |
| { | |
| name='icon_right_style', displayType='string',
| |
| label='Top-Right Icon Style',
| |
| description='The custom style of the icon at the top right of the card. Omit the \'\' used for CSS.',
| |
| example='background: red;',
| |
| },
| |
| {
| |
| name='icon_bottom_left', displayType='content',
| |
| label='Bottom-Left Icon',
| |
| description='Icon on the bottom left of the card.',
| |
| example='{{Icon/Element|Pyro|25}}',
| |
| },
| |
| { | |
| name='icon_bottom_left_style', displayType='string',
| |
| label='Bottom-Left Icon Style',
| |
| description='The custom style of the icon at the bottom left of the card. Omit the \'\' used for CSS.',
| |
| example='background: red;',
| |
| },
| |
| {
| |
| name='icon_bottom_right', displayType='content',
| |
| label='Bottom-Right Icon',
| |
| description='Icon on the bottom right of the card.',
| |
| example='{{Icon/Element|Pyro|25}}',
| |
| },
| |
| {
| |
| name='icon_bottom_right_style', displayType='string',
| |
| label='Bottom-Right Icon Style',
| |
| description='The custom style of the icon at the bottom right of the card. Omit the \'\' used for CSS.',
| |
| example='background: red;',
| |
| },
| |
| {
| |
| name='show_caption', type='1',
| |
| label='Show Caption',
| |
| trueDescription='show caption text below the card.',
| |
| },
| |
| {
| |
| name='caption', displayType='string',
| |
| label='Caption Text',
| |
| description='The linked caption text that shows below the card.',
| |
| displayDefault='same as Name',
| |
| defaultFrom='name',
| |
| example={'Apple', 'Rewards'},
| |
| },
| |
| {
| |
| name='caption_width',
| |
| label='Caption Width',
| |
| description='Width of the captions. Set to \'auto\' to automatically increase the caption width to prevent it from wrapping in the middle of words.',
| |
| displayDefault='same as card width (74px, or 40px for mini cards)',
| |
| example={'200px', 'auto'},
| |
| },
| |
| { | |
| name='note', displayType='string',
| |
| label='Caption Note',
| |
| description='The unlinked caption text that shows below the linked caption text.',
| |
| example='(Bonus reward)',
| |
| },
| |
| {
| |
| name='refinement', alias='r', displayType='number',
| |
| label='Refinement Rank',
| |
| description='The refinement of the weapon. Set to \'1a\' to denote a weapon that cannot be refined.',
| |
| example={'1', '2', '3', '4', '5', '1a'},
| |
| },
| |
| {
| |
| name='ascension', placeholderFor='Module:Icon',
| |
| },
| |
| { | |
| name='constellation', alias='c', displayType='number',
| |
| label='Constellation Level',
| |
| description='Constellation Level of the Character.',
| |
| example={'0', '1', '2', '3', '4', '5', '6'},
| |
| },
| |
| {
| |
| name='outfit', placeholderFor='Module:Icon',
| |
| },
| |
| {
| |
| name='stars', type='1',
| |
| label='Show Item Stars',
| |
| trueDescription='show the stars of the quality of the item. (Does not work if quality is "0" or split (e.g., "123" or "34").)',
| |
| },
| |
| { | |
| name='set', type='1',
| |
| label='Show Set Icon',
| |
| displayDefault='"1" if the card type is "Artifact Set"',
| |
| trueDescription='show set icon at the top right corner of the card.',
| |
| },
| |
| {
| |
| name='vol', displayType='number',
| |
| label='Book Volume',
| |
| description='Volume number of the book (for cards that show books). Sets Card Text and Page Link Suffix to point to the given volume.',
| |
| example={'1', '2', '3'},
| |
| },
| |
| {
| |
| name='danger', type='1',
| |
| label='Danger',
| |
| trueDescription='add Warning icon as the Top-Right Icon.',
| |
| },
| |
| {
| |
| name='mini', type='1',
| |
| label='Mini',
| |
| trueDescription='show a smaller card. (Not all parameters apply to mini cards.)',
| |
| },
| |
| {
| |
| name='miliastra_wonderland', type='1',
| |
| label='Miliastra Wonderland',
| |
| trueDescription='Shows styles for Miliastra Wonderland items and cosmetics.',
| |
| },
| |
| {
| |
| name='mobile_list', type='1',
| |
| label='Mobile List Item',
| |
| trueDescription='show Template:Item-like display on mobile',
| |
| },
| |
| } | | } |
| -- add parameters inherited from Icon for the main image, top-left/right icon, and equipped icon
| |
| Icon.addIconArgs(CARD_ARGS, '', '', { -- exclude args already present in CARD_ARGS or that don't apply to the main image
| |
| name=false,
| |
| link=false,
| |
| size=false,
| |
| alt=false,
| |
| })
| |
| Icon.addIconArgs(CARD_ARGS, 'icon_', 'Top-Left Icon ', { -- override to add `element` alias and document automatic icons
| |
| name={
| |
| alias='element',
| |
| description='Name of the icon to display at the top left of the card (without the prefix or extension).',
| |
| displayDefault='element icon for characters; furnishing blueprint/recipe/diagram icon if Name is prefixed accordingly; empty otherwise',
| |
| example={'Furnishing Blueprint', 'Fruit Paste Bait', 'Anemo'}
| |
| },
| |
| })
| |
| Icon.addIconArgs(CARD_ARGS, 'icon_right_', 'Top-Right Icon ', {
| |
| name={
| |
| description='Name of the icon to display at the top right of the card (without the prefix or extension).',
| |
| example={'Furnishing Blueprint', 'Fruit Paste Bait', 'Anemo'}
| |
| },
| |
| })
| |
| Icon.addIconArgs(CARD_ARGS, 'icon_bottom_left_', 'Bottom-Left Icon ', {
| |
| name={
| |
| description='Name of the icon to display at the bottom left of the card (without the prefix or extension).',
| |
| example={'Furnishing Blueprint', 'Fruit Paste Bait', 'Anemo'}
| |
| },
| |
| })
| |
| Icon.addIconArgs(CARD_ARGS, 'icon_bottom_right_', 'Bottom-Right Icon ', {
| |
| name={
| |
| description='Name of the icon to display at the bottom right of the card (without the prefix or extension).',
| |
| example={'Furnishing Blueprint', 'Fruit Paste Bait', 'Anemo'}
| |
| },
| |
| })
| |
| Icon.addIconArgs(CARD_ARGS, 'equipped_', 'Equipped ', { -- overrides to add `equipped`/`e` aliases and change default size
| |
| name={
| |
| alias={'equipped', 'e'},
| |
| description='Name of the weapon or character to display at the top right of the card (or bottom left, if Constellation Level is present; name does not include the prefix or extension).',
| |
| example={'Song of Broken Pines', 'Hu Tao'}
| |
| },
| |
| size={default='30'},
| |
| })
| |
|
| |
|
| | local COLON = ':' |
|
| |
|
| function p.main(frame) | | function p.main(frame) |
| local args = require('Module:Arguments').getArgs(frame, { | | local args = require('Module:Arguments').getArgs(frame, { |
| parentFirst = true,
| | wrapper = { 'Template:Card' }, |
| wrapper = { 'Template:Card' } | | parentOnly = false |
| }) | | }) |
| return p._main(args, frame) | | return p._main(args) |
| end | | end |
|
| |
|
| -- apply defaults; load and apply data (e.g., quality, character element) | | function p._main(args) |
| function p._processArgs(args)
| | local item = args[1] or args.name or 'Unknown' |
| local out = TemplateData.processArgs(args, CARD_ARGS) | | local label = args[2] or args.label or args.text or args.count or args.amount or args.x or nil |
| | |
| | -- Reset agent-specific data to prevent carry-over from previous cards |
| | local agRank, agAttribute, agSpecialty, bbRank, weRank, weSpecialty, outRank, notice = nil, nil, nil, nil, nil, nil, nil, nil |
| | |
| | -- Caption Params: |
| | local caption = args.caption or nil |
| | local caption_width = args.caption_width or args.captionWidth or nil |
| | |
| | -- Image File Params: |
| | local type, data = p.getTypeAndData(item, args.type) |
| | local suffix = args.suffix or '' |
| | local imageSize = args.image_size or args.imageSize or lib.ternary(args.mini == '1', 48, 70) |
| | local imageExt = args.image_ext or args.imageExt or 'png' |
| | |
| | -- Link Params: |
| | local link = args.link or lib.ternary(item == 'Unknown', '', item) |
| | local link_suffix = args.link_suffix or '' |
| | |
| | -- Rank Param: |
| | local rank = args.rank or args.quality or args.rarity or nil |
| | | |
| -- set defaults that depend on other arguments | | -- Try to get Rank From Data |
| out.defaults.show_caption = lib.isNotEmpty(out.nonDefaults.caption) | | if lib.isEmpty(rank) and data then |
| out.defaults.nolink = out.name == out.defaults.name and lib.isEmpty(out.nonDefaults.link)
| | if data.rank then |
| if out.vol ~= nil then
| | rank = data.rank |
| out.defaults.text = 'Vol. ' .. out.vol
| | end |
| out.defaults.link_suffix = '#Vol._' .. out.vol | |
| end | | end |
| | | |
| -- handle deprecated caption value | | -- If rank is still empty, set it to "C" |
| if tostring(out.caption) == '1' then | | if lib.isEmpty(rank) then |
| out.uses_deprecated_params = true | | rank = 'C' |
| out.caption = nil
| |
| out.show_caption = true
| |
| end | | end |
| | | |
| -- handle nolink | | -- If rank contains a semicolon, then split and get first |
| out.final_link = out.nolink and '' or (out.link .. out.link_suffix) | | if string.find(rank, ";") then |
| | rank = array._main({ |
| | rank, |
| | ';', |
| | firstItemOnly = 1 |
| | }) |
| | end |
| | | |
| -- build args for main card image | | -- Make sure rank is uppercase |
| local mainImageArgs = Icon.extractIconArgs(out) | | rank = rank:upper() |
| mainImageArgs.link = out.final_link
| |
| mainImageArgs.size = 74
| |
| | | |
| -- check for prefixes in `name` that correspond to top-left icons | | -- Modifiers: |
| -- note: priority of icon specification: `icon` arg > `icon_name` arg > prefix of `name` > character element from data
| | local isFirst = args.first or false |
| local baseName, prefix = Icon.stripPrefixes(out.name, PREFIX_ICONS) | | local isUp = args.UP or args.up or false |
| if prefix then | |
| -- configure icon if none is specified by `icon_name`,
| |
| -- making sure not to change `icon_type` if `icon_name` is explicitly specified
| |
| if out.icon_name == out.defaults.icon_name then
| |
| local prefixIcon = PREFIX_ICONS[prefix]
| |
| out.icon_name = prefixIcon.name
| |
| out.icon_type = prefixIcon.type
| |
| end
| |
| mainImageArgs.name = baseName
| |
| end
| |
| | | |
| -- create card image and get type/data | | -- Attribute/specialty |
| local card_type, data | | local attribute = args.attr or args.attribute or nil |
| out.image, card_type, data = Icon.createIcon(mainImageArgs) | | local specialty = args.spec or args.fightSpec or args.fs or nil |
| | | |
| -- set defaults based on data
| | if lib.isEmpty(suffix) then |
| if data then | | local lcType = type:lower() |
| if card_type == 'Character' then | | if (lcType == 'agent') then |
| if out.icon_name == out.defaults.icon_name and data.element ~= 'Adaptive' and lib.isNotEmpty(data.element) then | | suffix = ' Icon' |
| out.icon_name = data.element
| | --Grabs Agent Rank, Attribute and Specialty from Data to display icons |
| out.icon_type = 'Element'
| | agRank = data['rank'] |
| out.icon_link = '' | | agAttribute = data['attribute'] |
| | agSpecialty = data['specialty'] |
| | |
| | --In Full-Size Card-Mode, if there is no specified text, Agents will default to using their full name displayed underneath. |
| | if args.mini ~= "1" then |
| | if (label == nil) then label = item end |
| end | | end |
| out.element = data.element or out.element | | -- In Mini-Size Card-Mode, if there is no specified text, Agents will use their "shortName" pulled from /data as the displayed text. |
| out.weapon = data.weapon or out.weapon | | -- In cases where Agents do not have a "shortName", their full name will be displayed instead. |
| out.defaults.text = data.name or out.name
| | if args.mini == "1" then |
| out.defaults.text_size = data.text_size or out.text_size | | if (label == nil) and data['shortName'] ~= nil then label = data['shortName'] |
| end
| | elseif (label == nil) and data['shortName'] == nil then label = item |
| if card_type == 'Enemy' then
| | end |
| if out.icon_name == out.defaults.icon_name and lib.isNotEmpty(data.element) then
| |
| out.icon_name = data.element
| |
| out.icon_type = 'Element' | |
| out.icon_link = '' | |
| end | | end |
| out.element = data.element or out.element | | |
| end
| | -- hackish workaround to account for the slight transparent borders on hoyolab agent icons |
| if card_type == 'Fish' then
| | if (tonumber(imageSize) ~= nil) then |
| if out.icon_name == out.defaults.icon_name and lib.isNotEmpty(data.bait) then | | imageSize = tonumber(imageSize) + 2 |
| out.icon_name = data.bait | |
| out.icon_type = 'Item'
| |
| out.icon_link = ''
| |
| end | | end |
| out.prefix = '' | | |
| end
| | elseif (lcType == 'bangboo') then |
| if card_type == 'Food' then | | suffix = ' Icon' |
| if out.icon_name == out.defaults.icon_name and lib.isNotEmpty(data.effectType) then | | --Grabs Bangboo Rank from Data to display icons |
| out.icon_name = data.effectType
| | bbRank = data['rank'] |
| out.icon_type = 'Icon'
| | |
| out.icon_link = ''
| | elseif (lcType == 'w-engine') then |
| end | | suffix = ' Icon' |
| end | | --Grabs W-Engine Rank and Specialty from Data to display icons |
| if card_type == 'Cosmetic Component' or card_type == 'Cosmetic Set' or data.mode == 'Miliastra Wonderland' then
| | weRank = data['rank'] |
| out.miliastra_wonderland = true | | weSpecialty = data['specialty'] |
| end
| | |
| if data.quality then | | elseif (lcType == 'enemy') then |
| out.defaults.quality = data.quality | | suffix = '' --icon |
| end
| | enemyType = data and data['type'] or '' |
| if data.title then | | enemyTier = data and data['tier'] or '' |
| out.defaults.caption = data.title | | enemyWeakness = data and data['weakness'] or '' |
| | imageSize = lib.ternary(args.mini == '1', 48, 70) |
| | |
| | elseif (lcType == 'drive disc') then |
| | suffix = ' Icon' |
| | |
| | elseif (lcType == 'npc') then |
| | suffix = ' Icon' |
| | |
| | elseif (lcType == 'outfit') then |
| | suffix = ' Icon' |
| | --Grabs Outfit Rank from Data to display icons |
| | outRank = data['rank'] |
| end | | end |
| end | | end |
| | |
| | local final_file = args.image or type .. ' ' .. lib.sanitizeFileName(item) .. suffix .. '.' .. imageExt |
| | |
| | local final_link = link .. link_suffix |
| | |
| | local file = '[[File:' .. final_file .. '|' .. imageSize .. 'px|alt=' .. item .. '|link=' .. final_link .. ']]' |
| | | |
| -- set other defaults based on card type | | local result = mw.html.create() |
| if card_type == 'Artifact Set' then
| |
| out.defaults.set = true
| |
| end
| |
| | | |
| -- add top-left icon (if not specified by 'icon' wikitext) | | local card_container = result:tag('div') |
| if out.icon == out.defaults.icon then
| | :addClass('card-container') |
| local iconImage = Icon.createIcon(out, 'icon_') | | :addClass('card-rank-' .. rank) |
| | | |
| iconImage.defaults.size = lib.ternary(out.mini, 15, 20)
| | if args.mini == "1" then |
| -- disable link if nolink is explicitly set, but icon_link is not
| | card_container:addClass('mini-card') |
| if out.nonDefaults.nolink then
| |
| iconImage.defaults.link = ''
| |
| end
| |
| out.icon = iconImage:buildString() | |
| end | | end |
|
| |
| -- add top-right icon (if not specified by 'icon_right' wikitext)
| |
| if out.icon_right == out.defaults.icon_right then
| |
| local iconImage = Icon.createIcon(out, 'icon_right_')
| |
| | | |
| iconImage.defaults.size = lib.ternary(out.mini, 15, 20)
| | local card_wrapper = card_container:tag('div') |
| -- disable link if nolink is explicitly set, but icon_link is not | | :addClass('card-wrapper') |
| if out.nonDefaults.nolink then | | |
| iconImage.defaults.link = ''
| | local card_body = card_wrapper:tag('div') |
| end | | :addClass('card-body') |
| out.icon_right = iconImage:buildString() | | |
| end
| | local card_link = card_wrapper:tag('div') |
| | :addClass('card-link') |
| | :wikitext('[[' .. final_link .. ']]') |
| | | |
| -- add top-right icon (if not specified by 'icon_bottom_left' wikitext) | | local card_image = card_body:tag('div') |
| if out.icon_bottom_left == out.defaults.icon_bottom_left then
| | :addClass('card-image-container') |
| local iconImage = Icon.createIcon(out, 'icon_bottom_left_') | | :wikitext(file) |
| | | |
| iconImage.defaults.size = lib.ternary(out.mini, 15, 20)
| | --[[if label and not (args.label == "0" or args.text == "0") then --]] |
| -- disable link if nolink is explicitly set, but icon_link is not
| | if (label or args.show_text) and (args.label ~= "0" or args.text ~= "0") then |
| if out.nonDefaults.nolink then | | if args.show_label == "1" or args.show_text == "1" then |
| iconImage.defaults.link = '' | | label = data and data.name or item |
| end | | end |
| out.icon_bottom_left = iconImage:buildString()
| |
| end
| |
| | | |
| -- add top-right icon (if not specified by 'icon_bottom_right' wikitext)
| | local card_label = card_container:tag('div') |
| if out.icon_bottom_right == out.defaults.icon_bottom_right then
| | :addClass('card-label') |
| local iconImage = Icon.createIcon(out, 'icon_bottom_right_')
| | :wikitext(label) |
|
| | end |
| iconImage.defaults.size = lib.ternary(out.mini, 10, 20)
| | |
| -- disable link if nolink is explicitly set, but icon_link is not
| | if (caption or args.show_caption) and args.show_caption ~= "0" then |
| if out.nonDefaults.nolink then | | if args.show_caption == "1" then |
| iconImage.defaults.link = '' | | caption = (data and data.name) or item |
| end | | end |
| out.icon_bottom_right = iconImage:buildString() | | local card_caption = card_container:tag('div') |
| end
| | :addClass('card-caption') |
|
| | :wikitext('[[', final_link, '|', caption, ']]') |
| -- add equipped icon
| | |
| if lib.isNotEmpty(out.equipped_name) then
| | if caption_width == 'auto' or lib.isEmpty(caption_width) then |
| local equippedImage, equippedType = Icon.createIcon(out, 'equipped_')
| | card_caption:addClass('auto-width') |
| if equippedType == 'Character' then | |
| equippedImage.defaults.size = 50 | |
| equippedImage.defaults.suffix = 'Side Icon'
| |
| equippedImage.defaults.alt = 'Equipped on ' .. equippedImage.alt
| |
| else | | else |
| equippedImage.defaults.alt = 'Equipped with ' .. equippedImage.alt | | card_caption:css('width', caption_width) |
| end
| |
| if out.nonDefaults.nolink then
| |
| equippedImage.defaults.link = ''
| |
| end | | end |
| out.equipped = equippedImage:buildString()
| |
| end | | end |
| | | |
| -- add enemy danger icon
| | if (isFirst) then |
| if out.danger then | | local card_mod_first = card_wrapper:tag('div') |
| out.icon_right = '[[File:Icon Warning.png|25x25px|link=|alt=Warning icon]]'
| | :addClass('card-modifier card-modifier-first') |
| out.icon_right_style = 'top: -8px; right: -10px; z-index: 1'
| | :wikitext('[[File:Icon Item First.png|x25px]]') |
| end | | end |
| | | |
| return out | | if (isUp) then |
| end
| | local card_mod_up = card_wrapper:tag('div') |
| | | :addClass('card-modifier card-modifier-up') |
| local function setCaptionWidth(node, width)
| | :wikitext('[[File:Icon Item UP.png|x25px]]') |
| if width == 'auto' then
| |
| node:addClass('auto-width')
| |
| else
| |
| node:css('width', width)
| |
| end | | end |
| end
| |
|
| |
| function p._main(args, frame)
| |
| local a = p._processArgs(args)
| |
| | | |
| local node_container = mw.html.create('div'):addClass('card-container') | | -- Attribute icon, applied automatically for agents or manually specified for anything else |
|
| | if args.mini ~= "1" then -- Only display the icons if mini is not set to "1" |
| if a.mini then | | if ne(agRank) then |
| node_container:addClass('mini-card')
| | card_body:addClass('card-rank-' .. string.lower(agRank)) |
| end
| | card_body:tag('span') |
|
| | :addClass('card-icon-rank') |
| if a.miliastra_wonderland then
| | :wikitext('[[File:Icon AgentRank ', agRank, '.png|alt=', agRank, '|link=|20px]]') |
| node_container:addClass('miliastra-wonderland') | | end |
| end
| | if ne(bbRank) then |
|
| | card_body:addClass('card-rank-' .. string.lower(bbRank)) |
| if a.text and tonumber((tostring(a.text):gsub(',', ''):gsub('[kKmMbBtT%%]$', '')))~=nil then
| | card_body:tag('span') |
| local mult = a.text:gsub('^.-([kKmMbBtT%%])$', '%1')
| | :addClass('card-icon-rank') |
| a.text = lib.thousandsSeparator((tostring(a.text):gsub(',', ''):gsub('[kKmMbBtT%%]$', ''))) .. (mult == a.text and '' or mult)
| | :wikitext('[[File:Icon Bangboo Rank ', bbRank, '.png|alt=', bbRank, '|link=|20px]]') |
| end
| | end |
|
| | if ne(weRank) then |
| -- create two wrapper divs for the main card body
| | card_body:addClass('card-rank-' .. string.lower(weRank)) |
| -- (required for CSS positioning and rounded corners, respectively)
| | card_body:tag('span') |
| local node_card = node_container:tag('span')
| | :addClass('card-icon-rank') |
| :addClass('card-wrapper')
| | :wikitext('[[File:Icon AgentRank ', weRank, '.png|alt=', weRank, '|link=|20px]]') |
| :tag('span')
| |
| :addClass('card-body')
| |
|
| |
| local node_image = node_card:tag('span')
| |
| :addClass('card-image-container') | |
| if lib.isNotEmpty(a.quality) then
| |
| if tonumber(a.quality)==nil then node_image:addClass('card-quality-' .. string.lower(a.quality:gsub('%D', ''):gsub(' ', '%-'))) end
| |
| node_image:addClass('card-quality-' .. string.lower(a.quality:gsub(' ', '%-')))
| |
| end
| |
| if lib.isNotEmpty(a.weapon) then node_image:addClass('card-weapon-' .. string.lower(a.weapon:gsub(' ', '%-'))) end
| |
| if lib.isNotEmpty(a.element) then node_image:addClass('card-element-' .. string.lower(a.element:gsub(' ', '%-'))) end
| |
| node_image:tag('span')
| |
| :wikitext(a.image:buildString())
| |
|
| |
| if lib.isNotEmpty(a.icon) then
| |
| node_card:tag('span')
| |
| :addClass('card-icon')
| |
| :cssText(a.icon_style)
| |
| :wikitext(a.icon)
| |
| end
| |
|
| |
| if a.mini then
| |
| if lib.isNotEmpty(a.text) and tonumber((a.text:gsub(',', ''):gsub('[kKmMbBtT%%]$', ''))) ~= nil then
| |
| node_card:tag('span'):addClass('card-text'):wikitext(a.text)
| |
| end | | end |
| if lib.isNotEmpty(a.icon_right) then | | if ne(agAttribute) then |
| node_card:tag('span') | | card_body:addClass('card-attribute-' .. string.lower(agAttribute)) |
| :addClass('card-icon-right') | | card_body:tag('span') |
| :cssText(a.icon_right_style) | | :addClass('card-icon-attribute') |
| :wikitext(a.icon_right)
| | :wikitext('[[File:Icon ', agAttribute, '.png|alt=', agAttribute, '|link=', agAttribute, '|20px]]') |
| end | | end |
| else
| | if ne(agSpecialty) then |
| if a.set then | | card_body:addClass('card-specialty-' .. string.lower(agSpecialty)) |
| node_card:tag('span') | | card_body:tag('span') |
| :addClass('card-set-container')
| | :addClass('card-icon-specialty') |
| :tag('span')
| | :wikitext('[[File:Icon ', agSpecialty, '.png|alt=', agSpecialty, '|link=', agSpecialty, '|20px]]') |
| :addClass('icon')
| |
| :wikitext('[[File:Set.svg|14px|link=|alt=Artifact set]]')
| |
| end | | end |
| if a.stars then | | if ne(weSpecialty) then |
| local starsImage = QUALITY_STARS[a.quality] | | card_body:addClass('card-specialty-' .. string.lower(weSpecialty)) |
| if starsImage then | | card_body:tag('span') |
| node_card:tag('span')
| | :addClass('card-icon-specialty') |
| :addClass('card-stars')
| | :wikitext('[[File:Icon ', weSpecialty, '.png|alt=', weSpecialty, '|link=', weSpecialty, '|20px]]') |
| :tag('span')
| |
| :wikitext(starsImage)
| |
| end
| |
| end | | end |
| if lib.isNotEmpty(a.icon_right) then | | if ne(outRank) then |
| node_card:tag('span') | | card_body:addClass('card-rank-' .. string.lower(outRank)) |
| :addClass('card-icon-right') | | card_body:tag('span') |
| :cssText(a.icon_right_style) | | :addClass('card-icon-rank') |
| :wikitext(a.icon_right)
| | :wikitext('[[File:Icon Item Rank ', outRank, '.png|alt=', outRank, '|link=|20px]]') |
| end | | end |
| if lib.isNotEmpty(a.icon_bottom_left) then | | local cinema = args.cinema or args.c or nil |
| node_card:tag('span') | | if ne(cinema) then |
| :addClass('card-icon-bottom-left') | | card_body:tag('span') |
| :cssText(a.icon_bottom_left_style) | | :addClass('card-cinema') |
| :wikitext(a.icon_bottom_left) | | :addClass('cinema-' .. cinema) |
| | :wikitext(' C', cinema) |
| | card_body:addClass('card-with-cinema') |
| end | | end |
| if lib.isNotEmpty(a.icon_bottom_right) then | | local phase = args.phase or args.p or nil |
| node_card:tag('span') | | if ne(phase) then |
| :addClass('card-icon-bottom-right') | | card_body:tag('span') |
| :cssText(a.icon_bottom_right_style) | | :addClass('card-phase') |
| :wikitext(a.icon_bottom_right) | | :addClass('phase-' .. phase) |
| | :wikitext(' P', phase) |
| | card_body:addClass('card-with-phase') |
| end | | end |
| if lib.isNotEmpty(a.equipped) then | | local notice = args.notice or nil |
| node_card:tag('span') | | if ne(notice) then |
| :addClass('card-equipped') | | card_body:tag('span') |
| :wikitext(a.equipped) | | :addClass('card-notice-label') |
| | :wikitext(notice) |
| | end |
| | if ne(enemyType) then |
| | card_body:tag('span') |
| | :addClass('card-icon-enemy-type') |
| | :wikitext('[[File:', enemyType, ' Icon.png|alt=', enemyType, '|link=', enemyType, '|28px]]') |
| end | | end |
|
| | if ne(enemyWeakness) then |
| if lib.isNotEmpty(a.text) then | | local weaknessContainer = card_body:tag('span') |
| local node_text = node_card:tag('span') | | :addClass('card-enemy-weaknesses') |
| :addClass('card-text') | |
| :addClass('card-font')
| |
| :wikitext(a.text)
| |
|
| |
| if a.text_size then
| |
| node_text:addClass('card-text-' .. a.text_size)
| |
| end
| |
| | | |
| if a.multiline_text then | | for weakness in lib.gsplit(enemyWeakness, ';') do |
| node_text:addClass('multi-line') | | weaknessContainer:wikitext('[[File:Icon ', weakness, '.png|16px|link=', weakness, '|Weak to ', weakness, ']]') |
| end | | end |
| end
| |
|
| |
| if lib.isNotEmpty(a.refinement) then
| |
| node_card:tag('span')
| |
| :addClass('card-refinement')
| |
| :addClass('refine-' .. a.refinement)
| |
| :wikitext(' R', (a.refinement:gsub('a', ''))) -- extra parens to take only first value returned from gsub
| |
| end
| |
| if lib.isNotEmpty(a.constellation) then
| |
| node_card:tag('span')
| |
| :addClass('card-constellation')
| |
| :addClass('constellation-' .. a.constellation)
| |
| :wikitext(' C', a.constellation)
| |
| node_card:addClass('card-with-constellation')
| |
| end | | end |
| end | | end |
| | | |
|
| | if ne(enemyTier) then |
| if a.show_caption and lib.isNotEmpty(a.caption) then | | card_body:addClass('card-enemy card-enemy-' .. enemyTier:gsub(' ', '')) |
| local node_caption = node_container:tag('span') | |
| :addClass('card-caption')
| |
| :wikitext(' ', a.nolink and a.caption or ('[[' .. a.final_link .. '|' .. a.caption .. ']]'))
| |
| setCaptionWidth(node_caption, a.caption_width)
| |
| end | | end |
| | | |
| if lib.isNotEmpty(a.note) then | | return tostring(result) |
| local node_note = node_container:tag('span')
| | end |
| :addClass('card-caption')
| | |
| :wikitext(a.note)
| | function p.getTypeAndData(name, type) |
| setCaptionWidth(node_note, a.caption_width)
| | local img_type = type or 'Item' |
| end | | local img_data = nil |
| | | |
| if a.mobile_list then | | for i, v in ipairs(allData) do |
| if a.text ~= '—' or a.caption or a.note then | | -- Only if the type was either not provided in the card args or if the provided type from card args is equal |
| local node_mobile_text = node_card
| | if lib.isEmpty(type) or v[1] == type then |
| :tag('span')
| | local data = v[2][name] |
| :addClass('card-mobile-text')
| | if data then |
| if a.nolink then
| | img_type = v[1] |
| node_mobile_text:wikitext(' ', a.caption)
| | img_data = data |
| else | | break |
| node_mobile_text:wikitext(' [[', a.final_link, '|', a.caption, ']]')
| |
| end
| |
| if tonumber((a.text:gsub(',', ''))) ~= nil then | |
| node_mobile_text:wikitext(' ×') | |
| end
| |
| if (a.caption or ''):gsub('­', '') ~= (a.text or ''):gsub('­', '') and a.text ~= '—' then
| |
| node_mobile_text:wikitext(' ', a.text) | |
| end
| |
| if a.note then
| |
| node_mobile_text:wikitext(' (', a.note, ')') | |
| end | | end |
| end | | end |
| end | | end |
| | | |
| if a.uses_deprecated_params then
| | return img_type, img_data |
| node_container:wikitext('[[Category:Pages Using Deprecated Template Parameters]]')
| |
| end
| |
| | |
| return node_container | |
| end
| |
| | |
| function p.templateData(frame)
| |
| return TemplateData.templateData(CARD_ARGS, {
| |
| description="This template is used to create an item display that is similar to the items in the Inventory in-game. Text can be shown below the item's image, background and stars can match the quality, refinement, icons, and set can be added.\n\nIf the image name matches an existing Item, then the quality will automatically be set.\n\nIf the image name matches an existing Character of Weapon, then the format will automatically change to match that type item.",
| |
| format='inline'
| |
| }, frame)
| |
| end
| |
| | |
| function p.syntax(frame)
| |
| return TemplateData.syntax(CARD_ARGS, frame)
| |
| end | | end |
|
| |
|
| return p | | return p |