Editing Module:Card gallery/File/CG

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page is not enabled for semantic in-text annotations due to namespace restrictions. Details about how to enable the namespace can be found on the configuration help page.

Latest revision Your text
Line 14: Line 14:
 
local DATA = require( 'Module:Data' );
 
local DATA = require( 'Module:Data' );
 
local UTIL = require( 'Module:Util' );
 
local UTIL = require( 'Module:Util' );
 
local StringBuffer = require( 'Module:StringBuffer' );
 
local getCardImageName = require( 'Module:Card image name' );
 
  
 
-------------
 
-------------
 
-- Constants:
 
-- Constants:
 
-------------
 
-------------
local PAGENAME = mw.title.getCurrentTitle().text;
+
local CARD_BACK_TCG = 'Back-EN.png';
 
+
local CARD_BACK_JP   = 'Back-JP.png';
local CARD_BACK_TCG    = 'Back-EN.png';
+
local CARD_BACK_AE   = 'Back-AE.png';
local CARD_BACK_JP     = 'Back-JP.png';
+
local CARD_BACK_KR   = 'Back-KR.png';
local CARD_BACK_AE     = 'Back-AE.png';
+
local OFFICIAL_PROXY = DATA.getRelease( 'OP' );
local CARD_BACK_KR     = 'Back-KR.png';
 
local LANGUAGE_ENGLISH = DATA.getLanguage( 'EN' );
 
local OFFICIAL_PROXY   = DATA.getRelease( 'OP' );
 
  
 
---------------
 
---------------
Line 48: Line 42:
 
-- @description Boolean indicating if the file doesn't have an edition.
 
-- @description Boolean indicating if the file doesn't have an edition.
 
local function hasNoEdition( t )
 
local function hasNoEdition( t )
local rg = ( t.region or t.parent:getRegion() ).index;
+
local rg = t.parent:getRegion().index;
 
+
return rg == 'JP' or rg == 'JA' or rg == 'TC';
return rg == 'JP'
 
or rg == 'JA'
 
or rg == 'TC'
 
or rg == 'SC'
 
or (
 
rg == 'KR'
 
and t.setAbbr:match( 'RD/' )
 
);
 
 
end
 
end
  
Line 82: Line 68:
 
end
 
end
  
if cardNumber and cardNumber:match( '^[/%w]-%-%w-$' ) then
+
if cardNumber and cardNumber:match( '^%w-%-%w-$' ) then
 
-- Input like «TLM-EN012».
 
-- Input like «TLM-EN012».
 
t.number  = cardNumber:upper();
 
t.number  = cardNumber:upper();
t.setAbbr = t.number:match( '^([/%w]-)%-%w-$' );
+
t.setAbbr = t.number:match( '^(%w-)%-%w-$' );
 
else
 
else
 
-- Input like «S1».
 
-- Input like «S1».
Line 103: Line 89:
  
 
t.set  = set;
 
t.set  = set;
t.setEn = DATA.getName( set, LANGUAGE_ENGLISH ) or set; --TODO: either UTIL.trim or... check later
+
t.setEn = UTIL.getName( set ) or set; --TODO: either UTIL.trim or... check later
t.setLn = DATA.getName( set, t.parent:getLanguage() );
+
t.setLn = UTIL.getName( set, t.parent:getLanguage().index );
 
end
 
end
  
Line 126: Line 112:
 
table.insert( releases, releaseAsKey );
 
table.insert( releases, releaseAsKey );
 
end
 
end
table.sort( releases );
+
table.sort( releases );  
  
 
t.releases = {};
 
t.releases = {};
Line 143: Line 129:
 
-- @description Sets the `rarity` attribute.
 
-- @description Sets the `rarity` attribute.
 
local function initRarity( t )
 
local function initRarity( t )
t.rarity = DATA.getRarity( _standard[ 3 ] );
+
local rarity = not t.flags.isOP and _standard[ 3 ];
  
if not t.file and not t.flags.isOP and not t.rarity then
+
if not t.flags.isOP and rarity == '' then
 
return t:error( 'rarity' );
 
return t:error( 'rarity' );
 
end
 
end
 +
 +
t.rarity = DATA.getRarity( rarity ); -- TODO: error in case there's no rarity found.
 
end
 
end
  
Line 157: Line 145:
 
t.edition = DATA.getEdition( edition );
 
t.edition = DATA.getEdition( edition );
  
if not t.file and not hasNoEdition( t ) and not t.edition then
+
if not hasNoEdition( t ) and not t.edition then
 
return t:error( 'edition' );
 
return t:error( 'edition' );
 
end
 
end
Line 173: Line 161:
  
 
-- @name initOptions
 
-- @name initOptions
-- @description Sets any possible options (`region`, `extension` and `description`).
+
-- @description Sets any possible options (`extension` and `description`).
 
local function initOptions( t )
 
local function initOptions( t )
-- Region:
 
t.region = DATA.getRegion( _options[ 'region' ] );
 
 
if _options[ 'region' ] and not t.region then
 
t.parent:error(
 
('Invalid custom region value %s given for file input number %d!'):format(
 
_options[ 'region' ],
 
t.id
 
)
 
);
 
end
 
 
 
-- Extension:
 
-- Extension:
 
local extension = _options[ 'extension' ];
 
local extension = _options[ 'extension' ];
Line 193: Line 169:
 
-- Description:
 
-- Description:
 
t.description = _options[ 'description' ];
 
t.description = _options[ 'description' ];
 
-- File:
 
t.file = _options[ 'file' ];
 
 
end
 
end
  
Line 201: Line 174:
 
-- @description Initializes the attributes of the File instance.
 
-- @description Initializes the attributes of the File instance.
 
local function init( t )
 
local function init( t )
initOptions( t );
 
 
initNumber( t );
 
initNumber( t );
 
initSet( t );
 
initSet( t );
Line 208: Line 180:
 
initEdition( t );
 
initEdition( t );
 
initAlt( t );
 
initAlt( t );
 +
initOptions( t );
 
return t;
 
return t;
end
 
 
local function buildFile( t )
 
local file = StringBuffer()
 
:add( getCardImageName( PAGENAME ) )
 
:add( t.setAbbr )
 
:add( ( t.region or t.parent:getRegion() ).index )
 
:add( t.rarity and t.rarity.abbr )
 
:add( t.edition and t.edition.abbr )
 
 
for _, release in ipairs( t.releases ) do
 
file:add( release.abbr )
 
end
 
 
file
 
:add( t.flags.isOP and OFFICIAL_PROXY.abbr )
 
:add( t.alt )
 
:flush( '-' )
 
:add( t.extension )
 
:flush( '.' )
 
 
return file:toString()
 
 
end
 
end
  
Line 280: Line 231:
 
self.flags.hasErrors = true;
 
self.flags.hasErrors = true;
 
self.parent:error(
 
self.parent:error(
('No %s found for file input number %d!'):format( parameter, self.id )
+
('No %s given for file input number %d!'):format( parameter, self.id )
 
)
 
)
  
Line 294: Line 245:
  
 
-- Build file:
 
-- Build file:
local file = ( self.file or buildFile( self ) ):gsub( '[/:]' , '' )
+
local file = UTIL.newStringBuffer()
 +
:add( UTIL.getImgName() )
 +
:add( self.setAbbr )
 +
:add( self.parent:getRegion().index )
 +
:add( self.rarity and self.rarity.abbr )
 +
:add( self.edition and self.edition.abbr )
 +
;
 +
 
 +
for _, release in ipairs( self.releases ) do
 +
file:add( release.abbr );
 +
end
 +
 
 +
file
 +
:add( self.flags.isOP and OFFICIAL_PROXY.abbr )
 +
:add( self.alt )
 +
:flush( '-' )
 +
:add( self.extension )
 +
:flush( '.' )
 +
;
  
 
-- Build caption:
 
-- Build caption:
local caption = StringBuffer()
+
local caption = UTIL.newStringBuffer()
 
:add( self.number and UTIL.link( self.number ) )
 
:add( self.number and UTIL.link( self.number ) )
 
:add(
 
:add(
Line 324: Line 293:
 
:flush( '<br />' )
 
:flush( '<br />' )
 
;
 
;
 
+
return ('%s | %s'):format( file, caption:toString() );
+
return ('%s | %s'):format( file:toString(), caption:toString() );
 
end
 
end
  

Please note that all contributions to Yugipedia are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 International License (see Yugipedia:Licensing for more details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)
Preview page with this template
Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above.

View this template