模块

装备:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
第160行: 第160行:
end
end


-- 生成装备列表
-- 生成装备卡片列表(用于筛选页面)
function p.list(frame)
function p.generateCards(frame)
     local html = mw.html.create('table')
     local html = mw.html.create()
        :attr('id', 'CardSelectTr')
        :addClass('wikitable')
        :cssText('width: 100%;')
      
      
     -- 表头
     -- 遍历所有装备,生成5星卡片
     local headerRow = html:tag('thead'):tag('tr')
     for equipName, equipData in pairs(data) do
        :attr('id', 'CardSelectTabHeader')
        local base = equipData.base
   
        local level5 = equipData["5"]
    headerRow:tag('th'):wikitext('装备')
       
    headerRow:tag('th'):wikitext('稀有度')
        if level5 then  -- 只显示有5星的装备
    headerRow:tag('th'):wikitext('区域')  
            -- 创建可筛选的卡片容器
    headerRow:tag('th'):wikitext('类型')
            local cardWrapper = html:tag('div')
    headerRow:tag('th'):wikitext('属性')
                :addClass('divsort')
    headerRow:tag('th'):wikitext('TAG')
                :attr('data-param1', rarityMap[base.rarity] or base.rarity)  -- 稀有度
   
                :attr('data-param2', base.area) -- 区域
    -- 表体
                :attr('data-param3', base.tag) -- TAG(多个用逗号分隔)
    local tbody = html:tag('tbody')
                :cssText('display: inline-block; margin: 5px;')
   
           
    -- 遍历所有装备
            -- 生成卡片内容
    for name, equipData in pairs(data) do
            local cardDiv = cardWrapper:tag('div')
        if equipData.base then
                :addClass('equipment-card')
             -- 默认显示5星装备
                :attr('data-equipment', equipName)
             local level = "5"
                :attr('data-level', '5')
            local levelData = equipData[level]
                :cssText('position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;')
           
            -- 背景
            cardDiv:tag('div')
                :cssText('position: absolute; top: 0px; left: 0px;')
                :wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', base.rarity))
           
            -- 装备图片
            cardDiv:tag('div')
                :cssText('position: absolute; top: 43px; left: 13px;')
                :wikitext(string.format('[[File:%s|124px|link=]]', base.art))
           
            -- 底部背景
            cardDiv: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')
           
             -- 星级
             cardDiv:tag('div')
                :cssText('position: absolute; bottom: 10px; left: 20px;')
                :wikitext('[[File:icon_star_rating_5.png|link=]]')
              
              
             if levelData then
             -- 顶层蒙版
                local row = tbody:tag('tr')
            cardDiv:tag('div')
                    :attr('data-param1', equipData.base.rarity)
                :cssText('position: absolute; top: 0px; left: 0px;')
                    :attr('data-param2', equipData.base.area)
                :wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]')
                    :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
     end
     end

2025年10月17日 (五) 16:49的版本

此模块的文档可以在模块:装备/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.generateCards(frame)
    local html = mw.html.create()
    
    -- 遍历所有装备,生成5星卡片
    for equipName, equipData in pairs(data) do
        local base = equipData.base
        local level5 = equipData["5"]
        
        if level5 then  -- 只显示有5星的装备
            -- 创建可筛选的卡片容器
            local cardWrapper = html:tag('div')
                :addClass('divsort')
                :attr('data-param1', rarityMap[base.rarity] or base.rarity)  -- 稀有度
                :attr('data-param2', base.area)  -- 区域
                :attr('data-param3', base.tag)  -- TAG(多个用逗号分隔)
                :cssText('display: inline-block; margin: 5px;')
            
            -- 生成卡片内容
            local cardDiv = cardWrapper:tag('div')
                :addClass('equipment-card')
                :attr('data-equipment', equipName)
                :attr('data-level', '5')
                :cssText('position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;')
            
            -- 背景
            cardDiv:tag('div')
                :cssText('position: absolute; top: 0px; left: 0px;')
                :wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', base.rarity))
            
            -- 装备图片
            cardDiv:tag('div')
                :cssText('position: absolute; top: 43px; left: 13px;')
                :wikitext(string.format('[[File:%s|124px|link=]]', base.art))
            
            -- 底部背景
            cardDiv: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')
            
            -- 星级
            cardDiv:tag('div')
                :cssText('position: absolute; bottom: 10px; left: 20px;')
                :wikitext('[[File:icon_star_rating_5.png|link=]]')
            
            -- 顶层蒙版
            cardDiv:tag('div')
                :cssText('position: absolute; top: 0px; left: 0px;')
                :wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]')
        end
    end
    
    return tostring(html)
end

return p