Modulo:Scacchiera: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m Annullata la modifica 70153086 di Mess (discussione)
chaturanga
Riga 2:
 
local function image_square( pc, row, col, size )
local colornames = { l = 'del bianco', d = 'del nero' }
local piecenames = {
p = 'pedone',
r = 'torre',
n = 'cavallo',
b = 'alfiere',
q = 'donna',
k = 're',
a = 'arcivescovo',
c = 'cancelliere',
z = 'campione',
w = 'mago',
t = 'giullare',
h = 'pedone capovolto',
m = 'torre capovolta',
s = 'barca',
f = 're capovolto',
e = 'elefante',
g = 'grillo',
N = 'nottambulo',
B = 'alfiere capovolto',
}
local symnames = {
Riga 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 ''
local piece = mw.ustring.gsub( pc, '^.*(%w)(%w).*$', '%1' ) or ''
Riga 56:
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, background)
local root = mw.html.create('div')
local bg_filename = ''
root:addClass('chess-board')
if background == 'chaturanga' then
:css('position', 'relative')
bg_filename = 'Chaturanga489.png'
:wikitext(string.format( '[[File:Chessboard480.svg|%dx%dpx|link=]]', 8 * size, 8 * size ))
else
bg_filename = 'Chessboard480.svg'
end
 
local root = mw.html.create('div')
root:addClass('chess-board')
:css('position', 'relative')
:wikitext(string.format( '[[File:Chessboard480.svg%s|%dx%dpx|link=]]', bg_filename, 8 * size, 8 * size ))
for trow = 1,8 do
local row = rev and trow or ( 9 - trow )
Riga 79 ⟶ 87:
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
Riga 93 ⟶ 101:
end
 
function chessboard(args, size, rev, letters, numbers, header, footer, align, clear, background)
function letters_row( rev, num_lt, num_rt )
local letters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}
local root = mw.html.create('')
if num_lt then
root:tag('td')
:css('vertical-align', 'inherit')
:css('padding', '0')
end
for k = 1,8 do
root:tag('td')
:css('padding', '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)
Riga 127 ⟶ 135:
 
local root = mw.html.create('div')
:addClass('thumb')
:addClass(align)
:css('clear', clear)
:css('text-align', 'center')
:wikitext(header)
local div = root:tag('div')
:addClass('thumbinner')
: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
tablerow:tag('td')
:css('padding', '0')
:css('vertical-align', 'inherit')
:css('width', '18px')
:css('height', size .. 'px')
:wikitext(rev and 1 or 8)
end
local td = tablerow:tag('td')
:attr('colspan', 8)
:attr('rowspan', 8)
:css('padding', '0')
:css('vertical-align', 'inherit')
:wikitext(innerboard(args, size, rev, background))
if ( numbers_rt ) then
tablerow:tag('td')
:css('padding', '0')
:css('vertical-align', 'inherit')
:css('width', '18px')
:css('height', size .. 'px')
:wikitext(rev and 1 or 8)
end
if ( numbers_lt or numbers_rt ) then
Riga 177 ⟶ 185:
local idx = rev and trow or ( 9 - trow )
tablerow = b:tag('tr')
:css('vertical-align', 'middle')
if ( numbers_lt ) then
tablerow:tag('td')
: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
Riga 196 ⟶ 204:
if ( letters_bt ) then
b:tag('tr')
:css('vertical-align', 'middle')
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
 
if (footer and footer ~= '') then
div:tag('div')
:addClass('thumbcaption')
:wikitext(footer)
end
 
return tostring(root)
Riga 261 ⟶ 269:
local clear = args.clear or pargs.clear or ( align:match('tright') and 'right' ) or 'none'
local fen = args.fen or pargs.fen
local background = args.background or pargs.background or 'checks'
size = mw.ustring.match( size, '[%d]+' ) or '26' -- remove px from size
Riga 268 ⟶ 277:
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, background)
end
if args[3] then
return chessboard(args, size, reverse, letters, numbers, header, footer, align, clear, background)
else
return chessboard(pargs, size, reverse, letters, numbers, header, footer, align, clear, background)
end
end