Open main menu

Yugipedia β

Changes

Module:Card type

1,210 bytes added, 6 years ago
Fix on table count. Convert card name to page name sooner (on main). Start _type functions. _link.
-- @@@ for ideas.
local CardType = {};
 
------------------
-- Aux functions:
------------------
-- Trim function:
if s and not v:match( '^%s*$' ) then
return mw.text.trim( s ); -- If not nil nor empty.
end
end
 
function _link( v, label )
if type( v ) == 'string' then
return '[['..v..'|'..(label or mw.text.split( v, ' %(' )[1])..']]';
end
if type( v ) == 'table' then
return v --@@@
end
end
local counter = 0;
for _,v in pairs( t ) do
counter = counter + 1;
end
for _,v in ipairs( t ) do
counter = counter + 1;
end
function _error( message )
local _error = mw.html.create( 'div' ) :tag( 'strong' ):addClass( 'error' ):wikitext( 'Error: '..message ):done() :AllDone();
return tostring( _error );
end
-- Similar to #show parser function.
-- Returns table with the results.
function CardType._show( namepage, property ) local page = name:gsub-- At this point, SMW is enabled and «name» is formatted properly ( '#', '' as pagename);.
local result = mw.smw.ask{ '[['..page..']]', '?'..property..'=', mainlabel = '-' };
return t;
end
 
-------------------
-- Main functions:
-------------------
function _monster( card )
return
end
 
function _spell( card )
return
end
 
function _trap( card )
return
end
 
function _counter()
return _link( 'Counter' );
end
 
function _type( card )
local _cardTypeTable = _show( card, 'Card type' );
local _cardType = _cardTypeTable and table.concat( _cardTypeTable, '\n' ):lower();
if not _trim( _cardType ) then
return _error( 'On «_type»; No card type available!' );
end
if _cardType:match('monster') then return_monster( card ); elseif _cardType:match('spell') then return _spell( card ); elseif _cardType:match('trap') then return _trap( card ); elseif _cardType:match('counter') then return _counter(); else return _error( 'On «_type»; Non-standard card type!' ); end
end
return _error( 'Empty value!' );
end
local _page = _card:gsub( '#', '' );
--local track = _redirect( _card ) and _error
return _type( _card _page );
end
return CardType;
Bureaucrats, System administrator, Administrators
57,479
edits