全站通知:
模块:数据
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:数据/doc创建
local p = {}
local count = 0
SEPARATOR = '、'
p["输出"] = function(frame)
mw.log(string.len((frame.args)[1]))
return frame.args
end
p["生成材料列表"] = function(list)
local str = [[
]]
for i, item in ipairs(list) do
item = mw.text.trim(item)
if item ~= '' then
str = str..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {item,["尺寸"]="小"}
})
end
end
return str
end
p["生成带数字材料列表"] = function(list)
local str = [[
]]
local result = {}
for i, item in ipairs(list) do
item = mw.text.trim(item)
if item ~= '' then
result = mw.text.split(item,':')
if result[2] ~= nil and result[2] ~= "" then
str = str..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {result[1],result[2],["尺寸"]="小"}
})
else
str = str..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {result[1],["尺寸"]="小"}
})
end
end
end
return str
end
p["字符串生成带数字材料列表"] = function(str)
local result = {}
local result2 = {}
local str2 = [[]]
result = mw.text.split(str,SEPARATOR)
for i, item in ipairs(result) do
item = mw.text.trim(item)
if item ~= '' then
result2 = mw.text.split(item,':')
if result2[2] ~= nil then
str2 = str2.."[[文件:"..result2[1]..".png|50px|link="..result2[1].."]]x"..result2[2].." "
else
str2 = str2.."[[文件:"..result2[1]..".png|50px|link="..result2[1].."]]"
end
end
end
return str2
end
p["数据处理"] = function(frame)
local result = {}
args = frame.args
for k, v in pairs(args) do
if type(k) == 'number' then
result[k] = mw.text.split(v, SEPARATOR)
if v ~= "" then
count = count + 1
end
elseif type(v) == 'string' then
result[k] = mw.text.trim(v)
else
result[k] = v
end
end
return result
end
p["字符串数据处理"] = function(str)
local result = {}
local str2 = [[
]]
result = mw.text.split(str, SEPARATOR)
for i, item in ipairs(result) do
item = mw.text.trim(item)
if item ~= '' then
str2 = str2.."[[文件:"..item..".png|50px|link="..item.."]]"
end
end
return str2
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成铁安局驱逐系列掉落列表']({args={["系列任务名称"] = "抱残守缺系列",[1] = "城市声望、遗落的铁盟标准装备箱、铁盟币",[2] = "城市声望、遗落的铁盟优质装备箱、铁盟币",[3] = "城市声望、遗落的铁盟顶级装备箱",["任务1"] = "横行霸道",["任务2"] = "除恶务本",["任务3"] = "测试"} } ) )
*wiki >> {{#invoke: 数据| 生成铁安局驱逐系列掉落列表 | 系列任务名称 = 抱残守缺系列 | 1 = 城市声望、遗落的铁盟标准装备箱、铁盟币 | 2 = 城市声望、遗落的铁盟优质装备箱、铁盟币 | 3 = 遗落的铁盟顶级装备箱 | 任务1 = 横行霸道 | 任务2 = 除恶务本 | 任务3 = 测试}}
]]--
p["生成铁安局驱逐任务掉落列表"] = function(frame)
local arg = p["数据处理"](frame)
if arg["系列任务名称"] == "" then
return "|-"
end
_G.frame = frame
local content = [[]]
content = ([[
|-
| %s | '''%s''' || ]]):format("rowspan="..count,arg["系列任务名称"])
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
if i == 1 then
content = content..([[ '''%s''' || ]]):format(arg['任务'..i]or i)
else
content = content..([[
|-
|'''%s''' || ]]):format(arg['任务'..i]or i)
end
content = content..p["生成材料列表"](list)
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成铁安局悬赏任务列表']({args={["任务难度"] = "一星",[1] = "城市声望、遗落的铁盟标准装备箱、铁盟币",[2] = "城市声望、遗落的铁盟优质装备箱、铁盟币",[3] = "城市声望、遗落的铁盟顶级装备箱",["BOSS1"] = "横行霸道",["BOSS2"] = "除恶务本",["BOSS3"] = "测试",["推荐等级1"]="100",["推荐等级2"]="200",["推荐等级3"]="300"} } ) )
*wiki >>
]]--
p["生成铁安局悬赏任务列表"] = function(frame)
local arg = p["数据处理"](frame)
if arg["任务难度"] == "" or count == 0 then
return "|-"
end
_G.frame = frame
local content = [[]]
content = ([[
|-
| %s | '''%s''' || ]]):format("rowspan="..count,arg["任务难度"])
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
if i == 1 then
content = content..([[ '''%s''' || ]]):format(arg['BOSS'..i]or i)
content = content..([[ '''%s''' ||]]):format(arg['推荐等级'..i]or i)
else
content = content..([[
|-
|'''%s''' || ]]):format(arg['BOSS'..i]or i)
content = content..([[ '''%s''' || ]]):format(arg['推荐等级'..i]or i)
end
content = content..p["生成带数字材料列表"](list)
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成市政厅交易许可列表']({args={["累计投资额度1"] = "100000",["累计投资额度2"] = "200000",[1] = "红茶",[2] = "电脑",["商品1购买地点"] ="修格里城",["商品2购买地点"] ="铁盟哨站" } } ) )
*wiki >>
]]--
p["生成市政厅交易许可列表"] = function(frame)
local arg = p["数据处理"](frame)
_G.frame = frame
local content = [[]]
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
content = content..([[
|-
|'''%s''' || ]]):format(arg['累计投资额度'..i]or i)
if mw.text.trim(arg['商品'..i..'购买地点']) == "" then
content = content..p["生成材料列表"](list)..("购买城市:[[%s]]"):format(arg['城市名'])
else
content = content..p["生成材料列表"](list)..("购买城市:[[%s]]"):format(arg['商品'..i..'购买地点']or i)
end
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成交易所商品列表']({args={["商品1类型"] = "特产",["商品1加成"] = "叶珏",[1] = "红茶" } } ) )
*wiki >>
]]--
p["生成交易所商品列表"] = function(frame)
local content = [[]]
local arg = p["数据处理"](frame)
_G.frame = frame
for i, list in ipairs(arg) do
if list[1] ~= '' then
content = content..([[
|-
|%s || ]]):format("[[文件:"..list[1]..".png|50px|link="..list[1].."]]")
content = content..arg["商品"..i.."类型"].." || "
if mw.text.trim(arg["商品"..i.."加成"]) ~= "" then
content = content..arg["商品"..i.."加成"]
end
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成作战任务掉落列表']({args={["任务1"] = "作战名",[1] = "掉落物、掉落物2、掉落物3",["推荐等级1"] = "12",["首通1"]="桦石、金币" } } ) )
*wiki >>
]]--
p["生成作战计划掉落列表"] = function(frame)
local arg = p["数据处理"](frame)
_G.frame = frame
local content = [[]]
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
content = content..([[
|-
|%s || ]]):format(arg['任务'..i]or i)
content = content..([[ %s || ]]):format(arg['推荐等级'..i]or i)
content = content..p["字符串生成带数字材料列表"](arg['首通'..i]).."||"
content = content..p["生成材料列表"](list)
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成兑换列表']({args={[1] = "桦石:50、城市声望:50",["兑换物1"] = "兑换物123",["可兑换次数1"] = "11" } } ) )
*wiki >>
]]--
p["生成兑换列表"] = function(frame)
local arg = p["数据处理"](frame)
_G.frame = frame
local content = [[]]
local str = {}
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
str = mw.text.split(arg['兑换物'..i],':')
if str[2] ~= nil and str[2] ~= "" then
content = content..([==[
|-
|[[文件:%s.png|50px|link=%s]]x%s || ]==]):format(str[1]or"",str[1]or"",str[2]or"")
else
content = content..([==[
|-
|[[文件:%s.png|50px|link=%s]] || ]==]):format(str[1]or"",str[1]or"")
end
if arg['类型'..i] ~= nil then
content = content..([[ %s ||]]):format(arg['类型'..i])
end
content = content..([[ %s || ]]):format(arg['可兑换次数'..i]or i)
content = content..p["生成带数字材料列表"](list)
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成回收列表']({args={[1] = "桦石",["回收价格1"] = "铁盟币:10000" } } ) )
*wiki >>
]]--
p["生成回收列表"] = function(frame)
local arg = p["数据处理"](frame)
_G.frame = frame
local content = [[]]
local str = {}
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
content = content..([==[
|-
|[[文件:%s.png|50px|link=%s]] || ]==]):format(list[1] or i,list[1] or i)
str = mw.text.split(arg['回收价格'..i],':')
content = content..([==[[[文件:%s.png|50px|link=%s]]x%s]==]):format(str[1]or"",str[1]or"",str[2]or"")
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成物资订单列表']({args={[1] = "声望:50、金钱:100",["订单1"] = "红茶:100、绿茶:10" } } ) )
*wiki >>
]]--
p["生成物资订单列表"] = function(frame)
local arg = p["数据处理"](frame)
_G.frame = frame
local content = [[]]
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
content = content..[[
|-
|]]
content = content..p["字符串生成带数字材料列表"](arg['订单'..i]).."||"
content = content..p["生成带数字材料列表"](list)
end
end
content = mw.text.trim(content)
return content
end
--[[
*测试输入
*控制台 >> mw.logObject(p['生成物资订单列表']({args={[1] = "声望:50、金钱:100",["订单1"] = "红茶:100、绿茶:10" } } ) )
*wiki >>
]]--
p["生成支援计划列表"] = function(frame)
local arg = p["数据处理"](frame)
_G.frame = frame
local content = [[]]
for i, list in ipairs(arg) do
if list and #list > 0 and mw.text.trim(list[1]) ~= '' then
content = content..([[
|-
| %s || ]]):format(arg["阶段"..i])
content = content..p["生成带数字材料列表"](list)
end
end
content = mw.text.trim(content)
return content
end
--[==[
*测试输入
*控制台 >> mw.logObject(p['生成列表']({args={["表格列数"] = "6",["标题1"] = "电力等级#colspan=5",["标题2"] = "所需材料",["标题3"] = "插槽数量",["标题4"] = "车厢数量",["标题5"] = "电力总值",["标题6"] = "列车时速",["电力等级1"]="1*#kkk",["所需材料1"]="铁盟币:200、桦石:20",["电力等级2"]="2*",["插槽数量1"]="0 *#rowspan=4",["车厢数量1"]="4 *#rowspan=9",["电力总值1"]="",["列车时速1"]="",["所需材料2"]="铁盟币、桦石",["电力等级3"]="3*",["所需材料3"]="铁盟币" }} ) )
本函数可以生成大部分形状的标准表格,允许自定义表格列数、支持将材料名转化为图标;
支持将材料名:数量转化为图标x数量、支持多个材料名同时转化、支持填写列表参数。
注:本函数支持处理以下特殊符号:
符号 样例 处理结果 简介
: 铁盟币:50 [[文件:铁盟币|50px|link=铁盟币]]x50 将材料名与材料数量分隔开
、 铁盟币、桦石 [[文件:铁盟币|50px|link=铁盟币]] [[文件:桦石|50px|link=桦石]] 将不同材料之间分隔开
# 铁盟币:50 #rowspan=5 rowspan=5 | [[文件:铁盟币|50px|link=铁盟币]]x50 将表格内容和表格参数分隔开
* 100* 100 代表该内容不需要任何处理,直接被输出到表格中
没有任何特殊符号 铁盟币 [[文件:铁盟币|50px|link=铁盟币]] 将材料名转化为材料图标
符号之间除了*以外都可以相互嵌套使用,如
符号 样例 处理结果
:、# 铁盟币:50、桦石:100 #rowspan=5 rowspan=5 | [[文件:铁盟币|50px|link=铁盟币]]x50 [[文件:桦石|50px|link=桦石]]x100
注意事项:符号#后方的所有特殊符号不会再被识别
假设参数 表格列数 = x
则需要以下参数: 标题1 标题2 标题3.......标题x
对应的应当有参数名为标题11 标题12 标题13..... 标题21 标题22 标题23..... 标题x1 标题x2 标题x3......等参数举例如下:
style="width:15%;font-weight:bold"
↓的属性
名称 兑换次数 所需材料
桦石 10 [[文件:铁盟币|50px|link=铁盟币]]
枝条 100 [[文件:铁盟币|50px|link=铁盟币]]x50
口香糖 1000 [[文件:铁盟币|50px|link=铁盟币]]x100 [[文件:桦石|50px|link=桦石]]
上述表格转化为wiki语言为:
{{#invoke: 数据| 生成列表
| 表格列数 = 3
| 标题1 = 名称#style="width:15%;font-weight:bold"
| 标题2 = 兑换次数
| 标题3 = 所需材料
| 名称1 = 桦石*
| 兑换次数1 = 10*
| 所需材料1 = 铁盟币
| 名称2 = 枝条*
| 兑换次数2 = 100*
| 所需材料2 = 铁盟币:50
| 名称3 = 口香糖*
| 兑换次数3 = 1000*
| 所需材料3 = 铁盟币:100、桦石
}}
{{道具图标|桦树鞭毛|32K|尺寸=小}}
]==]--
p["生成列表"] = function(frame)
local arg = frame.args
_G.frame = frame
local str = [[]]
local str1 = [[]]
local str2 = [[]]
local result = {}
local result2 = {}
local content = [[
|-
! ]]
local count = 1
for i=1, tonumber(arg['表格列数']) do
if i ~= 1 then
content = content.." !! "
end
if arg['标题'..tostring(i)] ~= nil and arg['标题'..tostring(i)] ~= ""then
str = arg['标题'..tostring(i)]
s = string.find(str,"#")
if s ~= nil then
str1 = string.sub(str,1,s-1)
str2 = string.sub(str,s+1)
content = content..str2.." | "
arg['标题'..tostring(i)] = mw.text.trim(str1)
str = str1
end
content = content..str
end
end
while true do
if arg[arg['标题'.."1"]..count] == nil or arg[arg['标题'.."1"]..count] == "" or arg[arg['标题'.."1"]..count] == " " or arg[arg['标题'.."1"]..count] == "*" or arg[arg['标题'.."1"]..count] == "* "then
if arg['标题'.."2"] ~= nil and arg['标题'.."2"] ~= "" and arg['标题'.."2"] ~= " " then
if arg[arg['标题'.."2"]..count] == nil or arg[arg['标题'.."2"]..count] == "" or arg[arg['标题'.."2"]..count] == " " or arg[arg['标题'.."2"]..count] == "*" or arg[arg['标题'.."2"]..count] == "* "then
if arg['标题'.."3"] ~= nil and arg['标题'.."3"] ~= "" and arg['标题'.."3"] ~= " " then
if arg[arg['标题'.."3"]..count] == nil or arg[arg['标题'.."3"]..count] == "" or arg[arg['标题'.."3"]..count] == " " or arg[arg['标题'.."3"]..count] == "*" or arg[arg['标题'.."3"]..count] == "* "then
break
end
else
break
end
end
else
break
end
end
content = content..[[
|-
]]
for i=1, tonumber(arg['表格列数']) do
if arg['标题'..tostring(i)] == nil or arg[arg['标题'..tostring(i)]..tostring(count)] == nil or arg['标题'..tostring(i)] == "" or arg[arg['标题'..tostring(i)]..tostring(count)] == "" then
else
str = arg[arg['标题'..tostring(i)]..tostring(count)]
s = string.find(str,"#")
if s ~= nil then
str1 = string.sub(str,1,s-1)
str2 = string.sub(str,s+1)
content = content.."| "..str2.." | "
str = str1
else
if i ~= 1 then
content = content.." || "
else
content = content.." | "
end
end
t = string.find(str,"、")
w = string.find(str,"*")
if w ~= nil then
str1 = string.sub(str,1,w-1)
if w ~= string.len(str) then
str2 = string.sub(str,w+1)
content = content..str1..str2
else
content = content..str1
end
else
if t ~= nil then
result2 = mw.text.split(str, "、")
for j, str4 in ipairs(result2) do
f = string.find(str4,":")
if f ~= nil then
result3 = mw.text.split(str4, ":")
str1 = result3[1]
str2 = result3[2]
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {str1,str2,["尺寸"]="小"}
})
else
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {str4,["尺寸"]="小"}
})
end
end
else
f = string.find(str,":")
if f ~= nil then
result2 = mw.text.split(str, ":")
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {result2[1],result2[2],["尺寸"]="小"}
})
else
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {str,["尺寸"]="小"}
})
end
end
end
content = content..[[
]]
end
end
count = count + 1
end
content = mw.text.trim(content)
return content
end
p["生成道具图标"] = function(frame)
local arg = frame.args
local str = arg[1]
local content = [[]]
t = string.find(str,"、")
if t ~= nil then
result = mw.text.split(str, "、")
for j, str1 in ipairs(result) do
f = string.find(str1,":")
if f ~= nil then
result2 = mw.text.split(str1, ":")
str1 = result2[1]
str2 = result2[2]
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {str1,str2}
})
else
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {str1}
})
end
end
else
f = string.find(str,":")
if f ~= nil then
result = mw.text.split(str, ":")
str1 = result[1]
str2 = result[2]
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {str1,str2}
})
else
content = content..mw.text.trim(frame:expandTemplate{
title = '道具图标',
args = {str1}
})
end
end
return content
end
return p