Module:Chess from pgn: Difference between revisions

Content deleted Content added
Import from hewiki
 
.
Line 13:
function display_game(frame)
local gameargs = frame:getParent().args['pgn']
for k, v in frame.args do args[k] = v end
local game = args['pgn']
if not game then error('must have "pgn" parameter') end
local moves = pgn.pgn2fen(game)
local template = frame.args['template']
if not template then error('must have "template" parameter') end
local tmTable = {}
Line 27 ⟶ 30:
end
template = mw.text.unstripNoWiki( template )
for arg, val in pairs(frame.args) do -- collect boards of the form "12l = comment"
local index = moveToIndex(arg)
if index >= 0 then hydrate(index, val) end
end
 
for arg, val in pairs(frame.args) do -- collect boards of the form "| from1 = 7d | to1 = 8l | comments1 = { "comment", "comment" }
if arg:match('^from%d+$') then
local hunk = arg:match(('^from(%d+)$'))
toMove = frame.args['to' .. hunk]
if not toMove then error (string.format('parameter %s exists, but no parameter to%s', arg, hunk)) end
local fromIndex = moveToIndex(val)
Line 42 ⟶ 45:
if toIndex < 0 then error(string.format('malformed value for parameter to%s', hunk)) end
local comments = {}
local commentsVal = frame.args['comments' .. hunk] or ''
for comment in commentsVal:gmatch('{([^}]*)}') do table.insert(comments, comment) end
for index = fromIndex, toIndex do hydrate(index, table.remove(comments, 1) or '') end