Difference between pages "Gandora the Dragon of Destruction" and "Module:Input parser"

From Yugipedia
(Difference between pages)
Jump to: navigation, search
 
(Also check if the linked text contains only whitespace)
 
Line 1: Line 1:
{{Redirect|Gandora|the archetype|Gandora (archetype)}}
+
--[[
{{CardTable2
+
Common functions for helping with extracting data from wikitext input
| fr_name              = Gandora le Dragon de la Destruction
+
]]--
| de_name              = Gandora der Drache der Zerstörung
+
 
| it_name              = Gandora, il Drago della Distruzione
+
 
| pt_name              = Gandora o Dragão da Destruição
+
local inputParser = {}
| es_name              = Gandora el Dragón de la Destrucción
+
 
| ja_name              = {{Ruby|破|は}}{{Ruby|壊|かい}}{{Ruby|竜|りゅう}}ガンドラ
+
-- Convert an unordered list (bulleted list) to an array (i.e. table)
| romaji_name          = Hakairyū Gandora
+
-- e.g. `'\n* A\n* B\n* C'` -> `{ 'A', 'B', 'C' }`
| ko_name              = 파괴룡 간드라
+
--
| ko_rr_name            = Pagwiryong Gandeura
+
-- @param text string unordered list in wikitext
| sc_name              = 破坏龙 钢多拉
+
-- @return table
| image                = GandoratheDragonofDestruction-MIL1-EN-C-1E.png
+
function inputParser.ulToArray(text)
| attribute            = DARK
+
-- No text, return empty table
| types                = Dragon / Effect
+
if (not text) then return {} end
| atk                  = 0
+
 
| def                  = 0
+
-- remove initial `*` and spacing
| level                = 8
+
local trimmedText = mw.text.trim(text, '* \n')
| password              = 64681432
+
 
| effect_types          = Summoning condition, Ignition, Lingering, Trigger
+
-- If the text is empty or only contained whitespace, return empty table
| lore                  = Cannot be [[Special Summon]]ed. You can [[pay]] half your [[LP]]; [[destroy]] as many cards on the [[field]] as possible (other than this card), and if you do, [[banish]] them. This card gains 300 [[ATK]] for each card destroyed this way. [[Once per turn]], during the [[End Phase]], if this card was [[Normal Summon|Normal]] or [[Flip Summon]]ed this [[turn]]: Send it to the [[Graveyard]].
+
if (trimmedText == '') then return {} end
| fr_lore              = Non Invocable Spécialement. Vous pouvez payer la moitié de vos LP ; détruisez autant de cartes sur le Terrain que possible (cette carte exclue), et si vous le faites, bannissez-les. Cette carte gagne 300 ATK pour chaque carte détruite de cette façon. Une fois par tour, durant la End Phase, si cette carte a été Invoquée Normalement ou par Flip ce tour : envoyez-la au Cimetière.
+
 
| de_lore              = Kann nicht als Spezialbeschwörung beschworen werden. Du kannst die Hälfte deiner LP zahlen; zerstöre so viele Karten auf dem Spielfeld wie möglich (außer dieser Karte) und falls du dies tust, verbanne sie. Diese Karte erhält 300 ATK für jede Karte, die auf diese Art zerstört wurde. Einmal pro Spielzug, während der End Phase, falls diese Karte in diesem Spielzug als Normal- oder Flippbeschwörung beschworen wurde: Lege sie auf den Friedhof.
+
-- Split by `*`, surrounded in optional spaces
| it_lore              = Non può essere Evocato Specialmente. Puoi pagare la metà dei tuoi LP; distruggi tante carte sul Terreno quante possibile (a parte questa carta) e, se lo fai, bandiscile. Questa carta guadagna 300 ATK per ogni carta distrutta in questo modo. Una volta per turno, durante la End Phase, se questa carta è stata Evocata Normalmente o per Scoperta in questo turno: mandala al Cimitero.
+
return mw.text.split(trimmedText, '%s*\*%s*')
| pt_lore              = Não pode ser Invocado por Invocação-Especial. Você pode pagar metade dos seus PV; destrua tantos cards no campo quanto possível (que não sejam este card) e, se isso acontecer, bana-os. Este card ganha 300 de ATK para cada card destruído desta forma. Uma vez por turno, durante a Fase Final, se este card foi Invocado por Invocação-Normal ou Virar neste turno: envie-o para o Cemitério.
+
end
| es_lore              = No puede ser Invocado de Modo Especial. Puedes pagar la mitad de tus LP; destruye tantas cartas en el Campo como sea posible (que no sean esta carta), y, si lo haces, destiérralas. Esta carta gana 300 ATK por cada carta destruida de esta forma. Una vez por turno, durante la End Phase, si esta carta fue Invocada de Modo Normal o por Volteo en este turno: mándala al Cementerio.
+
 
| ja_lore              = このカードは特殊召喚できない。①:LPを半分払って発動できる。フィールドの他のカードを全て破壊し除外する。このカードの攻撃力は、この効果で破壊したカードの数×300アップする。②:このカードを召喚・反転召喚したターンのエンドフェイズに発動する。このカードを墓地へ送る。
+
-- Parse data from a wikitext link
| ko_lore              = 이 카드는 특수 소환할 수 없다. ①: LP를 절반 지불하고 발동할 수 있다. 이 카드 이외의 필드의 카드를 전부 파괴하고 제외한다. 이 카드의 공격력은, 이 효과로 파괴한 카드의 수 × 300 올린다. ②: 이 카드를 일반 소환 / 반전 소환한 턴의 엔드 페이즈에 발동한다. 이 카드를 묘지로 보낸다.
+
-- e.g. `'[[Metal Fiend Token (manga)|Metal Devil]]'` -> `{ link = 'Metal Fiend Token (manga)', text = 'Metal Devil' }`
| sc_lore              = 此卡不可特殊召唤。<br />①:支付一半LP可以发动。将场上的其他卡全部破坏并除外。此卡的攻击力上升相当于以此效果破坏的卡的数量×300的数值。<br />②:此卡召唤・反转召唤的回合的结束阶段发动。将此卡送至墓地。
+
-- @param linkInput string
| en_sets              =
+
-- @return table
CT07-EN020; Collectible Tins 2010 Wave 2; Super Rare
+
function inputParser.parseLink(linkInput)
SP13-EN041; Star Pack 2013; Common, Starfoil Rare
+
if (not linkInput) then
YGLD-ENC03; Yugi's Legendary Decks; Common
+
return { link = nil, text = nil }
MIL1-EN005; Millennium Pack; Common
+
end
| na_sets              =
+
 
JUMP-EN028; Shonen Jump Vol. 7, Issue 1 promotional card; Ultra Rare
+
--[[
| fr_sets              =
+
Pattern for a link in wikitext
CT07-FR020; Collectible Tins 2010 Wave 2; Super Rare
+
- two opening square brackets
SP13-FR041; Star Pack 2013; Common, Starfoil Rare
+
- any number of non-`|` non-`]` characters <-- first capture group
YGLD-FRC03; Yugi's Legendary Decks; Common
+
- optional pipe character
MIL1-FR005; Millennium Pack; Common
+
- optional amount of any characters <-- second capture group
| de_sets              =  
+
- two closing square brackets
CT07-DE020; Collectible Tins 2010 Wave 2; Super Rare
+
]]--
SP13-DE041; Star Pack 2013; Common, Starfoil Rare
+
local pattern = '%[%[([^|%]]*)|?(.-)%]%]'
YGLD-DEC03; Yugi's Legendary Decks; Common
+
 
MIL1-DE005; Millennium Pack; Common
+
-- Store the first capture group as the link
| it_sets              =  
+
-- And the second as the display text
CT07-IT020; Collectible Tins 2010 Wave 2; Super Rare
+
local link, text = linkInput:match(pattern)
SP13-IT041; Star Pack 2013; Common, Starfoil Rare
+
 
YGLD-ITC03; Yugi's Legendary Decks; Common
+
-- If the text doesn't match the pattern, assume there's no link, only text
MIL1-IT005; Millennium Pack; Common
+
if (not link) then
| pt_sets              =  
+
return { link = nil, text = linkInput }
SP13-PT041; Star Pack 2013; Common, Starfoil Rare
+
end
YGLD-PTC03; Yugi's Legendary Decks; Common
+
 
MIL1-PT005; Millennium Pack; Common
+
-- If the text is empty or only contains whitespace, default it to the link
| sp_sets              =
+
if (not text or (type(text) == 'string' and mw.text.trim(text) == '')) then
CT07-SP020; Collectible Tins 2010 Wave 2; Super Rare
+
text = link
SP13-SP041; Star Pack 2013; Common, Starfoil Rare
+
end
YGLD-SPC03; Yugi's Legendary Decks; Common
+
 
MIL1-SP005; Millennium Pack; Common
+
return { link = link, text = text }
| jp_sets              =  
+
end
VB8-JP001; The Valuable Book 8 promotional cards; Ultra Rare
+
 
MFC2-JP005; Monster Figure Collection Volume 2 promotional cards; Duel Terminal Normal Parallel Rare
+
--[[
15AY-JPC03; Memories of the Duel King: Ceremonial Battle Arc; Common
+
A number of modules accept input formatted like this:
MP01-JP008; Millennium Pack (OCG); Millennium Super Rare
+
List item 1; // arg1::value1; arg2; arg3::value3
VF16-JPP01; Jump Victory Carnival 2016 - Promotion Pack; Normal Parallel Rare
+
List Item 2; // arg1::value1; arg2; arg3::value3
LEDE-JPS01; Legacy of Destruction +1 Bonus Pack; Quarter Century Secret Rare
+
 
| kr_sets              =
+
This function gets the arguments after the double forward slash.
PP03-KR024; Premium Pack Vol.3; Ultra Rare
+
 
MP01-KR008; Millennium Pack (OCG); Millennium Super Rare
+
e.g.
15AY-KRC03; Memories of the Duel King: Ceremonial Battle Arc; Common
+
Mystical Moon; 800 // debut; mentioned; dub; qty::2
| sc_sets              =  
+
becomes
LEDE-SC081; Legacy of Destruction; Common
+
{ ['debut'] = true, ['mentioned'] = true, ['dub'] = true, ['qty'] = '2' }
LEDE-SCS01; Legacy of Destruction +1 Bonus Pack; Quarter Century Secret Rare
+
]]--
| ygo_sets              =
+
--
'''[[Mileage Points 4 (YGOO-BP)|Mileage Points 4]]'''
+
-- @param lineText string
| archseries            = Gandora (archetype)
+
-- @return table
| related_to_archseries =  
+
function inputParser.getLineArgs(lineText)
* Shining Sarcophagus (series)
+
-- Get text after the `//`
* Signature move
+
local argsText = mw.text.split(lineText, '%s*//%s*')[2] or ''
| action                =  
+
 
* Sends from field to Graveyard
+
-- Split by semicolons surrounded by any amount of spaces
* Activates during the turn in which it was Normal Summoned
+
-- e.g. `'[[Mystical Moon]] // debut; mentioned; dub; qty::2'`
* Activates during the turn in which it was Flip Summoned
+
-- becomes `{ 'debut', 'mentioned', 'dub', 'qty::2' }`
* Sends itself from field to Graveyard
+
local argsArr = mw.text.split(argsText, '%s*;%s*')
| stat_change          = This card gains ATK
+
 
| m/s/t                =  
+
-- Pattern for matching two pieces of text separated by a double semicolon
* Destroys Spell Cards
+
local pattern = '(.*)::(.*)'
* Destroys Trap Cards
+
* Destroys Monster Cards
+
local args = {}
| summoning            = Cannot be Special Summoned
+
 
| banished              =  
+
-- Parse the named variables in the list
* Banishes from your field
+
-- e.g. `{ 'debut', 'mentioned', 'dub', 'qty::2' }`
* Banishes from your opponent's field
+
-- becomes `{ ['debut'] = true, ['mentioned'] = true, ['dub'] = true, ['qty'] = '2' }
| life_points          =
+
for _, arg in pairs(argsArr) do
* Halves the player's LP
+
local param, value = arg:match(pattern)
* Pays Life Points for cost
+
| database_id          = 6076
+
if (not param) then
}}
+
-- table.insert(args, arg)
 +
args[arg] = true
 +
else
 +
args[param] = value
 +
end
 +
end
 +
 
 +
return args
 +
end
 +
 
 +
return inputParser

Latest revision as of 20:47, 1 April 2024

--[[
Common functions for helping with extracting data from wikitext input
]]--


local inputParser = {}

-- Convert an unordered list (bulleted list) to an array (i.e. table)
-- e.g. `'\n* A\n* B\n* C'` -> `{ 'A', 'B', 'C' }`
--
-- @param text string unordered list in wikitext
-- @return table
function inputParser.ulToArray(text)
	-- No text, return empty table
	if (not text) then return {} end

	-- remove initial `*` and spacing
	local trimmedText = mw.text.trim(text, '* \n')

	-- If the text is empty or only contained whitespace, return empty table 
	if (trimmedText == '') then return {} end

	-- Split by `*`, surrounded in optional spaces
	return mw.text.split(trimmedText, '%s*\*%s*')
end

-- Parse data from a wikitext link
-- e.g. `'[[Metal Fiend Token (manga)|Metal Devil]]'` -> `{ link = 'Metal Fiend Token (manga)', text = 'Metal Devil' }`
-- @param linkInput string
-- @return table
function inputParser.parseLink(linkInput)
	if (not linkInput) then
		return { link = nil, text = nil }
	end

	--[[
	Pattern for a link in wikitext
	- two opening square brackets
	- any number of non-`|` non-`]` characters <-- first capture group
	- optional pipe character
	- optional amount of any characters <-- second capture group
	- two closing square brackets
	]]--
	local pattern = '%[%[([^|%]]*)|?(.-)%]%]'

	-- Store the first capture group as the link
	-- And the second as the display text
	local link, text = linkInput:match(pattern)

	-- If the text doesn't match the pattern, assume there's no link, only text
	if (not link) then
		return { link = nil, text = linkInput }
	end

	-- If the text is empty or only contains whitespace, default it to the link
	if (not text or (type(text) == 'string' and mw.text.trim(text) == '')) then
		text = link
	end

	return { link = link, text = text }
end

--[[
A number of modules accept input formatted like this:
List item 1; // arg1::value1; arg2; arg3::value3
List Item 2; // arg1::value1; arg2; arg3::value3

This function gets the arguments after the double forward slash.

e.g.
Mystical Moon; 800 // debut; mentioned; dub; qty::2
becomes
{ ['debut'] = true, ['mentioned'] = true, ['dub'] = true, ['qty'] = '2' }
]]--
--
-- @param lineText string
-- @return table
function inputParser.getLineArgs(lineText)
	-- Get text after the `//`
	local argsText = mw.text.split(lineText, '%s*//%s*')[2] or ''

	-- Split by semicolons surrounded by any amount of spaces
	-- e.g. `'[[Mystical Moon]] // debut; mentioned; dub; qty::2'`
	-- becomes `{ 'debut', 'mentioned', 'dub', 'qty::2' }`
	local argsArr = mw.text.split(argsText, '%s*;%s*')

	-- Pattern for matching two pieces of text separated by a double semicolon
	local pattern = '(.*)::(.*)'
	
	local args = {}

	-- Parse the named variables in the list
	-- e.g. `{ 'debut', 'mentioned', 'dub', 'qty::2' }`
	-- becomes `{ ['debut'] = true, ['mentioned'] = true, ['dub'] = true, ['qty'] = '2' }
	for _, arg in pairs(argsArr) do
		local param, value = arg:match(pattern)
		
		if (not param) then
			-- table.insert(args, arg)
			args[arg] = true
		else
			args[param] = value
		end
	end

	return args
end

return inputParser