< Module:Card table | Extensions | Card game card(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
-- <pre>
--[=[Doc
@module ???
@description
@author [[User:Becasita]]
@contact [[User talk:Becasita]]
@todo add skill cards support here (ln_skill_activation and source_card)
]=]
local DATA = require( 'Module:Data' );
local UTIL = require( 'Module:Util' );
local mwTextSplit = mw.text.split;
local mwTextGsplit = mw.text.gsplit;
local Processor = {};
do
-- Sets:
local REGIONS = DATA( 'region' );
local function processSets( ct, region, parameter, argument )
local setData = {};
for line in mwTextGsplit( argument, '%s*\n%s*' ) do
if UTIL.trim( line ) then
local split = mwTextSplit( line, '%s*;%s*' );
setData.number = split[ 1 ];
setData.set = split[ 2 ];
setData.rarities = {};
for rarityPart in mwTextGsplit( split[ 3 ] ) do
local rarity = DATA.getRarity( rarityPart );
if rarity then
table.insert( setData.rarities );
else
local message = ('Cannot find a rarity on %s sets (%s) for `%s`!'):format(
region.full,
UTIL.formatParameter( parameter ),
rarityPart
);
ct:error( message );
end
end
end
end
-- TODO: check if should be added or not ??
ct:Contents():Sections():GetOrSet( 'Sets' )
:setContent( {
[table.concat{ region.index, 'Sets' }] = setData,
} )
;
end
for _, region in ipairs( REGIONS ) do
Processor[ table.concat{ region.index, '_sets' } ] = function( ct, parameter, argument )
return processSets( ct, region, parameter, argument );
end
end
end
DefaultProcessor[ 'skill_activation' ] = function( ct, parameter, argument )
ct:Contents():Rows():Set( 'Skill activation' )
:setContent( {
skillActivation = argument,
} )
;
end
DefaultProcessor[ 'source_card' ] = function( ct, parameter, argument )
ct:Contents():Rows():Set( 'Source card' )
:setContent( {
sourceCard = argument,
} )
;
end
do
-- keys:
-- Skill activation
local LANGUAGES = DATA( 'language' );
local ENGLISH_LANGUAGE = DATA.getLanguage( 'en' );
local function processNonEnglishData( ct, language, key, parameter, argument )
local data = ct:Contents():Sections():GetOrSet( 'Non-English data' );
local languageData = data:getContent()[ language.index ] or {};
languageData[ key ] = argument;
data:setContent( {
[language.index] = languageData,
} );
end
for _, language in ipairs( LANGUAGES ) do
if language.index ~= ENGLISH_LANGUAGE.index then
DefaultProcessor[ table.concat{ language.index, '_skill_activation' } ] = function( ct, parameter, argument )
return processNonEnglishData( ct, language, 'Skill activation', parameter, argument );
end
end
end
end
return Processor;
-- </pre>