Content deleted Content added
Plastikspork (talk | contribs) Nevermind, more complicated, need piece labels as well, so better with a data submodule for different games |
rename class "chess-board" to "chess-pieces", since the div contains only the pieces, and to avoid confusion with the new top-level "chessboard" class |
||
(28 intermediate revisions by 5 users not shown) | |||
Line 1:
local p = {}
local cfg, nrows, ncols
local function innerboard(args, size, rev)
pattern = cfg.pattern or '%w%w'
local
root:addClass('chess-pieces notheme')
:css('position', 'relative')
:wikitext(
for trow = 1,
local row = rev and trow or (
for tcol = 1,
local col = rev and (
local piece = args[
local img = cfg.image_square(piece:match(pattern), row, col, size )
root:tag('div')
:css('top', tostring(( trow - 1 ) * size) .. 'px')
:css('left', tostring(( tcol - 1 ) * size) .. 'px')
:wikitext(img)
end
Line 69 ⟶ 25:
end
return tostring(
end
function chessboard(args, size, rev, letters, numbers, header, footer, align, clear)
function letters_row( rev, num_lt, num_rt )
local letters = cfg.letters()
local
if num_lt then
end
for k = 1,
:css('height', '18px')
: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 =
if ( numbers_lt ) then width = width + 18 end
if ( numbers_rt ) then width = width + 18 end
Line 101 ⟶ 58:
:addClass('chessboard')
:addClass('thumb')
:addClass('noviewer')
:addClass(align)
if( header and header ~= '' ) then
root:tag('div')
:css('margin', '0 auto')
:css('max-width', (width + ncols) .. 'px')
:wikitext(header)
end
local
:addClass('thumbinner
:css('width', width .. 'px')
local
:attr('cellpadding', '0')
:attr('cellspacing', '0')
if ( letters_tp ) then
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
local tablerow =
if ( numbers_lt ) then
tablerow:tag('td')
:css('width', '18px')
:css('height',
:wikitext(rev and 1 or
end
local td = tablerow:tag('td')
:attr('colspan',
:attr('rowspan',
:wikitext(innerboard(args, size, rev))
Line 134 ⟶ 94:
tablerow:tag('td')
:css('width', '18px')
:css('height',
:wikitext(rev and 1 or
end
if ( numbers_lt or numbers_rt ) then
for trow = 2,
local idx = rev and trow or (
tablerow =
if ( numbers_lt ) then
tablerow:tag('td')
:css('height',
:wikitext(idx)
end
if ( numbers_rt ) then
tablerow:tag('td')
:css('height',
:wikitext(idx)
end
Line 154 ⟶ 114:
end
if ( letters_bt ) then
:wikitext(letters_row( rev, numbers_lt, numbers_rt ))
end
if
:addClass('thumbcaption')
:wikitext(footer)
end
return tostring(root) ..
mw.getCurrentFrame():extensionTag( 'templatestyles', '', { src = 'Module:Chessboard/styles.css' } )
end
Line 211 ⟶ 171:
local args = frame.args
local pargs = frame:getParent().args
local style = args.style or pargs.style or 'Chess'
cfg = require('Module:Chessboard/' .. style)
nrows, ncols = cfg.dims()
local size = args.size or pargs.size or '26'
local reverse = ( args.reverse or pargs.reverse or '' ):lower() == "true"
Line 216 ⟶ 180:
local numbers = ( args.numbers or pargs.numbers or 'both' ):lower()
local header = args[2] or pargs[2] or ''
local footer = args[
local align = ( args[1] or pargs[1] or 'tright' ):lower()
local clear = args.clear or pargs.clear or ( align:match('tright') and 'right' ) or 'none'
local fen = args.fen or pargs.fen
local pgn = args.pgn or pargs.pgn
size = mw.ustring.match( size, '[%d]+' ) or '26' -- remove px from size
if (pgn) then
local pgnModule = require('Module:Pgn')
metadata, moves = pgnModule.main(pgn)
fen = moves[#moves]
end
if (fen) then
align = args.align or pargs.align or 'tright'
Line 230 ⟶ 197:
header = args.header or pargs.header or ''
footer = args.footer or pargs.footer or ''
return
end
if args[3] then
return
else
return
end
end
|