Module:Card

local card = {}

-- Libraries of functions --

-- stands for High Frequency local HF = require('Module:HF') -- Parses invocation and template parameters, trims whitespace, and removes blanks. local getArgs = require('Dev:Arguments').getArgs -- Gives the name of the current page. It's expensive, so we only do it once. -- The _G then makes it global, available to all page functions. _G.page_title = mw.title.getCurrentTitle.text -- Parses template parameters from article, trims whitespace, and removes blanks. t_args = getArgs(frame, { trim = true, removeBlanks = true, parentOnly = true }) -- The occasions where we need the same "variables" to process multiple fields are global. --- _G.level_rank = ( string.match( (t_args['type2'] or '').. (t_args['type3'] or '').. (t_args['type4'] or ''), 'Xyz') and 'Rank' ) or 'Level' if t_args['kr_sets'] or t_args['ko_sets'] then _G.kr_release = 1 end if t_args['ae_sets'] then _G.ae_release = 1 end if t_args['tc_sets'] then _G.tc_release = 1 end if t_args['na_sets'] then _G.na_release = 1 end if t_args['eu_sets'] then _G.eu_release = 1 end if t_args['de_sets'] then _G.de_release = 1 end if t_args['it_sets'] then _G.it_release = 1 end if t_args['pt_sets'] then _G.pt_release = 1 end if t_args['sp_sets'] then _G.sp_release = 1 end if t_args['jp_sets'] or t_args['ja_sets'] then _G.ocg_jp = 1 end _G.ocg = (ocg_jp or '') .. (kr_release or '') .. (ae_release or '') .. (tc_release or '') if t_args['en_sets'] or na_release or eu_release or t_args['au_sets'] then _G.tcg_en = 1 end if t_args['fr_sets'] or t_args['fc_sets'] then _G.tcg_fr = 1 end _G.tcg = (tcg_en or '') .. (tcg_fr or '') .. (de_release or '') .. (it_release or '') .. (pt_release or '') .. (sp_release or '') _G.ocg_tcg = ocg .. tcg -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

--

-- -- Public functions (called from a Template or article) -- -- -- Primary image handler -- use and  inside function card.image_front -- | end function card.image_back -- | Back -- --> end

-- Machine translation link -- use inside -- "label" is optional, and defaults to 📃 function card.translate(frame) -- Parses invocation parameters, trims whitespace. local vars = getArgs(frame, { trim = true, frameOnly = true }) -- Parses template parameters, trims whitespace, and removes blanks. local t = getArgs(frame, { trim = true, removeBlanks = true, parentOnly = true }) assert(vars[1], 'No language code given for translation link.') assert(vars[2], 'No text given for translation link.') local language, parameter, label = vars[1], vars[2], vars[3] or '📃' local text = t[parameter] or '' local URI = mw.uri.new( { protocol = 'https', host = 'translate.google.com', path = '/#'..language..'/en/'..mw.uri.encode(text) } ) local element = mw.html.create('span'):addClass('plainlinks'):addClass('sysop-show') :wikitext(HF.ExternalLink( tostring(URI), label )):allDone return tostring(element) end

-- Render ultimate type -- use inside function card.type(frame) local t = getArgs(frame, { trim = true, removeBlanks = true, parentOnly = true }) local output = {} local type1, type2, type3, type4 = t['type'] or '', t['type2'] or nil, t['type3'] or nil, t['type4'] or nil local type1U = mw.getContentLanguage:ucfirst(type1) local switch = { [''] = "",       ['Equip Card'] = HF.Link(type1U).." ", ['Tip Card'] = HF.Link(type1U).." ", ['Strategy Card'] = HF.Link(type1U).." ", ['FAQ Card'] = HF.Link(type1U).." ", ['Illustration Card'] = HF.Link(type1U).." ", ['Counter'] = HF.Link(type1U).." ", }   local switch2 = { ['Flip'] = "Flip monster", ['Spirit'] = "Spirit monster", ['Union'] = "Union monster", ['Toon'] = "Toon monster", ['Gemini'] = "Gemini monster", ['Tuner'] = "Tuner monster", ['Dark Tuner'] = "Dark Tuner monster", }   if t['type'] or type2 or type3 or type4 then if type1:match('%(') then type1_prefix = type1:match('(%a*)%(') else type1_prefix = type1 end table.insert(output,            switch[type1] or HF.Link(type1U, type1_prefix)..' ' ) if type2 then table.insert(output, HF.Link( switch2[type2] or type2..' Monster', type2)) end if type3 then table.insert(output, HF.Link( switch2[type3] or type3..' Monster', type3).." ") end if type4 then table.insert(output, HF.Link( type4..' Monster', type4).." ") end end return table.concat(output, ' / ') end

-- use inside function card.card_type (frame) local t = getArgs(frame, { trim = true, removeBlanks = true, parentOnly = true }) if t.type2 == "Token" then token = 1 else token = nil end if t.atk or t.def or t.level or t.rank or t.link_arrows or token == 1 then monster = 1 else monster = nil end local o = {} if monster or t.card_type then table.insert(o, HF.Link( (t.card_type or 'Monster')..' Card', (t.card_type or 'Monster'))) if t.card_type == 'Speed Spell' then table.insert(o, ' ') elseif not monster then table.insert(o, '') end table.insert(o, ' '..(t.card_type or 'Monster')..'| ]]') if monster then table.insert(o, ' ') end end return table.concat(o) end

-- use inside function card.level (frame) local t = getArgs(frame, { trim = true, removeBlanks = true, parentOnly = true }) local stars = t.level or t.rank or nil local o = {} if stars then table.insert(o, HF.Link(level_rank..' '..stars..' Monster Cards', stars)) if ocg_tcg or vg then table.insert(o,            string.rep( '', ( type(stars) == 'number' and stars or 1 ) )        ) end table.insert(o,           ' '..            ' '..            ' '..            ' '    ) return table.concat(o) end end

function card.atkdef --    -- end

function card.passcode --   --    --    --{{ #vardefine: $token-counter | {{ #var: $token | {{ #var: $counter }} }} --{{ #vardefine: $limitation_text | {{ #if: {{{limitation_text|}}} | {{{limitation_text}}} | {{ #if: {{ #var: $token-counter }} | This card cannot be in a Deck. }} }} }}   --{{ #vardefine: $kr_release | {{ #if: {{{kr_sets|}}}{{{ko_sets|}}} | 1 }}}} --{{ #vardefine: $ae_release | {{ #if: {{{ae_sets|}}} | 1 }}}} --{{ #vardefine: $tc_release | {{ #if: {{{tc_sets|}}} | 1 }}}} --{{ #vardefine: $na_release | {{ #if: {{{na_sets|}}} | 1 }}}} --{{ #vardefine: $eu_release | {{ #if: {{{eu_sets|}}} | 1 }}}} --{{ #vardefine: $de_release | {{ #if: {{{de_sets|}}} | 1 }}}} --{{ #vardefine: $it_release | {{ #if: {{{it_sets|}}} | 1 }}}} --{{ #vardefine: $pt_release | {{ #if: {{{pt_sets|}}} | 1 }}}} --{{ #vardefine: $sp_release | {{ #if: {{{sp_sets|}}} | 1 }}}} --{{ #vardefine: $ocg-jp  | {{ #if: {{{jp_sets|}}}{{{ja_sets|}}} | 1 }}}} --{{ #vardefine: $ocg     | {{ #var: $ocg-jp }}{{ #var: $kr_release }}{{ #var: $ae_release }}{{ #var: $tc_release }}}} --{{ #vardefine: $tcg-en  | {{ #if: {{{en_sets|}}}{{ #var: $na_release }}{{ #var: $eu_release }}{{{au_sets|}}} | 1 }}}} --{{ #vardefine: $tcg-fr  | {{ #if: {{{fr_sets|}}}{{{fc_sets|}}} | 1 }}}} --{{ #vardefine: $tcg     | {{ #var: $tcg-en }}{{ #var: $tcg-fr }}{{ #var: $de_release }}{{ #var: $it_release }}{{ #var: $pt_release }}{{ #var: $sp_release }}}} --{{ #vardefine: $ocg-tcg | {{ #var: $ocg }}{{ #var: $tcg }}}} --{{ #vardefine: $passcode  | {{{passcode|}}}}} -- {{CardTable2/row | check = {{ #var: $passcode }} | header = Passcode| data   = {{  | checkfail = {{ #if: {{ #var: $ocg-tcg }}    | {{ #if: {{ #var: $limitation_text }}      || {{ #if: {{ #var: $non-game }}{{ #pos: {{{image}}} | -BD-JP- }} ||  }}    }}  }}}} end

function card.limitation_text --{{ #vardefine: $token   | {{ #ifeq: {{{type2}}} | Token | 1 }}}} --{{ #vardefine: $counter | {{ #ifeq: {{{type}}} | Counter | 1 }}}} --{{ #vardefine: $token-counter | {{ #var: $token | {{ #var: $counter }} }} --{{ #vardefine: $limitation_text | {{ #if: {{{limitation_text|}}} | {{{limitation_text}}} | {{ #if: {{ #var: $token-counter }} | This card cannot be in a Deck. }} }} }} --{{CardTable2/row| check = {{ #var: $limitation_text }}| header = Limitation text| data   = {{ #var: $limitation_text }} }} end

function card.effecttypes --{{ #vardefine: $card_type | {{{card_type|}}}}} --{{ #vardefine: $effect_monster  | {{ #if: {{{effect_types|}}}{{ #pos: {{{type2}}}{{{type3}}}{{{type4}}} | Effect }} | 1 }}}} --{{CardTable2/row| check = {{{effect_types|}}}{{{pendulum_effect_types|}}}| header = Card effect types| dataclass = hlist hcomma| data   = {{ #if: {{{pendulum_effect_types|}}} | ; Pendulum Effect {{CardTable2/effect|{{{pendulum_effect_types}}}|y}}{{ #if: {{{effect_types|}}} | ; Monster Effect }} }}{{ #if: {{{effect_types|}}} | {{CardTable2/effect|{{{effect_types}}}|{{ #var: $card_type }}}} }}| checkfail = {{ #if: {{ #var: $effect_monster }}{{ #var: $card_type }} |  }}}} end

--function card.continuous --end

function card.statuses --{{ #vardefine: $token   | {{ #ifeq: {{{type2}}} | Token | 1 }}}} --{{ #vardefine: $counter | {{ #ifeq: {{{type}}} | Counter | 1 }}}} --{{ #vardefine: $token-counter | {{ #var: $token | {{ #var: $counter }} }} --{{ #vardefine: $kr_release | {{ #if: {{{kr_sets|}}}{{{ko_sets|}}} | 1 }}}} --{{ #vardefine: $ae_release | {{ #if: {{{ae_sets|}}} | 1 }}}} --{{ #vardefine: $tc_release | {{ #if: {{{tc_sets|}}} | 1 }}}} --{{ #vardefine: $ocg-jp  | {{ #if: {{{jp_sets|}}}{{{ja_sets|}}} | 1 }}}} --{{ #vardefine: $ocg     | {{ #var: $ocg-jp }}{{ #var: $kr_release }}{{ #var: $ae_release }}{{ #var: $tc_release }}}} --{{ #vardefine: $non-game | {{ #switch: {{ lc: {{{type}}} }} | illustration card | tip card | strategy card | faq card | non-game card | character card = 1 }}}} --{{ #if: {{ #var: $non-game }} || {{ #if: {{ #var: $ocg }} | {{ #vardefine: $ocg-status | {{ #if: {{{ocg|}}} | {{{ocg}}} | {{ #if: {{ #var: $token-counter }} | Legal | Unlimited }} }} }} }}{{ #if: {{ #var: $tcg }}  | {{ #vardefine: $adv-status  | {{ #if: {{{adv|}}} | {{{adv}}} | {{ #if: {{ #var: $token-counter }} | Legal | Unlimited }} }}    }}{{ #vardefine: $trad-status | {{ #if: {{{trad|}}} | {{{trad}}} | {{ #ifeq: {{ #var: $adv-status }} | Forbidden | Limited }} }}    }}{{ #vardefine: $trad-status | {{ #ifeq: {{ #var: $adv-status }} | {{ #var: $trad-status }} || {{ #var: $trad-status }} }}    }}{{ #vardefine: $adv-status  | {{ #if: {{ #var: $trad-status }} | {{ #var: $adv-status }} | {{ #ifeq: {{ #var: $ocg-status }} | {{ #var: $adv-status }} || {{ #var: $adv-status }} }} }}    }}  }}{{ #vardefine: $statuscount | {{ #expr: {{ #if: {{ #var: $ocg }} | 1 | 0 }} + {{ #if: {{ #var: $adv-status }} | 1 | 0 }} + {{ #if: {{ #var: $trad-status }} | 1 | 0 }} }}  }}{{ #ifexpr: {{ #var: $statuscount }} > 0    | Statuses {{ #if: {{ #var: $ocg }} |   {{  {{ #switch: {{ lc: {{ #var: $ocg-status }} }} | not yet released | not yet legal =   }} {{ #if: {{ #var: $adv-status }} | (OCG) | {{ #if: {{ #var: $tcg }} |   {{ #switch: {{ lc: {{ #var: $ocg-status }} }} | not yet released | not yet legal =   }} }} }}   }}{{ #if: {{ #var: $tcg }} | {{ #if: {{ #var: $adv-status }} |   {{ #if: {{ #var: $ocg }} |  }}{{  (TCG Advanced{{ #if: {{ #var: $trad-status }} || and Traditional }}) {{ #if: {{ #var: $trad-status }} ||   }}{{ #switch: {{ lc: {{ #var: $adv-status }} }} | not yet released | not yet legal =   }}   {{ #if: {{ #var: $trad-status }} | {{  (TCG Traditional)   }}    }}  }} }}}} end

-- Formats card sets in rows -- Detects if the content uses a wrapper template, or is data -- use {{#invoke:Card|cardset_format|{{{parameter}}}|}} inside function card.cardset_format (frame) local inv_args = getArgs(frame, { trim = true, frameOnly = true }) local out = {} -- no logic yet table.insert(out, _cardset_envelope(inv_args)) return table.concat(out) end

function card.search_categories end

function card.other end

function card.external_links end

function card.card_table end

function card.sorting end

function card.semantics end

-- Internal functions (used in this and other Modules --

-- Create an envelope for existing tables function _cardset_envelope (inv_args) local envelope = mw.html.create('div') :addClass('mw-collapsible'):addClass('mw-collapsed') :attr('data-expandtext','Show'):attr('data-collapsetext','Hide') :wikitext(inv_args[1]):allDone return tostring(envelope) end

-- If card set content passed is only data, build a table around it function _cardset_table end

-- Build table rows for _cardset_table function _cardset_row end

- -- Output (send it back to whatever called it) -- - return card