Changes

Jump to: navigation, search

Module:Card gallery/File/CG

1,121 bytes added, 1 year ago
Restoring revision 5047626 by User:Becasita on 2022-08-22 19:06:13. "Use `Module:Card image name` directly."
local DATA = require( 'Module:Data' );
local UTIL = require( 'Module:Util' );
 
local StringBuffer = require( 'Module:StringBuffer' );
local getCardImageName = require( 'Module:Card image name' );
-------------
-- Constants:
-------------
local CARD_BACK PAGENAME = mw.title.getCurrentTitle().text; local CARD_BACK_TCG = 'Back-EN.png';local CARD_BACK_JP = 'Back-JP.png';local CARD_BACK_AE = 'Back-AE.png';local CARD_BACK_KR = 'Back-KR.png';local LANGUAGE_ENGLISH = DATA.getLanguage( 'EN' );local OFFICIAL_PROXY = DATA.getRelease( 'OP' );
---------------
-- a new instance is created (through `new()`), there's no
-- problem, because their useful lifetime is only inside
-- that function very function.
-- This way, having them here kinda as static variables,
-- supports encapsulation, since each instance of `File`
-- @description Boolean indicating if the file doesn't have an edition.
local function hasNoEdition( t )
local rg = ( t.region or t.parent:getRegion() ).index;  return rg == 'JP' or rg == 'JA' or rg == 'TC' or rg == 'SC' or ( rg == 'KR' and t.setAbbr:match( 'RD/' ) );end -- @description Decides what kind of card backing to present.local function getCardBack( rg ) return ( ( rg == 'JP' or rg == 'JA' or rg == 'TC') and CARD_BACK_JP or rg == 'AE' and CARD_BACK_AE or rg == 'KR' and CARD_BACK_KR or CARD_BACK_TCG );
end
end
if cardNumber and cardNumber:match( '^[/%w]-%-%w-$' ) then
-- Input like «TLM-EN012».
t.number = cardNumber:upper();
t.setAbbr = t.number:match( '^([/%w]-)%-%w-$' );
else
-- Input like «S1».
t.set = set;
t.setEn = UTILDATA.getName( set , LANGUAGE_ENGLISH ) or set;--TODO: either UTIL.trim or... check later t.setLn = UTILDATA.getName( set, t.parent:getLanguage().index );
end
table.insert( releases, releaseAsKey );
end
table.sort( releases );
t.releases = {};
-- @description Sets the `rarity` attribute.
local function initRarity( t )
local t.rarity = not t.flagsDATA.isOP and getRarity( _standard[ 3 ]);
if not t.file and not t.flags.isOP and not t.rarity == '' then
return t:error( 'rarity' );
end
 
t.rarity = DATA.getRarity( rarity ); -- TODO: error in case there's no rarity found.
end
t.edition = DATA.getEdition( edition );
if not t.file and not hasNoEdition( t ) and not t.edition then
return t:error( 'edition' );
end
-- @name initOptions
-- @description Sets any possible options (`region`, `extension` and `description`).
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:
local extension = _options[ 'extension' ];
-- Description:
t.description = _options[ 'description' ];
 
-- File:
t.file = _options[ 'file' ];
end
-- @description Initializes the attributes of the File instance.
local function init( t )
initOptions( t );
initNumber( t );
initSet( t );
initEdition( t );
initAlt( t );
initOptions( 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
self.flags.hasErrors = true;
self.parent:error(
('No %s given found for file input number %d!'):format( parameter, self.id )
)
function File:render()
if self.flags.hasErrors then
return ('%s | File #%d'):format( CARD_BACKgetCardBack( self.parent:getRegion().index ), self.id );
end
-- Build file:
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 :addor buildFile( self.flags.isOP and OFFICIAL_PROXY.abbr ) :add( self.alt ) :flushgsub( '-[/:]' ) :add( self.extension ) :flush( , '.' ) ;
-- Build caption:
local caption = UTIL.newStringBufferStringBuffer()
:add( self.number and UTIL.link( self.number ) )
:add(
UTIL.link(
self.set,
self.setEn --self.setEn:match( '%(2011%)' ) and self.setEn -- or self.setEn:match( '%(series%)' )
)
)
:flush( '<br />' )
;
return ('%s | %s'):format( file:toString(), caption:toString() );
end
Bots, mover
37,923
edits

Navigation menu