- 致编者:请牢记我们的域名wiki.mcbe-dev.net!
- 致编者:欢迎加入本Wiki的官方交流QQ群或Discord服务器!
- 基岩版1.19.31现已发布!(了解更多)
- Inner Core现已支持Xbox模组联机!(了解更多)
- 如果您是第一次来到本Wiki,欢迎注册一个账户
- 点击顶部的“编辑”或“编辑源代码”按钮即可编辑当前页面
- 请知悉:在不登录时也可以编辑和新建页面,但是您当前的IP地址会记录在编辑历史中
Module:Command table
来自Minecraft基岩版开发Wiki
local p = {}
local function GetCount(args, key, value, argType)
local i = 0
if argType == 'cmd' then
if value == 'any' then
repeat
i = i + 1
key = key + 3
until args[key] == nil or
(args[key] ~= value and args[key] ~= '*' and args[key] ~= '~' and args[key] ~= '任意')
else
repeat
i = i + 1
key = key + 3
until args[key] == nil or (args[key] ~= value and args[key] ~= '*' and args[key] ~= '~')
end
elseif argType == 'tc-result' then
if value == 'succeed' then
repeat
i = i + 1
key = key + 3
until args[key] == nil or (args[key] ~= value and args[key] ~= 'yes' and args[key] ~= '成功')
elseif value == 'fail' then
repeat
i = i + 1
key = key + 3
until args[key] == nil or (args[key] ~= value and args[key] ~= 'no' and args[key] ~= '失败')
else
repeat
i = i + 1
key = key + 3
until args[key] == nil or args[key] ~= value
end
end
if i then
return i
end
return 1
end
local function GetTableChoice(str)
if str == 'N/A' then
return nil, 'tc-na', str
elseif string.match(str, '^style=".*" class="tc%-%w+%-?%w-" %| .*$') then
return string.match(str, '^style="(.*)" class="(tc%-%w+%-?%w-)" %| (.*)$')
elseif string.match(str, '^class="tc%-%w+%-?%w-" %| .*$') then
return nil, string.match(str, '^class="(tc%-%w+%-?%w-)" %| (.*)$')
end
return nil, nil, str
end
function p.OutputTable(f)
local args = require('Module:Arguments').getArgs(f)
local tableHtml = mw.html.create('table'):addClass('wikitable')
:tag('tr')
:tag('th'):wikitext('命令'):done()
:tag('th'):wikitext('执行结果'):done()
:tag('th'):wikitext('[[命令方块|成功次数]]增量'):allDone()
local _cmd = '任意'
local cmdType = ''
local cmdCount = 1
local isCmdChanged = true
local _situation = ''
local situationType = ''
local style = {}
local resultType
local _result
for i, v in ipairs(args) do
local value = tostring(v)
if i % 3 == 1 then
style[1] = nil
if value == 'any' or value == '任意' then
if _cmd ~= '任意' then
_cmd = '任意'
cmdCount = GetCount(args, i, 'any', 'cmd')
isCmdChanged = true
elseif i == 1 then
cmdCount = GetCount(args, i, 'any', 'cmd')
end
elseif _cmd ~= value and value ~= '*' and value ~= '~' then
style[1], cmdType, _cmd = GetTableChoice(value)
cmdCount = GetCount(args, i, value, 'cmd')
isCmdChanged = true
elseif i == 1 and (value == '*' or value == '~') then
cmdCount = GetCount(args, i, 'any', 'cmd')
end
elseif i % 3 == 2 then
style[2] = nil
if value == 'succeed' or value == 'yes' or value == '成功' then
_situation = '成功'
situationType = 'tc-yes'
elseif value == 'fail' or value == 'no' or value == '失败' then
_situation = '失败'
situationType = 'tc-no'
else
style[2], situationType, _situation = GetTableChoice(value)
end
elseif i % 3 == 0 then
style[3] = nil
style[3], resultType, _result = GetTableChoice(value)
local tableRow = tableHtml:tag('tr'):css('text-align', 'center')
if isCmdChanged then
isCmdChanged = false
tableRow:tag('td'):cssText(style[1]):attr({rowspan = cmdCount}):addClass(cmdType):wikitext(_cmd)
end
tableRow
:tag('td'):cssText(style[2]):addClass(situationType):wikitext(_situation):done()
:tag('td'):cssText(style[3]):addClass(resultType):wikitext(_result):done()
end
end
return tostring(tableHtml)
end
function p.ResultTable(f)
local args = require('Module:Arguments').getArgs(f)
local tableHtml = mw.html.create('table'):addClass('wikitable')
:tag('tr')
:tag('th'):wikitext('命令'):done()
:tag('th'):wikitext('触发条件'):done()
:tag('th'):wikitext('执行结果'):allDone()
local _cmd = '任意'
local cmdType = ''
local cmdCount = 1
local isCmdChanged = true
local _situation = ''
local isSituationSucceeded = false
local situationType = ''
local _result = ''
local isResultChanged = true
local resultCount = 1
local resultType = ''
local style = {}
for i, v in ipairs(args) do
local value = tostring(v)
if i % 3 == 1 then
style[1] = nil
if value == 'any' or value == '任意' then
if _cmd ~= '任意' then
_cmd = '任意'
cmdCount = GetCount(args, i, 'any', 'cmd')
isCmdChanged = true
elseif i == 1 then
cmdCount = GetCount(args, i, 'any', 'cmd')
end
elseif _cmd ~= value and value ~= '*' and value ~= '~' then
style[1], cmdType, _cmd = GetTableChoice(value)
cmdCount = GetCount(args, i, value, 'cmd')
isCmdChanged = true
elseif i == 1 and (value == '*' or value == '~') then
cmdCount = GetCount(args, i, 'any', 'cmd')
end
elseif i % 3 == 2 then
style[2] = nil
if value == 'succeed' or value == 'yes' or value == '成功' then
_situation = '执行成功'
situationType = 'tc-yes'
isSituationSucceeded = true
else
style[2], situationType, _situation = GetTableChoice(value)
end
elseif i % 3 == 0 then
style[3] = nil
if value == 'succeed' or value == 'yes' or value == '成功' then
if _result ~= '成功' then
_result = '成功'
resultType = 'tc-yes'
resultCount = GetCount(args, i, 'succeed', 'tc-result')
isResultChanged = true
end
elseif value == 'fail' or value == 'no' or value == '失败' then
if _result ~= '失败' then
_result = '失败'
resultType = 'tc-no'
resultCount = GetCount(args, i, 'fail', 'tc-result')
isResultChanged = true
end
else
resultCount = 1
style[3], resultType, _result = GetTableChoice(value)
isResultChanged = true
end
if isSituationSucceeded and resultType == nil then
resultType = 'tc-yes'
isSituationSucceeded = false
end
local tableRow = tableHtml:tag('tr'):css('text-align', 'center')
if isCmdChanged then
isCmdChanged = false
tableRow:tag('td'):cssText(style[1]):attr({rowspan = cmdCount}):addClass(cmdType):wikitext(_cmd)
end
tableRow:tag('td'):cssText(style[2]):addClass(situationType):wikitext(_situation)
if isResultChanged then
isResultChanged = false
tableRow:tag('td'):cssText(style[3]):attr({rowspan = resultCount}):addClass(resultType):wikitext(_result)
end
end
end
return tostring(tableHtml)
end
return p