Difference between pages "Module:Card table sets" and "Module:Card table sets/sandbox"
(Difference between pages)
(Fix for cases where it makes sense to show the dab text on set names (such as reprint sets of Legendary Collection: 25th Anniversary Edition).) |
(Distinguish th elements using CSS classes.) |
||
Line 12: | Line 12: | ||
local Reporter = require( 'Module:Reporter' ) | local Reporter = require( 'Module:Reporter' ) | ||
local StringBuffer = require( 'Module:StringBuffer' ) | local StringBuffer = require( 'Module:StringBuffer' ) | ||
− | |||
− | |||
− | |||
local LANGUAGE_ENGLISH = DATA.getLanguage( 'English' ) | local LANGUAGE_ENGLISH = DATA.getLanguage( 'English' ) | ||
Line 22: | Line 19: | ||
local reporter; | local reporter; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
local function formatCardNumber( cardNumber ) | local function formatCardNumber( cardNumber ) | ||
Line 34: | Line 26: | ||
end | end | ||
− | local function | + | local function validateRarities( rarities, lineno ) |
− | local | + | local validated = {} |
− | |||
− | |||
local position = 0 | local position = 0 | ||
− | |||
− | |||
for _, r in ipairs( rarities ) do | for _, r in ipairs( rarities ) do | ||
− | |||
− | |||
if UTIL.trim( r ) then | if UTIL.trim( r ) then | ||
− | + | position = position + 1 | |
local rarity = DATA.getRarity( r ) | local rarity = DATA.getRarity( r ) | ||
if rarity then | if rarity then | ||
− | + | table.insert( validated, rarity.full ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
else | else | ||
− | local message = ( 'No such rarity for `%s`, at non-empty input line %d, at non-empty position %d.' ) | + | local message = ('No such rarity for `%s`, at non-empty input line %d, at non-empty position %d.') |
− | :format( r, lineno, | + | :format( r, lineno, position ) |
− | + | reporter:addError( message ) | |
− | |||
− | reporter | ||
− | |||
− | |||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
end | end | ||
− | return | + | return validated |
end | end | ||
− | local function | + | local function printRarities( rarities ) |
− | + | local linked = {} | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | for _, rarity in ipairs( rarities ) do | |
− | + | table.insert( linked, UTIL.link( rarity ) ) | |
− | + | end | |
− | |||
− | |||
− | |||
− | |||
− | return | + | return table.concat( linked, '<br />' ) |
end | end | ||
− | local function | + | local function setSMWProps( cardNumber, setName, rarities, regionFull ) |
− | + | if not mw.smw then | |
− | ' | + | reporter:addError( 'SMW is not available!' ) |
− | |||
− | |||
− | + | return | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | return | ||
end | end | ||
− | local | + | local setInfoProp = ('--- %s --- %s --- %s --- %s ---') |
+ | :format( | ||
+ | cardNumber, | ||
+ | setName, | ||
+ | table.concat( rarities, ',' ), | ||
+ | regionFull | ||
+ | ) | ||
− | local | + | local jsonRarities = {} |
− | + | for _, rarity in ipairs( rarities ) do | |
− | + | table.insert( jsonRarities, '"' .. rarity .. '"' ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | local setInfoJSONProp = ('{ "number": "%s", "name": "%s", "rarity": [%s], "region": "%s" }') | |
− | + | :format( | |
− | + | cardNumber, | |
− | + | setName, | |
− | + | table.concat( jsonRarities, ',' ), | |
− | + | regionFull | |
− | |||
− | |||
) | ) | ||
− | |||
− | + | local setRes = mw.smw.set{ | |
− | + | ['Set information'] = setInfoProp, | |
+ | ['Set information (JSON)'] = setInfoJSONProp, | ||
+ | } | ||
− | + | if not setRes then | |
− | + | reporter:addError( "Failed to set SMW properties for set information!" ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | |||
− | |||
end | end | ||
Line 275: | Line 134: | ||
end | end | ||
− | + | local function createDataRow( region, language, line, lineno ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | local function createDataRow( | ||
local parts = mwText.split( line, '%s*;%s*' ) | local parts = mwText.split( line, '%s*;%s*' ) | ||
Line 298: | Line 140: | ||
local setName = UTIL.trim( parts[ 2 ] ) | local setName = UTIL.trim( parts[ 2 ] ) | ||
local rarities = UTIL.trim( parts[ 3 ] ) | local rarities = UTIL.trim( parts[ 3 ] ) | ||
− | and | + | and validateRarities( |
mwText.split( parts[ 3 ], '%s*,%s*' ), | mwText.split( parts[ 3 ], '%s*,%s*' ), | ||
lineno | lineno | ||
) | ) | ||
+ | or {} | ||
if not setName then | if not setName then | ||
− | local message = ( 'No set name | + | local message = ('No set name given at non-empty input line %d.') |
:format( lineno ) | :format( lineno ) | ||
− | + | reporter:addWarning( message ) | |
− | |||
− | reporter | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local tr = mwHtmlCreate( 'tr' ) | local tr = mwHtmlCreate( 'tr' ) | ||
− | :node( createCell( 'release', | + | :node( createCell( 'release', setName and DATA.getReleaseDate( setName, region ) ) ) |
:node( createCell( 'number', cardNumber and formatCardNumber( cardNumber ) ) ) | :node( createCell( 'number', cardNumber and formatCardNumber( cardNumber ) ) ) | ||
− | :node( createCell( 'set', | + | :node( createCell( 'set', setName and UTIL.italicLink( setName ) ) ) |
if language.full ~= LANGUAGE_ENGLISH.full then | if language.full ~= LANGUAGE_ENGLISH.full then | ||
Line 347: | Line 162: | ||
createCell( | createCell( | ||
'set-localized', | 'set-localized', | ||
− | + | DATA.getName( setName, language ) | |
) | ) | ||
) | ) | ||
end | end | ||
− | tr:node( createCell( 'rarity', rarities | + | tr:node( createCell( 'rarity', printRarities( rarities ) ) ) |
+ | |||
+ | setSMWProps( cardNumber or '', setName or '', rarities, region.full ) | ||
return tostring( tr ) | return tostring( tr ) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | local function main( | + | local function main( regionInput, setsInput ) |
reporter = Reporter( 'Card table sets' ) | reporter = Reporter( 'Card table sets' ) | ||
Line 370: | Line 181: | ||
local language = DATA.getLanguage( regionInput ) | local language = DATA.getLanguage( regionInput ) | ||
− | |||
− | |||
local setsTable = mwHtmlCreate( 'table' ) | local setsTable = mwHtmlCreate( 'table' ) | ||
− | |||
:addClass( 'wikitable' ) | :addClass( 'wikitable' ) | ||
:addClass( 'sortable' ) | :addClass( 'sortable' ) | ||
Line 388: | Line 196: | ||
lineno = lineno + 1 | lineno = lineno + 1 | ||
− | setsTable:node( createDataRow( | + | setsTable:node( createDataRow( region, language, line, lineno ) ) |
end | end | ||
− | |||
− | |||
− | |||
− | |||
end | end | ||
else | else | ||
− | local message = 'No input | + | local message = 'No input given for the sets.' |
− | local category = 'transclusions with no input (((1)))' | + | local category = '((Card table sets)) transclusions with no input (((1)))' |
reporter | reporter | ||
Line 407: | Line 211: | ||
return StringBuffer() | return StringBuffer() | ||
:add( reporter:dump() ) | :add( reporter:dump() ) | ||
− | |||
:add( tostring( setsTable ) ) | :add( tostring( setsTable ) ) | ||
:toString() | :toString() | ||
Line 416: | Line 219: | ||
local arguments = frame:getParent().args | local arguments = frame:getParent().args | ||
− | return main( | + | return main( arguments[ 'region' ], arguments[ 1 ] ) |
end | end | ||
}, { | }, { | ||
− | __call = function( t, | + | __call = function( t, ... ) |
− | + | return main( ... ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | return main( | ||
end, | end, | ||
} ) | } ) | ||
-- </pre> | -- </pre> |