模块:装备
来自卡厄思梦境WIKI
此模块的文档可以在模块:装备/doc创建
local p = {}
local equipmentData = mw.loadData('模块:装备/data')
-- 辅助函数:解析文本格式
local function parseText(text)
if not text then return "" end
-- 将 {{文本|橙|数值}} 格式转换为HTML
text = text:gsub("{{文本|橙|([^}]+)}}", '<span style="color:#ff9500">%1</span>')
return text
end
-- 生成单个装备卡片
function p.card(frame)
local args = frame.args
local name = args[1] or args.name
local level = args[2] or args.level or "1"
if not name or not equipmentData[name] then
return "装备不存在"
end
local equip = equipmentData[name]
local base = equip.base
local levelData = equip[level]
if not levelData then
return "等级数据不存在"
end
-- 生成装备卡片HTML
local html = '<div class="equipment-card" style="position: relative; display: inline-block; width:150px; height: 230px;" data-equipment="' .. name .. '" data-level="' .. level .. '">'
html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_' .. base.rarity .. '.png|150px|link=]]</div>'
html = html .. '<div style="position: absolute; top: 43px; left: 13px;">[[File:' .. base.art .. '|124px|link=]]</div>'
html = html .. '<div style="position: absolute; bottom: 5px; left: 5px; width: 140px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px"></div>'
html = html .. '<div style="position: absolute; bottom: 10px; left: 20px;">[[File:icon_star_rating_' .. level .. '.png|link=]]</div>'
html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:equipment_顶层蒙版.png|150px|link=]]</div>'
html = html .. '</div>'
return frame:preprocess(html)
end
-- 生成装备详情弹窗
function p.popup(frame)
local args = frame.args
local name = args[1] or args.name
local level = args[2] or args.level or "1"
if not name or not equipmentData[name] then
return "装备不存在"
end
local equip = equipmentData[name]
local base = equip.base
local levelData = equip[level]
if not levelData then
return "等级数据不存在"
end
local desc = parseText(levelData.desc_global)
local encodedName = mw.uri.encode(name)
-- 生成弹窗HTML
local html = '<div class="equipment-popup" id="popup-' .. encodedName .. '-' .. level .. '" style="display:none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">'
html = html .. '<div style="position: relative; display: inline-block; width:368px; height: 335px; background-color: #343434; border-radius: 9px">'
html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_collection_rarity_' .. base.rarity .. '.png|link=]]</div>'
html = html .. '<div style="position: absolute; top: 40px; left: 128px;">[[File:' .. base.art .. '|124px|link=]]</div>'
html = html .. '<div style="position: absolute; top: 167px; left: 0px; width: 368px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px"></div>'
html = html .. '<div style="position: absolute; top: 173px; left: 128px;">[[File:icon_star_rating_' .. level .. '.png|link=]]</div>'
html = html .. '<div style="position: absolute; top: 205px; left: 5px; color: white">[[File:icon_equip_' .. base.type .. '_' .. base.rarity .. '.png|25px|link=]]</div>'
html = html .. '<div style="position: absolute; top: 209px; left: 33px; color: white">' .. name .. '</div>'
html = html .. '<div style="position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px"></div>'
html = html .. '<div style="position: absolute; top: 242px; left: 14px; color: white">' .. base.value_type .. '</div>'
html = html .. '<div style="position: absolute; top: 242px; right: 14px; color: white">' .. tostring(levelData.value) .. '</div>'
html = html .. '<div style="position: absolute; top: 277px; left: 10px; right: 10px; color: white">' .. desc .. '</div>'
html = html .. '</div></div>'
return frame:preprocess(html)
end
-- 生成装备卡片和弹窗的组合
function p.show(frame)
local args = frame.args
local name = args[1] or args.name
local level = args[2] or args.level or "1"
local card = p.card(frame)
local popup = p.popup(frame)
return card .. popup
end
-- 批量显示装备
function p.list(frame)
local result = {}
for name, _ in pairs(equipmentData) do
-- 创建一个新的frame对象用于传递参数
local newFrame = {
args = {name = name, level = "1"},
preprocess = frame.preprocess
}
table.insert(result, p.show(newFrame))
end
return table.concat(result, "\n")
end
-- 显示指定区域的装备
function p.areaList(frame)
local args = frame.args
local area = args[1] or args.area
if not area then
return "请指定区域"
end
local result = {}
for name, equip in pairs(equipmentData) do
if equip.base.area == area then
local newFrame = {
args = {name = name, level = "1"},
preprocess = frame.preprocess
}
table.insert(result, p.show(newFrame))
end
end
if #result == 0 then
return "该区域没有装备"
end
return table.concat(result, "\n")
end
-- 显示指定稀有度的装备
function p.rarityList(frame)
local args = frame.args
local rarity = args[1] or args.rarity
if not rarity then
return "请指定稀有度"
end
local result = {}
for name, equip in pairs(equipmentData) do
if equip.base.rarity == rarity then
local newFrame = {
args = {name = name, level = "1"},
preprocess = frame.preprocess
}
table.insert(result, p.show(newFrame))
end
end
if #result == 0 then
return "该稀有度没有装备"
end
return table.concat(result, "\n")
end
return p