模块:TowerTable/sandbox2
外观
此模块的文档可以在模块:TowerTable/sandbox2/doc创建
local p = {}
local COLORS = {
g = '#FFD200', c = '#BB4AFF', ['2'] = '#88FD57', ['3'] = '#57AAFD', ['4'] = '#B757FD',
['5'] = '#FDBF57', ['6'] = '#FD5A57', ['+'] = '#7BAD63', ['-'] = '#C36D61', ['+-'] = '#CCB543',
['清晨'] = '#FFD053', ['黄昏'] = '#FF8575', ['夜晚'] = '#8975FF',
b1 = '#FFFFFF', b2 = '#B2FF6B', b3 = '#58A7FF', b4 = '#C764EE', b5 = '#E99D4C', b6 = '#FF5D6C',
['所需金币'] = '#FFDC00', ['所需水晶'] = '#C44EFF',
['金币产量'] = '#FFC140', ['金币生产间隔'] = '#FFC140',
['水晶产量'] = '#CF80FD', ['水晶生产间隔'] = '#CF80FD',
['最大生命值'] = '#FF757E', ['攻击力'] = '#FFCA62', ['攻击间隔'] = '#5FFFF0', ['攻击范围'] = '#A1FF7A',
['连射次数'] = '#FF8DFC', ['子弹数量'] = '#F0FF62', ['穿透次数'] = '#C875FF', ['反弹次数'] = '#5869FF',
['生命恢复'] = '#89FF53', ['弹片数量'] = '#695BFF', ['爆炸半径'] = '#FFEF62', ['冰冻时间'] = '#88FFFD',
['燃烧时间'] = '#FF9662', ['治疗量'] = '#4AFF72',
DPS = '#FFFFFF', DPG = '#EEC200', DPC = '#AA39EE', GPS = '#FFFFFF', GPG = '#EEC200', GPC = '#AA39EE',
CPS = '#FFFFFF', CPG = '#EEC200', CPC = '#AA39EE', APS = '#FFFFFF', APG = '#EEC200', APC = '#AA39EE',
['天蓝产量'] = '#6BE4FF', ['天蓝生产间隔'] = '#6BE4FF', a = '#6BE4FF', ['所需天蓝'] = '#6BE4FF',
['静滞时间'] = '#B89EFF', ['潮湿时间'] = '#C7F0FF', ['过载次数'] = '#33D9FF', ['过载伤害'] = '#FF8C26',
['消耗过载层数'] = '#FF571A',
}
local cfg = {
wrapStyle = 'overflow-x:auto;width:100%;',
tableStyle = 'background-color:#212121;color: #EAECF0;white-space: nowrap;',
defaultClass = 'wikitable',
firstHeader = '防御塔等级与属性项(总和)',
errCategory = '[[Category:防御塔表格需要修复]]',
}
local function trim(s)
return mw.text.trim(s or '')
end
local function esc(s)
return (mw.text.encode(s or ''))
end
local function colored(value, colorKey)
local color = COLORS[colorKey] or '#000000'
return '<span style="color: ' .. color .. ';">' .. esc(value) .. '</span>'
end
local function labelHtml(call)
local body = call:gsub('^{{%s*[Tt]wtl%s*|', ''):gsub('%s*}}$', '')
local parts = {}
for a in mw.text.gsplit(body, '|') do
parts[#parts + 1] = trim(a)
end
local key = parts[1] or ''
local arg = parts[2] or ''
local function strong(inner)
return '<strong>' .. inner .. '</strong>'
end
local map = {
['基础面板'] = strong('基础面板'),
['基础升级'] = strong(colored('基础升级', '2')),
['进阶升级'] = strong(colored('进阶升级', '3')),
['q'] = strong(colored('分支Q:' .. arg, '4')),
['w'] = strong(colored('分支W:' .. arg, '4')),
['5q'] = strong(colored('分支Q:' .. arg, '5')),
['5w'] = strong(colored('分支W:' .. arg, '5')),
['4q5q'] = strong(colored('(分支Q:)', '4') .. colored('分支Q:' .. arg, '5')),
['4q5w'] = strong(colored('(分支Q:)', '4') .. colored('分支W:' .. arg, '5')),
['4w5q'] = strong(colored('(分支W:)', '4') .. colored('分支Q:' .. arg, '5')),
['4w5w'] = strong(colored('(分支W:)', '4') .. colored('分支W:' .. arg, '5')),
['1'] = strong(esc(arg)),
['2'] = strong(colored(arg, '2')),
['3'] = strong(colored(arg, '3')),
['4'] = strong(colored(arg, '4')),
['5'] = strong(colored(arg, '5')),
}
return map[key] or esc('未知的章节'), key, arg
end
function p.main(frame)
local args = frame.args
local parent = frame:getParent()
if parent and parent.args and (parent.args.header or parent.args.rows) then
args = parent.args
end
local class = args.class or cfg.defaultClass
local headerStr = trim(args.header)
local rowsStr = trim(args.rows)
local footerStr = trim(args.footer)
local issues = {}
if headerStr == '' then
return cfg.errCategory
end
local headers = {}
for h in mw.text.gsplit(headerStr, ',') do
headers[#headers + 1] = trim(h)
end
local ncol = #headers
if ncol == 0 then
return cfg.errCategory
end
local out = '<div style="' .. cfg.wrapStyle .. '">\n'
.. '<table class="' .. esc(class) .. '" style="' .. cfg.tableStyle .. '">\n'
.. '<tbody>\n<tr>\n<td><b>' .. esc(cfg.firstHeader) .. '</b></td>\n'
for _, h in ipairs(headers) do
out = out .. '<td>' .. colored(h, h) .. '</td>\n'
end
out = out .. '</tr>\n'
for row in mw.text.gsplit(rowsStr, ';') do
local rowTrim = trim(row)
if rowTrim ~= '' then
local cells = {}
for c in mw.text.gsplit(rowTrim, ',') do
cells[#cells + 1] = trim(c)
end
local firstCol = cells[1] or ''
local label, key, arg = nil, nil, nil
if firstCol:match('^{{%s*[Tt]wtl%s*|') then
label, key, arg = labelHtml(firstCol)
else
label = '<strong>' .. esc(firstCol) .. '</strong>'
end
if key == 'wno' or key == 'noup' then
out = out .. '<tr>\n<td>' .. label .. '</td>\n<td colspan="' .. esc(arg) .. '"></td>\n</tr>\n'
else
out = out .. '<tr>\n<td>' .. label .. '</td>\n'
for i = 2, #cells do
local header = headers[i - 1]
if header == nil then
issues[#issues + 1] = 'extra-cell'
break
end
out = out .. '<td>' .. colored(cells[i], header) .. '</td>\n'
end
if #cells - 1 < ncol then
issues[#issues + 1] = 'missing-cell'
for i = #cells + 1, ncol + 1 do
out = out .. '<td>' .. colored('', headers[i - 1]) .. '</td>\n'
end
end
out = out .. '</tr>\n'
end
end
end
if footerStr ~= '' then
out = out .. '<tr>\n<td colspan="' .. (ncol + 1) .. '">' .. esc(footerStr) .. '</td>\n</tr>\n'
end
out = out .. '</tbody>\n</table>\n</div>'
if #issues > 0 then
out = out .. cfg.errCategory
end
return out
end
return p