モジュール:Xiangqi diagram
モジュールの解説[作成]
function format(s)
s = string.gsub(s or '', '\n', '')
return s
end
local qidata = {
rs = {'暗'},
gd = {'将', '將'},
ad = {'士'},
ed = {'象'},
rd = {'车', '車'},
hd = {'马', '馬'},
cd = {'砲', '包'},
sd = {'卒'},
gl = {'帅', '帥'},
al = {'仕'},
el = {'相'},
rl = {'伡', '俥'},
hl = {'㐷', '傌'},
cl = {'炮'},
sl = {'兵'}
}
local p = {}
function p.board(frame)
local args = require('Module:Arguments').getArgs(frame)
local align = format(args[1])
if align == '' then
align = 'tright'
end
local header = format(args[2])
local footer = format(args[93])
local size
local width
local height
if args.size ~= nil then
size = args.size
width = size * 9
height = size * 12
elseif args.width ~= nil then
width = args.width
size = width / 9
height = size * 12
elseif args.height ~= nil then
height = args.height
size = height / 12
width = size * 9
else
size = 25
width = 225
height = 300
end
local ss = ''
ss = ss .. '<div class="' .. align .. '" style="clear:right;">'
ss = ss .. '<div style="width:' .. width .. 'px;border:1px solid #a2a9b1;padding:5px;background-color:#f8f9fa;">'
if header ~= '' then
ss = ss .. '<div style="text-align:center;margin-bottom:3px;width:' .. width .. 'px;">' .. header .. '</div>'
end
ss = ss .. '<div style="position:relative;overflow:hidden;width:' .. width .. 'px;height:' .. height .. 'px;">'
ss = ss .. '<div style="position:absolute;">[[File:Xiangqi_board.svg|' .. width .. 'px]]</div>'
for i = 0, 9 do
for j = 0, 8 do
local s = format(args[i * 9 + j + 3])
s = string.gsub(s, ' ', '')
s = string.gsub(s, ' ', '')
s = string.gsub(s, '_', '')
local sx = (j * size)
local sy = ((i + 1) * size)
-- 判斷棋名
local qi = ''
for key, val in pairs(qidata) do
if s:find(key) ~= nil then
qi = key
end
for k, v in ipairs(val) do
if s:find(v) ~= nil then
qi = key
end
end
end
if qi ~= '' then
ss = ss .. '<div style="position:absolute;left:' .. sx .. 'px;top:' .. sy .. 'px;">'
ss = ss .. '[[File:Xiangqi_' .. qi .. '1.svg|' .. size .. 'px]]</div>'
end
end
end
ss = ss .. '</div>'
if footer ~= '' then
ss = ss .. '<div style="text-align:left;margin-top:3px;width:' .. width .. 'px;">' .. footer .. '</div>'
end
ss = ss .. '</div></div>'
return ss
end
return p