Content deleted Content added
Plastikspork (talk | contribs) Test Tag: Reverted |
Plastikspork (talk | contribs) Nevermind, more complicated, need piece labels as well, so better with a data submodule for different games |
||
Line 1:
local p = {}
local cfg = mw.loadData('Module:Chessboard/configuration')
local function image_square( pc, row, col, size )
local piece = mw.ustring.gsub( pc, '^.*(%w)(%w).*$', '%1' ) or ''
local color = mw.ustring.gsub( pc, '^.*(%w)(%w).*$', '%2' ) or ''
local
local
local color_name = cfg.color_names[color]
local piece_name = cfg.piece_names[piece]
local symbol_name = cfg.symbol_names[piece .. color]
local alt = ''
if color_name and piece_name then
alt = message(
cfg.alt_with_color_and_piece,
square,
color_name,
piece_name
):plain()
elseif symbol_name then
alt = message(
cfg.alt_with_symbol,
square,
symbol_name
):plain()
else
alt = message(
cfg.alt_otherwise,
square,
piece,
color
):plain()
end
return string.format(
'[[File: piece, color, size, size, alt, alt )
end
local function innerboard(args, size, rev
local
local board_size = 8 * size
local size_px = size .. 'px'
board:addClass('chessboard-board')
:wikitext(string.format(
'[[File:Chessboard480.svg|%dx%dpx|link=|alt=Empty chess board|class=notpageimage]]',
board_size, board_size
))
for trow = 1,8 do
Line 82 ⟶ 56:
local col = rev and ( 9 - tcol ) or tcol
local piece = args[8 * ( 8 - row ) + col + 2] or ''
if square then
local img = image_square(square, row, col, size )
:css('top', tostring(( trow - 1 ) * size) .. 'px')
:css('left', tostring(( tcol - 1 ) * size) .. 'px')
:css('width',
:css('height',
:wikitext(img)
end
Line 96 ⟶ 69:
end
return tostring(
end
function chessboard(args, size, rev, letters, numbers, header, footer, align, clear
function letters_row( rev, num_lt, num_rt )
local
if num_lt then
end
for k = 1,8 do
:css('width', size .. 'px')
:wikitext(rev and
end
if num_rt then
end
return tostring(
end
local letters_tp = letters:match(
local letters_bt = letters:match(
local numbers_lt = numbers:match(
local numbers_rt = numbers:match(
local width = 8 * size + 2
if ( numbers_lt ) then width = width + 18 end
Line 134 ⟶ 99:
local root = mw.html.create('div')
:addClass('chessboard')
:addClass('thumb')
:addClass(align)
if
root:tag('div')
:addClass('chessboard-header')
:css('max-width', (width + 8) .. 'px')
:wikitext(header)
end
local
:addClass('thumbinner chessboard-board-wrapper')
:css('width', width .. 'px')
local
:addClass('chessboard-board-and-notation')
if ( letters_tp ) then
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
local tablerow =
local size_px = size .. 'px'
if ( numbers_lt ) then
tablerow:tag('td')
:css('width', '18px')
:css('height',
:wikitext(rev and 1 or 8)
end
Line 170 ⟶ 129:
:attr('colspan', 8)
:attr('rowspan', 8)
:wikitext(innerboard(args, size, rev))
if ( numbers_rt ) then
tablerow:tag('td')
:css('width', '18px')
:css('height',
:wikitext(rev and 1 or 8)
end
Line 186 ⟶ 140:
for trow = 2, 8 do
local idx = rev and trow or ( 9 - trow )
tablerow =
if ( numbers_lt ) then
tablerow:tag('td')
:css('
:wikitext(idx)
end
if ( numbers_rt ) then
tablerow:tag('td')
:css('
:wikitext(idx)
end
Line 207 ⟶ 154:
end
if ( letters_bt ) then
:
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
if (footer and footer ~= '') then
:addClass('thumbcaption')
:wikitext(footer)
Line 273 ⟶ 220:
local clear = args.clear or pargs.clear or ( align:match('tright') and 'right' ) or 'none'
local fen = args.fen or pargs.fen
size = mw.ustring.match( size, '[%d]+' ) or '26' -- remove px from size
local templatestyles = frame:extensionTag {
name = 'templatestyles', args = { src = 'Module:Chessboard/styles.css' }
}
if (fen) then
align = args.align or pargs.align or 'tright'
Line 285 ⟶ 230:
header = args.header or pargs.header or ''
footer = args.footer or pargs.footer or ''
return templatestyles .. chessboard( convertFenToArgs( fen ), size, reverse, letters, numbers, header, footer, align, clear
end
if args[3] then
return templatestyles .. chessboard(args, size, reverse, letters, numbers, header, footer, align, clear
else
return templatestyles .. chessboard(pargs, size, reverse, letters, numbers, header, footer, align, clear
end
end
Line 306 ⟶ 251:
res = mw.ustring.gsub( res,'\| \|', '| |' )
res = mw.ustring.gsub( res,'\| \|', '| |' )
end
|