local shogiobject =
------------------------- internal functions -----------------------
-- returns a japanese character for a roman letter abbreviation-- called by the shogiboard functionlocal function piecesymbol(abbreviation) -- the abbreviation argument is a string of 1-3 letters that stand for the English names of the shogi pieces -- the abbreviation is extracted out of a longer string by the processString function -- letter to character mapping (hash table) local piecenames = -- spit out the character corresponding to abbreviation -- if the abbreviation string is empty, then spit out nobreak space (for html tables) piece = piecenames[abbreviation] or ' ' return string.format(piece)end
-- function separates out the piece, the side, and the boldness info present in the string argument-- it returns an array with these three values plus the color (for promoted pieces)-- this info is passed to the makeTD functionfunction processString(ss) -- strip whitespace ss = mw.text.trim(ss) -- get the last character of the string local lastchar = mw.ustring.sub(ss, -1) -- chop off last character of string local restofstring = mw.ustring.sub(ss, 1, -2)
-- default is normal font -- but if the string ends with 'l' for 'last move', -- then the font should be bold and we need to get a new string with the this 'l' chopped off (with a new last character) local boldness = 'normal' if lastchar:match('l') then boldness = 'bold' lastchar = mw.ustring.sub(restofstring, -1) restofstring = mw.ustring.sub(restofstring, 1, -2) end -- the side is either 'g' for 'gote' or 's' for 'sente' -- it's the last character in the string (and if the string ended) local side = lastchar -- the leftover string is the shogi piece abbreviation local pieceabbr = restofstring -- default is black font -- if the piece is promoted (one the abbreviations below), then the piece should be red local color = 'black' if pieceabbr:match('t') or pieceabbr:match('pl') or pieceabbr:match('pn') or pieceabbr:match('ps') or pieceabbr:match('h') or pieceabbr:match('d') then color = 'red' end -- this is an exceptional bit: -- gote's king is usually 王 instead of 玉 by convention, -- but it's convenient to use the 'k' code for both sente and gote and let the default character be side-dependent if pieceabbr:match('k') and side:match('g') then pieceabbr = 'ou' end if pieceabbr:match('k') and side:match('s') then pieceabbr = 'gyoku' end -- similar to above exception, reverse default if pieceabbr:match('ak') and side:match('s') then pieceabbr = 'ou' end if pieceabbr:match('ak') and side:match('g') then pieceabbr = 'gyoku' end -- convert abbreviation to Japanese character local piecechar = piecesymbol(pieceabbr) if ss:match('yy') or ss:match('gr') or ss:match('rat') or ss:match('lat') or ss:match('uat') or ss:match('dat') or ss:match('lra') or ss:match('las') or ss:match('ras') or ss:match('uda') or ss:match('das') or ss:match('uas') or ss:match('da') or ss:match('dau') or ss:match('dad') or ss:match('daus') or ss:match('dads') or ss:match('daa') or ss:match('daad') or ss:match('daau') or ss:match('daaus') or ss:match('daads') or ss:match('kar') or ss:match('kal') or ss:match('kadr') or ss:match('kadl') or ss:match('rah') or ss:match('lah') or ss:match('dah') or ss:match('uah') or ss:match('durh') or ss:match('dulh') or ss:match('ddrh') or ss:match('ddlh') or ss:match('ddl') or ss:match('ddr') or ss:match('dul') or ss:match('dur') then piecechar = '' side = 'arrow' color = 'arrow' boldness = 'arrow' end local result = return resultend
-- function makes a
-- for bold pieces if bold:match('bold') then td:css('font-weight', 'bolder') -- traditionally bold type is gothic (sans serif) in Japanese typesetting of shogi diagrams within Japanese shogi books td:css('font-family', ' HiraginoSans-W5, sans-serif') end -- for arrow svgs if side:match('arrow') then td:css('padding', '0') td:css('width', '20px') td:css('height', '20px') td:css('font-size', '1px') td:css('line-height', '0') td:wikitext(piecechar) end return tostring(root)end
-- function makes the shogi diagram-- this is basically a
enclosing a .css
wrapper with a