模块

装备:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
第1行: 第1行:
local p = {}
local p = {}
local equipmentData = mw.loadData('模块:装备/data')
local data = mw.loadData('模块:装备/data')


-- 辅助函数:解析文本格式
-- 获取装备稀有度对应的中文
local function parseText(text)
local rarityMap = {
     if not text then return "" end
     [""] = "蓝",
     -- 将 {{文本|橙|数值}} 格式转换为HTML
     ["紫"] = "紫",
     text = text:gsub("{{文本|橙|([^}]+)}}", '<span style="color:#ff9500">%1</span>')
     ["金"] = ""
    return text
}
end


-- 生成单个装备卡片
-- 生成装备卡片
function p.card(frame)
function p.card(frame)
     local args = frame.args
     local args = frame.args
第16行: 第15行:
     local level = args[2] or args.level or "1"
     local level = args[2] or args.level or "1"
      
      
     if not name or not equipmentData[name] then
     if not name or not data[name] then
         return "装备不存在"
         return "装备不存在: " .. (name or "未指定")
     end
     end
      
      
     local equip = equipmentData[name]
     local equip = data[name]
     local base = equip.base
     local base = equip.base
     local levelData = equip[level]
     local levelData = equip[level]
      
      
     if not levelData then
     if not levelData then
         return "等级数据不存在"
         return "装备等级不存在: " .. level
     end
     end
      
      
     -- 生成装备卡片HTML,添加data属性用于JavaScript识别
     -- 生成HTML
     local html = '<span class="equipment-card-wrapper" data-equipment-name="' .. mw.text.encode(name) .. '" data-equipment-level="' .. level .. '">'
     local html = mw.html.create('div')
    html = html .. '<div style="position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;">'
        :addClass('equipment-card')
    html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_' .. base.rarity .. '.png|150px|link=]]</div>'
        :attr('data-equipment', name)
    html = html .. '<div style="position: absolute; top: 43px; left: 13px;">[[File:' .. base.art .. '|124px|link=]]</div>'
        :attr('data-level', level)
    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>'
        :cssText('position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;')
    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>'
      
      
     -- 生成隐藏的弹窗数据
     -- 背景
     local desc = parseText(levelData.desc_global)
     html:tag('div')
    html = html .. '<div class="equipment-popup-data" style="display:none;">'
        :cssText('position: absolute; top: 0px; left: 0px;')
    html = html .. '<div data-rarity="' .. base.rarity .. '" '
        :wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', base.rarity))
    html = html .. 'data-art="' .. base.art .. '" '
    html = html .. 'data-level="' .. level .. '" '
    html = html .. 'data-type="' .. base.type .. '" '
    html = html .. 'data-name="' .. mw.text.encode(name) .. '" '
    html = html .. 'data-value-type="' .. mw.text.encode(base.value_type) .. '" '
    html = html .. 'data-value="' .. levelData.value .. '" '
    html = html .. 'data-desc="' .. mw.text.encode(desc) .. '">'
    html = html .. '</div></div>'
    html = html .. '</span>'
      
      
     return frame:preprocess(html)
    -- 装备图片
    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
end


-- 生成装备列表
-- 生成装备详情弹窗
function p.list(frame)
function p.popup(frame)
     local result = {}
     local args = frame.args
     for name, _ in pairs(equipmentData) do
     local name = args[1] or args.name
        local newFrame = {
    local level = args[2] or args.level or "1"
            args = {name = name, level = "1"},
   
            preprocess = frame.preprocess
    if not name or not data[name] then
        }
         return "装备不存在: " .. (name or "未指定")
         table.insert(result, p.card(newFrame))
     end
     end
     return table.concat(result, "\n")
      
    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
end


return p
return p

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

此模块的文档可以在模块:装备/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

return p