Modulo:Scacchiera: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
aggiornamento nomi
aggiornamento
Riga 1:
local p = {}
 
local function image_square( pc, row, col, size )
function chessboard(args, size, rev, letters, numbers, header, footer, align, clear, type)
local colornames = { l = 'del bianco', d = 'del nero' }
function image_square( pc, row, col, size )
local piecenames = {
local colornames = { l = 'del bianco', d = 'del nero' }
p = 'pedone',
local piecenames = {
p r = 'pedonetorre',
r n = 'torrecavallo',
n b = 'cavalloalfiere',
b q = 'alfieredonna',
q k = 'donnare',
a = 'arcivescovo',
k = 're',
c = 'cancelliere',
a = 'arcivescovo',
c z = 'cancellierecampione',
z w = 'campionemago',
w t = 'magogiullare',
h = 'pedone capovolto',
t = 'giullare',
h m = 'pedonetorre capovoltocapovolta',
s = 'barca',
m = 'torre capovolta',
s f = 'barcare capovolto',
f e = 're capovoltoelefante',
e g = 'elefantegrillo',
g N = 'grillonottambulo',
B = 'alfiere capovolto',
N = 'nottambulo',
B = 'alfiere capovolto',
}
local symnames = {
Riga 50 ⟶ 49:
x8 = 'otto',
x9 = 'nove',
}
}
local colchar = {'a','b','c','d','e','f','g','h'}
local color = mw.ustring.gsub( pc, '^.*(%w)(%w).*$', '%2' ) or ''
function colchar( col )
local piece = return mw.ustring.gsub( 'abcdefgh'pc, '^.*(%w):sub( col%w).*$', col'%1' ) or ''
local alt = colchar[col] .. row .. ' '
if colornames[color] and piecenames[piece] then
alt = alt .. colornames[color] .. ' ' .. piecenames[piece]
else
alt = alt .. ( symnames[piece .. color] or piece .. ' ' .. color )
end
 
return string.format( '[[File:Chess %s%st45.svg|%dx%dpx|alt=%s|%s]]', piece, color, size, size, alt, alt )
 
end
local function innerboard(args, size, rev)
local root = mw.html.create('div')
root:addClass('chess-board')
:css('position', 'relative')
:wikitext(string.format( '[[File:Chessboard480.svg|%dx%dpx|link=]]', 8 * size, 8 * size ))
for trow = 1,8 do
local row = rev and trow or ( 9 - trow )
for tcol = 1,8 do
local col = rev and ( 9 - tcol ) or tcol
local piece = args[8 * ( 8 - row ) + col + 2] or ''
if piece:match( '%w%w' ) then
local img = image_square(piece:match('%w%w'), row, col, size )
root:tag('div')
:css('position', 'absolute')
:css('z-index', '3')
:css('top', tostring(( trow - 1 ) * size) .. 'px')
:css('left', tostring(( tcol - 1 ) * size) .. 'px')
:css('width', size .. 'px')
:css('height', size .. 'px')
:wikitext(img)
end
end
local color = mw.ustring.gsub( pc, '^.*(%w)(%w).*$', '%2' ) or ''
local piece = mw.ustring.gsub( pc, '^.*(%w)(%w).*$', '%1' ) or ''
local alt = colchar( col ) .. row .. ' '
if colornames[color] and piecenames[piece] then
alt = alt .. piecenames[piece] .. ' ' .. colornames[color]
else
alt = alt .. ( symnames[piece .. color] or piece .. ' ' .. color )
end
return string.format( '[[File:Chess %s%st45.svg|%dx%dpx|alt=%s|%s]]', piece, color, size, size, alt, alt )
end
 
return tostring(root)
end
 
function chessboard(args, size, rev, letters, numbers, header, footer, align, clear)
function letters_row( rev, num_lt, num_rt )
local tdletters = {'<tda', style="padding:'b', 0;'c', vertical-align:'d', inherit;height:18px;width:'e', ..'f', size ..'g', 'px;">h'}
local legendsroot = mw.html.create('abcdefgh')
if num_lt then
local l = mw.text.split( rev and legends:reverse() or legends, '' )
root:tag('td')
return '<tr style="vertical-align:middle">\n'
.. :css( num_lt and '<td style="vertical-align: inherit; padding: 0"></td>' or, 'inherit' )
:css('padding', .. td'0')
end
.. table.concat( l, '</td>' .. td )
for k = 1,8 .. '</td>'do
root:tag('td')
.. ( num_rt and '<td style="vertical-align: inherit; padding: 0"></td>' or '' )
.. :css('padding', '\n</tr>0')
:css('vartical-align', 'inherit')
:css('height', '18px')
:css('width', size .. 'px')
:wikitext(rev and letters[9-k] or letters[k])
end
if num_rt then
root:tag('td')
:css('vertical-align', 'inherit')
:css('padding', '0')
end
return tostring(root)
end
local letters_tp = letters:match( 'both' ) or letters:match( 'top' )
local letters_bt = letters:match( 'both' ) or letters:match( 'bottom' )
Riga 88 ⟶ 126:
if ( numbers_rt ) then width = width + 18 end
 
local broot = mw.html.create('div')
local caption = :addClass('thumb')
:addClass(align)
:css('clear', clear)
local background = ''
:css('text-align', 'center')
if type == 'chaturanga' then
:wikitext(header)
background = 'Chaturanga489.png'
local div = root:tag('div')
else
:addClass('thumbinner')
background = 'Chessboard480.svg'
:css('width', width .. 'px')
local b = div:tag('table')
:attr('cellpadding', '0')
:attr('cellspacing', '0')
:css('background', 'white')
:css('font-size', '88%')
:css('border' , '1px #b0b0b0 solid')
:css('padding', '0')
:css('margin', 'auto')
 
if ( letters_tp ) then
b:tag('tr')
:css('vertical-align', 'middle')
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
local tablerow = b:tag('tr'):css('vertical-align','middle')
if ( numbers_lt ) then
if ( letters_tp ) then b = b .. letters_row( rev, numbers_lt, numbers_rt ) .. '\n' end
tablerow:tag('td')
b = b .. '<tr style="vertical-align:middle">'
:css('padding', '0')
if ( numbers_lt ) then b = b .. '<td style="padding: 0; vertical-align: inherit; width:18px;height:' .. size .. 'px">' .. (rev and 1 or 8) .. '</td>' end
b = b .. :css('<td colspan=8 rowspan=8 style="padding: 0; vertical-align:', 'inherit;"><div class="chess-board" style="position:relative;">')
:css('width', '18px')
b = b .. string.format( '[[File:%s|%dx%dpx|link=]]', background, 8 * size, 8 * size )
:css('height', size .. 'px')
for trow = 1,8 do
local row = :wikitext(rev and trow1 or (8) 9 - trow )
end
for tcol = 1,8 do
local coltd = rev and tablerow:tag( 9 - tcol 'td') or tcol
:attr('colspan', 8)
local piece = args[8 * ( 8 - row ) + col + 2] or ''
if piece :matchattr( '%w%wrowspan', 8) then
:css('padding', '0')
local img = image_square(piece:match('%w%w'), row, col, size )
:css('vertical-align', 'inherit')
b = b .. string.format(
:wikitext(innerboard(args, size, rev))
'<div style="position:absolute;z-index:3;top:%dpx;left:%dpx;width:' .. size .. 'px;height:' .. size .. 'px;">%s</div>\n',
( trow - 1 ) * size, ( tcol - 1 ) * size, img )
if ( numbers_rt ) then end
tablerow:tag('td')
end
:css('padding', '0')
:css('vertical-align', 'inherit')
:css('width', '18px')
:css('height', size .. 'px')
:wikitext(rev and 1 or 8)
end
b = b .. '</div></td>'
if ( numbers_rt ) then b = b .. '<td style="width:18px;height:' .. size ..'px;padding:0">' .. (rev and 1 or 8) .. '</td>' end
if ( numbers_lt or numbers_rt ) then
for trow = 2, 8 do
local rowidx = rev and trow or ( 9 - trow )
btablerow = b .. :tag('<tr style="vertical-align:middle">')
if :css( numbers_lt ) then b = b .. '<td style="padding: 0; vertical-align: inherit;height:' .. size .., 'px">middle' .. row .. '</td>' end)
if ( numbers_lt ) then
if ( numbers_rt ) then b = b .. '<td style="padding: 0; vertical-align: inherit;height:' .. size .. 'px">' .. row .. '</td>' end
b = b .. tablerow:tag('</tr>\ntd')
:css('padding', '0')
:css('vertical-align', 'inherit')
:css('height', size .. 'px')
:wikitext(idx)
end
if ( numbers_rt ) then
tablerow:tag('td')
:css('padding', '0')
:css('vertical-align', 'inherit')
:css('height', size .. 'px')
:wikitext(idx)
end
end
end
if ( letters_bt ) then b = b .. letters_row( rev, numbers_lt, numbers_rt ) .. '\n' end
b:tag('tr')
 
if footer :matchcss( '^%s*$vertical-align', 'middle')
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
then
else
caption = '<div class="thumbcaption">' .. footer .. '</div>\n'
end
 
if (footer and footer ~= '') then
return '<div class="' .. align .. '" style="clear:' .. clear .. '; width:'.. width .. 'px; text-align:center;">'
div:tag('div')
.. header .. '\n<div class="thumbinner" style="width:' .. width .. 'px;">\n'
:addClass('thumbcaption')
.. '<table cellpadding=0 cellspacing=0 style="background:white; font-size:88%; border:1px #b0b0b0 solid; padding:0; '
:wikitext(footer)
.. 'margin:auto;">\n' .. b .. '\n</table>\n' .. caption .. '</div></div>'
end
 
return tostring(root)
end
 
Riga 193 ⟶ 261:
local clear = args.clear or pargs.clear or ( align:match('tright') and 'right' ) or 'none'
local fen = args.fen or pargs.fen
local type = args.type or pargs.type or 'scacchi'
size = mw.ustring.match( size, '[%d]+' ) or '26' -- remove px from size
Riga 201 ⟶ 268:
header = args.header or pargs.header or ''
footer = args.footer or pargs.footer or ''
return chessboard( convertFenToArgs( fen ), size, reverse, letters, numbers, header, footer, align, clear, type )
end
if args[3] then
return chessboard(args, size, reverse, letters, numbers, header, footer, align, clear, type)
else
return chessboard(pargs, size, reverse, letters, numbers, header, footer, align, clear, type)
end
end
 
function p.fen2ascii(frame)
-- {{#invoke:ScacchieraChessboard|fen2ascii|fen=...}}
local b = convertFenToArgs( frame.args.fen )
local res = '|=\n'
Riga 227 ⟶ 294:
 
function p.ascii2fen( frame )
-- {{#invoke:ScacchieraChessboard|ascii2fen|kl| | |....}}
return convertArgsToFen( frame.args, frame.args.offset or 1 )
end