Content deleted Content added
ooopsie |
nitpicking |
||
Line 3:
local colornames = { l = 'White', d = 'Black' }
function piecediv( piece, row, file, res )
▲ function rowchar() return 8 - row end
▲ function filechar() return ( "abcdefgh" ):sub( file + 1, file + 1 ) end
▲ function coord( ind ) return ( reverse and ( 7 - ind ) * size ) or ind * size end
local color = piece:match( '%u' ) and 'l' or 'd'
piece = piece:lower()
local alt = string.format("%s%s %s %s", filechar( file ), rowchar( row ), colornames[color], piecenames[piece] or piece)
local img = string.format('[[File:Chess %s%st45.svg|%dx%dpx|alt=%s|%s]]', piece, color, size, size, alt, alt)
table.insert( res, string.format('<div style="position:absolute;z-index:3;top:%dpx;left:%dpx;">%s</div>', coord( row ), coord( file ), img) )
end
function oneRow( s, row, res )
local file =
for piece in s:gmatch( "%w" ) do -- if a digit, increment "file" by the digit. else, add the piece _and_ increment file by 1
file = file + ( piece:match("%d") or piecediv( piece, row, file, res ) or 1 )
end
end
local result = {}
table.insert(result, string.format([=[
<div class="chess-fen" style="position:relative;">
[[File:Chessboard480.png|%dx%dpx|link=]]
]=],
local row = 0
for srow in string.gmatch("/" .. fen, "/%w+") do
oneRow(srow, row, result)▼
row = row + 1
▲ oneRow(srow, row, result)
end
table.insert(result, '</div>')
|