モジュール:Xiangqi diagram plus

-- 模块:Xiangqi diagram的扩展版，支持更多功能
-- 目前还在测试中……
local p = {}
function p.board(frame)
	local args = require('Module:Arguments').getArgs(frame)
	----设置对齐方式
	local align = string.gsub(args1 or , '\n', )
	if align ==  then
		align = 'tright'
	end
	local header = string.gsub(args2 or , '\n', )
	local footer = string.gsub(args93 or , '\n', )
	----设置整张图片的尺寸
	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 rows = args.rows
	local startrow = args.startrow
	local top = 0
	local bheight = height
	local cols = args.cols
	local startcol = args.startcol
	local left = 0
	local bwidth = width
	local bsize = size
	----设置起始列和列数
	if cols == nil and startcol ~= nil then
		cols = 9 - startcol
	end
	if cols ~= nil then
		width = width * cols / 9
	end
	if cols ~= nil and startcol == nil then
		startcol = 1
	end
	if startcol ~= nil then
		left = bwidth / 9 * (startcol - 1)
	end
	----设置起始行及行数
	if rows == nil and startrow ~= nil then
		rows = 12 - startrow
	end
	if rows ~= nil then
		bheight = bheight / 12 * rows
	end
	if rows ~= nil and startrow == nil then
		startrow = 1
	end
	if startrow ~= nil then
		top = height / 12 * startrow
	end
	----元件大小設定
	local sizef1 = size / 15
	local sizef2 = size / 20
	local sizef3 = size / 5
	local margin = size / 2 - sizef3 / 2
	local sizeX = math.ceil(size / 2, 0)
	local marginX = size / 2 - sizeX / 2
	----输出棋盘图片
	local qp = 
	qp = qp .. 
	qp = qp ..  .. header .. 
	qp = qp .. 
	qp = qp .. 
	qp = qp ..  .. bwidth .. 'px'
	qp = qp .. 
	qp = qp .. 
	for i = 0, 9 do
		for j = 0, 8 do
			local qz = string.gsub(argsi * 9 + j + 3 or , '\n', )
			qz = string.gsub(qz, ' ', )
			qz = string.gsub(qz, '　', )
			qz = string.gsub(qz, '_', )
			qz = string.gsub(qz, '车', 'rd')
			qz = string.gsub(qz, '車', 'rd')
			qz = string.gsub(qz, '伡', 'rl')
			qz = string.gsub(qz, '俥', 'rl')
			qz = string.gsub(qz, '马', 'hd')
			qz = string.gsub(qz, '馬', 'hd')
			qz = string.gsub(qz, '㐷', 'hl')
			qz = string.gsub(qz, '傌', 'hl')
			qz = string.gsub(qz, '相', 'el')
			qz = string.gsub(qz, '象', 'ed')
			qz = string.gsub(qz, '仕', 'al')
			qz = string.gsub(qz, '士', 'ad')
			qz = string.gsub(qz, '炮', 'cl')
			qz = string.gsub(qz, '砲', 'cd')
			qz = string.gsub(qz, '兵', 'sl')
			qz = string.gsub(qz, '卒', 'sd')
			qz = string.gsub(qz, '帅', 'gl')
			qz = string.gsub(qz, '帥', 'gl')
			qz = string.gsub(qz, '将', 'gd')
			qz = string.gsub(qz, '將', 'gd')
			qz = string.gsub(qz, '包', 'cd')
			qz = string.gsub(qz, '暗', 'rs')
			local sx = ((i + 1) * size)
			local sy = (j * size)
			local bj
			----方框
			bj = string.find(qz, '%')
			if bj ~= null then
				qp = qp .. 
				qp = qp .. 
				qp = qp .. 
				qp = qp .. 
				qp = qp .. 
				qp = qp .. 
			end
			qz = string.gsub(qz, '%', )
			qz = string.gsub(qz, '%', )
			----標點
			bj = string.find(qz, '%.')
			if bj ~= null then
				qp = qp .. 
				qp = qp .. 
				qp = qp .. 
			end
			qz = string.gsub(qz, '%.', )
			----標記叉號
			bj = string.find(qz, 'x')
			if bj ~= null then
				qp = qp .. 
				qp = qp ..  .. sizeX .. 'px'
				qp = qp .. 
			end
			qz = string.gsub(qz, 'x', )
			if qz ~=  then
				qp = qp .. 
				qp = qp ..  .. size .. 'px'
				qp = qp .. 
			end
		end
	end
	----箭头
	local arrow = args.arrow
	if arrow ~= nil then
		qp = qp .. drawArrow(arrow, size)
	end
	local count = 2
	while args'arrow' .. count ~= nil do
		qp = qp .. drawArrow(args'arrow' .. count, size)
		count = count + 1
	end
	qp = qp ..  .. footer .. 
	return qp
end
function drawArrow(arrow, size)
	arrow = string.gsub(arrow, ' ', )
	local start = 1
	local t = {}
	local str = 
	while true do
		local pos = string.find(arrow, ',', start, true)
		if not pos then
			break
		end
		table.insert(t, string.sub(arrow, start, pos - 1))
		start = pos + string.len(',')
	end
	table.insert(t, string.sub(arrow, start))
	t4 = t4 * 1
	while t4 = 360 do
		t4 = t4 - 360
	end
	----箭頭的底盤 拿來旋轉方向使用
	str = str .. 
	----箭頭的直線部分
	str = str .. 
	----箭頭的頭部分
	str = str .. 
	str = str .. 
	return str
end
return p