Modul:Schachbrett
Erscheinungsbild
Die Dokumentation für dieses Modul kann unter Modul:Schachbrett/Doku erstellt werden
local p = {}
p.f = function(frame)
local fen,size,reverse
function coord(ind)
return (reverse and (7 - ind) * size) or ind * size
end
function colBool(bool)
return (bool and 'l') or 'd'
end
function piecepict(file,row,piece)
local squareColor = colBool( (file + row) % 2 == 0 )
local pieceColor = colBool(piece == string.upper(piece))
return string.format('[[File:Chess %s%st45.svg|%dx%dpx|link=]]', string.lower(piece), pieceColor, size, size)
end
function oneRow(s, row)
local file = 0
local result = ''
for piece in string.gmatch(s, "%\w") do
if string.match(piece, "%\d") then
file = file + piece
else
result = result .. string.format('<div style="top:%dpx;left:%dpx;">%s</div>\n', coord(row), coord(file), piecepict(file,row,piece))
file = file + 1
end
end
return result
end
local row = 0;
fen = frame.args['fen']
size = frame.args['size'] or 30
reverse = string.lower(frame.args['reverse'] or '') == "true"
local result = string.format('<div class="chess-fen" style="min-width:%dpx;min-height:%dpx;">', size*8,size*8)
result = result .. string.format('<div style="z-index:0; top:0px; left:0px;">[[File:Chessboard480.png|%dx%dpx]]</div>', size * 8, size * 8)
for srow in string.gmatch("/" .. fen, "/%w+") do
result = result .. oneRow(srow, row)
row = row + 1
end
result = result .. '</div>'
return result
end
return p