模块

模块:装备

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献2025年10月17日 (五) 16:42的版本

此模块的文档可以在模块:装备/doc创建

local p = {}
local data = mw.loadData('模块:装备/data')

-- 获取装备稀有度对应的中文
local rarityMap = {
    ["蓝"] = "蓝",
    ["紫"] = "紫", 
    ["金"] = "金"
}

-- 生成装备卡片
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 data[name] then
        return "装备不存在: " .. (name or "未指定")
    end
    
    local equip = data[name]
    local base = equip.base
    local levelData = equip[level]
    
    if not levelData then
        return "装备等级不存在: " .. level
    end
    
    -- 生成HTML
    local html = mw.html.create('div')
        :addClass('equipment-card')
        :attr('data-equipment', name)
        :attr('data-level', level)
        :cssText('position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;')
    
    -- 背景
    html:tag('div')
        :cssText('position: absolute; top: 0px; left: 0px;')
        :wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', base.rarity))
    
    -- 装备图片
    html:tag('div')
        :cssText('position: absolute; top: 43px; left: 13px;')
        :wikitext(string.format('[[File:%s|124px|link=]]', base.art))
    
    -- 底部背景
    html:tag('div')
        :cssText('position: absolute; bottom: 5px; left: 5px; width: 140px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px')
    
    -- 星级
    html:tag('div')
        :cssText('position: absolute; bottom: 10px; left: 20px;')
        :wikitext(string.format('[[File:icon_star_rating_%s.png|link=]]', level))
    
    -- 顶层蒙版
    html:tag('div')
        :cssText('position: absolute; top: 0px; left: 0px;')
        :wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]')
    
    return tostring(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 data[name] then
        return "装备不存在: " .. (name or "未指定")
    end
    
    local equip = data[name]
    local base = equip.base
    local levelData = equip[level]
    
    if not levelData then
        return "装备等级不存在: " .. level
    end
    
    -- 处理描述文本
    local desc = levelData.desc_global
    desc = string.gsub(desc, "{{文本|橙|([^}]+)}}", '<span style="color:#ff9500;">%1</span>')
    
    -- 生成HTML
    local html = mw.html.create('div')
        :addClass('equipment-popup')
        :attr('id', 'equipment-popup-' .. mw.uri.encode(name))
        :cssText('position: relative; display: none; width:368px; height: 335px; background-color: #343434; border-radius: 9px')
    
    -- 背景
    html:tag('div')
        :cssText('position: absolute; top: 0px; left: 0px;')
        :wikitext(string.format('[[File:bg_collection_rarity_%s.png|link=]]', base.rarity))
    
    -- 装备图片
    html:tag('div')
        :cssText('position: absolute; top: 40px; left: 128px;')
        :wikitext(string.format('[[File:%s|124px|link=]]', base.art))
    
    -- 星级背景
    html:tag('div')
        :cssText('position: absolute; top: 167px; left: 0px; width: 368px; height: 35px; background-color: rgba(0,0,0,0.5);')
    
    -- 星级
    html:tag('div')
        :cssText('position: absolute; top: 173px; left: 128px;')
        :wikitext(string.format('[[File:icon_star_rating_%s.png|link=]]', level))
    
    -- 类型图标
    html:tag('div')
        :cssText('position: absolute; top: 205px; left: 5px; color: white')
        :wikitext(string.format('[[File:icon_equip_%s_%s.png|25px|link=]]', base.type, base.rarity))
    
    -- 装备名称
    html:tag('div')
        :cssText('position: absolute; top: 209px; left: 33px; color: white')
        :wikitext(name)
    
    -- 属性背景
    html:tag('div')
        :cssText('position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px')
    
    -- 属性类型
    html:tag('div')
        :cssText('position: absolute; top: 242px; left: 14px; color: white')
        :wikitext(base.value_type)
    
    -- 属性值
    html:tag('div')
        :cssText('position: absolute; top: 242px; right: 14px; color: white')
        :wikitext(levelData.value)
    
    -- 描述
    html:tag('div')
        :cssText('position: absolute; top: 277px; left: 10px; right: 10px; color: white; font-size: 14px;')
        :wikitext(desc)
    
    -- 关闭按钮
    html:tag('div')
        :addClass('equipment-popup-close')
        :cssText('position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; cursor: pointer; color: white; font-size: 20px;')
        :wikitext('×')
    
    return tostring(html)
end

-- 生成装备完整展示(卡片+弹窗)
function p.show(frame)
    local cardHtml = p.card(frame)
    local popupHtml = p.popup(frame)
    
    local wrapper = mw.html.create('div')
        :addClass('equipment-wrapper')
        :cssText('display: inline-block; position: relative;')
        :wikitext(cardHtml)
        :wikitext(popupHtml)
    
    return tostring(wrapper)
end

-- 生成装备列表
function p.list(frame)
    local html = mw.html.create('table')
        :attr('id', 'CardSelectTr')
        :addClass('wikitable')
        :cssText('width: 100%;')
    
    -- 表头
    local headerRow = html:tag('thead'):tag('tr')
        :attr('id', 'CardSelectTabHeader')
    
    headerRow:tag('th'):wikitext('装备')
    headerRow:tag('th'):wikitext('稀有度')
    headerRow:tag('th'):wikitext('区域') 
    headerRow:tag('th'):wikitext('类型')
    headerRow:tag('th'):wikitext('属性')
    headerRow:tag('th'):wikitext('TAG')
    
    -- 表体
    local tbody = html:tag('tbody')
    
    -- 遍历所有装备
    for name, equipData in pairs(data) do
        if equipData.base then
            -- 默认显示5星装备
            local level = "5"
            local levelData = equipData[level]
            
            if levelData then
                local row = tbody:tag('tr')
                    :attr('data-param1', equipData.base.rarity)
                    :attr('data-param2', equipData.base.area)
                    :attr('data-param3', equipData.base.tag)
                
                -- 装备名称与图片
                row:tag('td'):tag('div')
                    :cssText('display: flex; align-items: center;')
                    :tag('div')
                        :cssText('width: 60px; height: 60px; margin-right: 10px;')
                        :wikitext(string.format('[[File:%s|60px|link=]]', equipData.base.art))
                    :done()
                    :tag('div')
                        :tag('b'):wikitext(name):done()
                        :tag('br')
                        :tag('span'):cssText('color: #666; font-size: 0.9em;')
                            :wikitext('★★★★★')
                
                -- 稀有度
                local rarityColor = {
                    ["蓝"] = "#5BA3E0",
                    ["紫"] = "#B768D2", 
                    ["金"] = "#FFB13F"
                }
                row:tag('td')
                    :cssText('text-align: center; color: ' .. (rarityColor[equipData.base.rarity] or '#000'))
                    :wikitext(equipData.base.rarity)
                
                -- 区域
                row:tag('td'):wikitext(equipData.base.area)
                
                -- 类型
                row:tag('td'):wikitext(equipData.base.type)
                
                -- 属性
                row:tag('td'):wikitext(equipData.base.value_type .. ': ' .. levelData.value)
                
                -- TAG
                row:tag('td'):wikitext(equipData.base.tag)
            end
        end
    end
    
    return tostring(html)
end

return p