Module:Card

local p  = {} local lib = require('Module:Feature') local ElementIcon = require("Module:Icon/Element")

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {		parentFirst = true,		wrapper = { 'Template:Card' }	}) return p._main(args, frame) end

function p._main(args, frame) -- load data from subpages local data = nil local items = mw.loadData('Module:Card/items') local foods = mw.loadData('Module:Card/foods') local characters = mw.loadData('Module:Card/characters') local weapons = mw.loadData('Module:Card/weapons') local furnishings = mw.loadData('Module:Card/furnishings')

-- declare local variables and set defaults local name = args.name or args[1] or args.character or 'Unknown' local type = args.type or 'Item' local rarity = args.rarity or '0' local link = args.link or name local text = args.text or args[2] or '&mdash;' local ext = args.ext or 'png' local icon = args.icon or nil local icon_style = args.icon_style or nil local caption = lib.ternary(args.caption ~= nil, lib.ternary(tostring(args.caption) == '1', link, args.caption), nil) local caption_width = args.caption_width or '' local refinement = args.refinement or nil local constellation = args.c or args.constellation or nil local stars = args.stars or nil local set = args.set or nil local mobile = args.mobile or nil local mobileHideText = tostring(args.mobileHideText) == "1" or false

-- set local variables based on type if items[name] ~= nil or items[name:gsub("Instructions: ", "")] ~= nil or items[name:gsub("Diagram: ", "")] ~= nil then data = items[name] or items[name:gsub("Instructions: ", "")] or items[name:gsub("Diagram: ", "")] type = "Item" rarity = rarity == "0" and data.rarity or rarity elseif foods[name] ~= nil or foods[name:gsub("Delicious ", "")] ~= nil or foods[name:gsub("Suspicious ", "")] ~= nil or foods[name:gsub("Recipe: ", "")] ~= nil then data = foods[name] or foods[name:gsub("Delicious ", "")] or foods[name:gsub("Suspicious ", "")] or foods[name:gsub("Recipe: ", "")] type = "Item" rarity = rarity == "0" and data.rarity or rarity elseif characters[name] ~= nil then data = characters[name] type = "Character" rarity = rarity == "0" and data.rarity or rarity text = lib.ternary(text == "&mdash;", data.name or name, text) local element = lib.ternary(args.element ~= nil, args.element, lib.ternary(data.element ~= "Adaptive" and data.element ~= "", data.element, nil)) icon = lib.ternary(element ~= nil, tostring(ElementIcon._main({element, 20})), nil) name = name .. "_Thumb" elseif weapons[name] ~= nil or weapons[name:gsub("Diagram: ", "")] ~= nil then data = weapons[name] or weapons[name:gsub("Diagram: ", "")] type = "Weapon" rarity = rarity == "0" and data.rarity or rarity text = lib.ternary(text == "&mdash;", "Lv. 1", text) refinement = refinement or "1" elseif furnishings[name] ~= nil or furnishings[name:gsub("Blueprint: ", "")] ~= nil then data = furnishings[name] or furnishings[name:gsub("Blueprint: ", "")] type = "Item" rarity = rarity == "0" and data.rarity or rarity else if type == "Character" then name = name .. "_Thumb" if args.element ~= nil then icon = tostring(ElementIcon._main({args.element, 20})) end elseif type == "Enemy" then name = name .. "_Icon" if args.element ~= nil then icon = tostring(ElementIcon._main({args.element, 20})) end end end

-- change name and add icon for blueprints and recipes local nameReplace = name if nameReplace:find("Blueprint: ") then nameReplace = nameReplace:gsub("Blueprint: ", "") icon = "" elseif nameReplace:find("Recipe: ") then nameReplace = nameReplace:gsub("Recipe: ", "") icon = "" elseif nameReplace:find("Instructions: ") then nameReplace = nameReplace:gsub("Instructions: ", "") icon = "" elseif nameReplace:find("Diagram: ") then nameReplace = nameReplace:gsub("Diagram: ", "") icon = "" end

local filename = 'File:' .. type .. '_' .. nameReplace .. '.' .. ext

local node_result    = mw.html.create local node_container = mw.html.create local node_optional  = mw.html.create

local rarityStars = { ['0'] = ,		['1'] = ,		['2'] = ,		['3'] = ,		['4'] = ,		['5'] = 	}

if caption then local node_caption = node_result :tag('div') :addClass('card_with_caption hidden') :node(node_container) if caption_width ~= '' then node_caption :css('width', caption_width) end else node_result :node(node_container) end

node_container :tag('div') :addClass('card_container card_' .. rarity .. ' hidden') :wikitext('') :tag('div') :addClass('card_image') :wikitext('74x74px|link=', link, '') :tag('div') :addClass('card_corner') :wikitext('') :done :done :tag('div') :addClass('card_text') :tag('span') :addClass('card_font') :wikitext(text) :done :done :node(node_optional)

if refinement then node_optional :tag('div') :addClass('card_refinement refine_' .. refinement) :wikitext(refinement) :done end

if constellation then node_optional :tag('div') :addClass('card_constellation') :wikitext(constellation) :done end

if icon then node_optional :tag('div') :addClass('card_icon') :cssText(icon_style) :wikitext(icon) :done end

if set then node_optional :tag('span') :addClass('card_set_container') :tag('span') :addClass('icon') :wikitext('') :done :done end

if stars then node_optional :tag('div') :addClass('card_stars star_' .. rarity) :wikitext(rarityStars[rarity]) :done end

if caption then node_container :tag('div') :addClass('card_caption') :wikitext(, caption, ) :done end

-- MOBILE LOGIC local node_mobile = mw.html.create local icon       = icon or '' local filestring = '20px|link=' .. link .. '' local stars      = lib.ternary(stars == "1", rarity .. '★', '') local name       = lib.ternary(name == text or mobileHideText or type == "Character", '',  text) local link       =  .. lib.ternary(caption ~= nil and caption ~= 1, caption, link) ..  local s          = icon .. filestring .. stars if (name ~= link or name ~= caption or name ~= "Lv. 1") and name ~= '' then s = s .. ' ' .. name .. ' ' .. link else s = s .. ' ' .. link end

if mobile == "bulleted" then node_mobile :tag('li') :addClass('mobileHide') :wikitext(s) elseif mobile == "inline" then node_mobile :tag('div') :addClass('mobileHide') :addClass('wds-dropdown') :wikitext(s) else --block node_mobile :tag('div') :addClass('mobileHide') :wikitext(s) end

node_result :node(node_mobile)

return node_result end

return p