模块:EquipmentInfoList:修订间差异
跳转到导航
跳转到搜索
创建页面,内容为“-- 模块:EventShopCounter -- 功能:统计活动商店数据中各阶段的物品数量 local p = {} -- 模块对外接口表 function p.countItems(frame) local args = frame.args local dataText = args.data or '' -- 初始化计数器 local counters = { ["金色阶段"] = 0, ["紫色阶段"] = 0, ["灰色阶段"] = 0, ["无限库存区"] = 0, ["其他"] = 0 } local currentStage = "其他"…” |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | |||
local p = {} | |||
function p. | function p.list(frame) | ||
local args = (frame == mw.getCurrentFrame() and frame.args) or frame | |||
local token_name = mw.text.trim(args["token_alias"] or "") | |||
local token_icon_file = mw.text.trim(args["token_icon"] or "道具_" .. token_name .. ".png") | |||
local token_icon_size = mw.text.trim(args["token_icon_size"] or "30px") | |||
local data_str = mw.text.trim(args["data"] or "") | |||
local nocss = mw.text.trim(args["nocss"] or "") | |||
local token_icon = string.format("[[File:%s|%s|link=]]", token_icon_file, token_icon_size) | |||
local selectall_str = frame:callParserFunction{name = '#Widget:ShopItemSelectAll', args = {item = token_name}} | |||
local checkbox_css = frame:callParserFunction{name = '#Widget:ShopItemListCss'} | |||
res_table = {} | |||
if nocss=="" then | |||
table.insert(res_table, checkbox_css .. "\n") | |||
end | |||
table.insert(res_table, '{| class="wikitable logo eventshoplist" style="white-space:normal;width:600px;max-width:100%;display:table;"\n') | |||
table.insert(res_table, string.format('!style="width:1.5em;"|%s!!可兑换道具!!style="width:5.0em;"|库存!!style="width:6.0em;"|单价\n', selectall_str)) | |||
local data_table = mw.text.split(data_str, "\n", true) | |||
local colorTable = {["金"]="#FFE0B2",["紫"]="#D1C4E9",["蓝"]="#BBDEFB",["灰"]="#E0E0E0",["复刻"]="linear-gradient(90deg,#b2f7ff,#bfb0f9);",["彩"]="linear-gradient(90deg,#FFE082,#FFCCBC,#A5D6A7,#FFCC80);"} | |||
local cur_collapseGroup = nil | |||
local cur_collapseGroupCollapse = nil | |||
for i = 1, #data_table do | |||
local datum_table = mw.text.split(data_table[i], ";;", true) | |||
local name = mw.text.trim(datum_table[2] or "") | |||
if datum_table[1]:sub(1,1)=='G' then --折叠模式 | |||
groupParam = mw.text.split(datum_table[1], "/", true) | |||
if groupParam[2] == 'X' then --结束折叠呼号 | |||
cur_collapseGroup = nil | |||
cur_collapseGroupCollapse = nil | |||
else --执行折叠呼号 | |||
cur_collapseGroup = groupParam[2] --取出ID | |||
cur_collapseGroupCollapse = (not groupParam[3]) and true or false --是否不折叠(直接显示) | |||
--换行符 | |||
local str = '|-' | |||
if datum_table[3] or datum_table[4] then | |||
str = str .. "style=\"text-align:center; " | |||
if datum_table[3] then str = str.."background:"..datum_table[3].."; " end | |||
if datum_table[4] then str = str.."color:"..datum_table[4]..";" end | |||
str = str .."\"" | |||
end | |||
str = str .. "\n" | |||
table.insert(res_table, str) | |||
--标题 | |||
table.insert(res_table, string.format("|colspan=3|'''%s'''\n", name)) | |||
--按钮 | |||
str = "|class=\"mw-customtoggle-eventShopList%s mw-collapsible __isC1__\" id=\"mw-customcollapsible-eventShopList%s\"|展开 <span class=\"mdi mdi-chevron-down\"></span>\n" | |||
str = str .. "|class=\"mw-customtoggle-eventShopList%s mw-collapsible __isC2__\" id=\"mw-customcollapsible-eventShopList%s\"|收起 <span class=\"mdi mdi-chevron-up\"></span>\n" | |||
str = string.format(str, cur_collapseGroup, cur_collapseGroup, cur_collapseGroup, cur_collapseGroup) | |||
if not cur_collapseGroupCollapse then --为空时不折叠 | |||
str = (str:gsub("__isC1__", "mw-collapsed")):gsub("__isC2__", "") | |||
else | |||
str = (str:gsub("__isC1__", "")):gsub("__isC2__", "mw-collapsed") | |||
end | |||
table.insert(res_table, str) | |||
end | |||
elseif datum_table[1]=='X' then --普通标题 | |||
table.insert(res_table, '|-\n') | |||
if datum_table[3] or datum_table[4] then | |||
local str = "|style=\"text-align:center; " | |||
if datum_table[3] then str = str.."background:"..datum_table[3].."; " end | |||
if datum_table[4] then str = str.."color:"..datum_table[4]..";" end | |||
str = str..string.format("\" colspan=4|'''%s'''\n", name) | |||
table.insert(res_table, str) | |||
else | |||
table.insert(res_table, string.format("!colspan=4|%s\n", name)) | |||
end | |||
elseif datum_table[1]=='C' then --注释 | |||
table.insert(res_table, '|-\n') | |||
local str = "|__style__ __curColl__ colspan=4|%s\n" | |||
if datum_table[3] or datum_table[4] then | |||
local sstr = "" | |||
if datum_table[3] then sstr = sstr.."background:"..datum_table[3].."; " end | |||
if datum_table[4] then sstr = sstr.."color:"..datum_table[4]..";" end | |||
str = str:gsub("__style__", sstr) | |||
else | |||
str = str:gsub("__style__", "") | |||
end | |||
if cur_collapseGroup then | |||
local cgstr = ("class=\"mw-collapsible __isC__\" id=\"mw-customcollapsible-eventShopList%s\""):format(cur_collapseGroup) | |||
cgstr = cgstr:gsub("__isC__", cur_collapseGroupCollapse and "mw-collapsed" or "") | |||
str = str:gsub("__curColl__", cgstr) | |||
else | |||
str = str:gsub("__curColl__", "") | |||
end | |||
str = string.format(str, name) | |||
table.insert(res_table, str) | |||
else --商品 | |||
local color = mw.text.trim(datum_table[5] or "") | |||
local textColor = mw.text.trim(datum_table[6] or "") | |||
local checkbox_str = "" | |||
local num_limit = tonumber(mw.text.trim(datum_table[3] or "")) | |||
local unit_price = tonumber(mw.text.trim(datum_table[4] or "")) | |||
if num_limit ~= nil and unit_price ~= nil then | |||
checkbox_str = frame:expandTemplate{title = "商店列表复选框", args = { token_name, num_limit * unit_price, ((datum_table[1] == '1') and "是" or "否")}} | |||
end | |||
local num_limit_str = (num_limit ~= nil) and num_limit or mw.text.trim(datum_table[3] or "——") | |||
local unit_price_str = (unit_price ~= nil) and tostring(unit_price) or mw.text.trim(datum_table[4] or "——") | |||
--换行 | |||
local str = '|-__style__ __curColl__\n' | |||
if color~="" or textColor~="" then | |||
str = str:gsub("__style__", string.format("style=\"background:%s;color:%s\"", colorTable[color] or color, textColor) ) | |||
else | |||
str = str:gsub("__style__ ", "") | |||
end | |||
if cur_collapseGroup then | |||
local cgstr = ("class=\"mw-collapsible __isC__\" id=\"mw-customcollapsible-eventShopList%s\""):format(cur_collapseGroup) | |||
cgstr = cgstr:gsub("__isC__", cur_collapseGroupCollapse and "mw-collapsed" or "") | |||
str = str:gsub("__curColl__", cgstr) | |||
else | |||
str = str:gsub("__curColl__", "") | |||
end | |||
table.insert(res_table, str) | |||
--table.insert(res_table, (color ~= "") and (string.format('|-style="background:%s"\n', color)) or ('|-\n')) | |||
table.insert(res_table, string.format("|%s||%s||%s||%s%s\n", checkbox_str, name, num_limit_str, token_icon, unit_price_str)) | |||
end | |||
end | |||
local total_str = frame:callParserFunction{name = '#Widget:ShopItemTotalCost', args = {item = token_name}} | |||
table.insert(res_table, '|-\n') | |||
table.insert(res_table, string.format('| ||colspan="2"|勾选项目总价||%s\'\'\'%s\'\'\'\n', token_icon, total_str)) | |||
table.insert(res_table, '|}') | |||
return table.concat(res_table) | |||
end | end | ||
return p | return p | ||
2025年12月17日 (三) 06:23的版本
此模块的文档可以在模块:EquipmentInfoList/doc创建
local p = {}
function p.list(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
local token_name = mw.text.trim(args["token_alias"] or "")
local token_icon_file = mw.text.trim(args["token_icon"] or "道具_" .. token_name .. ".png")
local token_icon_size = mw.text.trim(args["token_icon_size"] or "30px")
local data_str = mw.text.trim(args["data"] or "")
local nocss = mw.text.trim(args["nocss"] or "")
local token_icon = string.format("[[File:%s|%s|link=]]", token_icon_file, token_icon_size)
local selectall_str = frame:callParserFunction{name = '#Widget:ShopItemSelectAll', args = {item = token_name}}
local checkbox_css = frame:callParserFunction{name = '#Widget:ShopItemListCss'}
res_table = {}
if nocss=="" then
table.insert(res_table, checkbox_css .. "\n")
end
table.insert(res_table, '{| class="wikitable logo eventshoplist" style="white-space:normal;width:600px;max-width:100%;display:table;"\n')
table.insert(res_table, string.format('!style="width:1.5em;"|%s!!可兑换道具!!style="width:5.0em;"|库存!!style="width:6.0em;"|单价\n', selectall_str))
local data_table = mw.text.split(data_str, "\n", true)
local colorTable = {["金"]="#FFE0B2",["紫"]="#D1C4E9",["蓝"]="#BBDEFB",["灰"]="#E0E0E0",["复刻"]="linear-gradient(90deg,#b2f7ff,#bfb0f9);",["彩"]="linear-gradient(90deg,#FFE082,#FFCCBC,#A5D6A7,#FFCC80);"}
local cur_collapseGroup = nil
local cur_collapseGroupCollapse = nil
for i = 1, #data_table do
local datum_table = mw.text.split(data_table[i], ";;", true)
local name = mw.text.trim(datum_table[2] or "")
if datum_table[1]:sub(1,1)=='G' then --折叠模式
groupParam = mw.text.split(datum_table[1], "/", true)
if groupParam[2] == 'X' then --结束折叠呼号
cur_collapseGroup = nil
cur_collapseGroupCollapse = nil
else --执行折叠呼号
cur_collapseGroup = groupParam[2] --取出ID
cur_collapseGroupCollapse = (not groupParam[3]) and true or false --是否不折叠(直接显示)
--换行符
local str = '|-'
if datum_table[3] or datum_table[4] then
str = str .. "style=\"text-align:center; "
if datum_table[3] then str = str.."background:"..datum_table[3].."; " end
if datum_table[4] then str = str.."color:"..datum_table[4]..";" end
str = str .."\""
end
str = str .. "\n"
table.insert(res_table, str)
--标题
table.insert(res_table, string.format("|colspan=3|'''%s'''\n", name))
--按钮
str = "|class=\"mw-customtoggle-eventShopList%s mw-collapsible __isC1__\" id=\"mw-customcollapsible-eventShopList%s\"|展开 <span class=\"mdi mdi-chevron-down\"></span>\n"
str = str .. "|class=\"mw-customtoggle-eventShopList%s mw-collapsible __isC2__\" id=\"mw-customcollapsible-eventShopList%s\"|收起 <span class=\"mdi mdi-chevron-up\"></span>\n"
str = string.format(str, cur_collapseGroup, cur_collapseGroup, cur_collapseGroup, cur_collapseGroup)
if not cur_collapseGroupCollapse then --为空时不折叠
str = (str:gsub("__isC1__", "mw-collapsed")):gsub("__isC2__", "")
else
str = (str:gsub("__isC1__", "")):gsub("__isC2__", "mw-collapsed")
end
table.insert(res_table, str)
end
elseif datum_table[1]=='X' then --普通标题
table.insert(res_table, '|-\n')
if datum_table[3] or datum_table[4] then
local str = "|style=\"text-align:center; "
if datum_table[3] then str = str.."background:"..datum_table[3].."; " end
if datum_table[4] then str = str.."color:"..datum_table[4]..";" end
str = str..string.format("\" colspan=4|'''%s'''\n", name)
table.insert(res_table, str)
else
table.insert(res_table, string.format("!colspan=4|%s\n", name))
end
elseif datum_table[1]=='C' then --注释
table.insert(res_table, '|-\n')
local str = "|__style__ __curColl__ colspan=4|%s\n"
if datum_table[3] or datum_table[4] then
local sstr = ""
if datum_table[3] then sstr = sstr.."background:"..datum_table[3].."; " end
if datum_table[4] then sstr = sstr.."color:"..datum_table[4]..";" end
str = str:gsub("__style__", sstr)
else
str = str:gsub("__style__", "")
end
if cur_collapseGroup then
local cgstr = ("class=\"mw-collapsible __isC__\" id=\"mw-customcollapsible-eventShopList%s\""):format(cur_collapseGroup)
cgstr = cgstr:gsub("__isC__", cur_collapseGroupCollapse and "mw-collapsed" or "")
str = str:gsub("__curColl__", cgstr)
else
str = str:gsub("__curColl__", "")
end
str = string.format(str, name)
table.insert(res_table, str)
else --商品
local color = mw.text.trim(datum_table[5] or "")
local textColor = mw.text.trim(datum_table[6] or "")
local checkbox_str = ""
local num_limit = tonumber(mw.text.trim(datum_table[3] or ""))
local unit_price = tonumber(mw.text.trim(datum_table[4] or ""))
if num_limit ~= nil and unit_price ~= nil then
checkbox_str = frame:expandTemplate{title = "商店列表复选框", args = { token_name, num_limit * unit_price, ((datum_table[1] == '1') and "是" or "否")}}
end
local num_limit_str = (num_limit ~= nil) and num_limit or mw.text.trim(datum_table[3] or "——")
local unit_price_str = (unit_price ~= nil) and tostring(unit_price) or mw.text.trim(datum_table[4] or "——")
--换行
local str = '|-__style__ __curColl__\n'
if color~="" or textColor~="" then
str = str:gsub("__style__", string.format("style=\"background:%s;color:%s\"", colorTable[color] or color, textColor) )
else
str = str:gsub("__style__ ", "")
end
if cur_collapseGroup then
local cgstr = ("class=\"mw-collapsible __isC__\" id=\"mw-customcollapsible-eventShopList%s\""):format(cur_collapseGroup)
cgstr = cgstr:gsub("__isC__", cur_collapseGroupCollapse and "mw-collapsed" or "")
str = str:gsub("__curColl__", cgstr)
else
str = str:gsub("__curColl__", "")
end
table.insert(res_table, str)
--table.insert(res_table, (color ~= "") and (string.format('|-style="background:%s"\n', color)) or ('|-\n'))
table.insert(res_table, string.format("|%s||%s||%s||%s%s\n", checkbox_str, name, num_limit_str, token_icon, unit_price_str))
end
end
local total_str = frame:callParserFunction{name = '#Widget:ShopItemTotalCost', args = {item = token_name}}
table.insert(res_table, '|-\n')
table.insert(res_table, string.format('| ||colspan="2"|勾选项目总价||%s\'\'\'%s\'\'\'\n', token_icon, total_str))
table.insert(res_table, '|}')
return table.concat(res_table)
end
return p