模块

装备:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
第154行: 第154行:
-- 主函数
-- 主函数
function p.show(frame)
function p.show(frame)
     local args = frame:getParent().args
    -- 直接使用 frame.args 而不是 getParent().args
     local args = frame.args
   
    -- 如果 frame.args 为空,尝试使用 getParent().args(用于模板调用)
    if not args[1] and not args.name then
        args = frame:getParent().args
    end
   
     local name = args[1] or args.name or ""
     local name = args[1] or args.name or ""
     local star = tonumber(args[2] or args.star or 1)
     local star = tonumber(args[2] or args.star or 1)
   
    -- 去除可能的空格
    name = mw.text.trim(name)
      
      
     if name == "" then
     if name == "" then
         return "错误: 未指定装备名称"
         return "错误: 未指定装备名称"
    end
   
    -- 检查装备是否存在
    if not equipment_data[name] then
        return "错误: 装备不存在 - " .. name
     end
     end
      
      

2025年10月17日 (五) 15:22的版本

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

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

-- 获取装备星级图标
local function getStarIcon(star)
    return "[[File:icon_star_rating_" .. star .. ".png|link=]]"
end

-- 生成装备卡片HTML
local function generateEquipmentCard(name, star)
    local equip = equipment_data[name]
    if not equip then
        return "装备不存在: " .. name
    end
    
    local base = equip.base
    local level = equip[star] or equip[1]
    
    local html = mw.html.create('div')
        :addClass('equipment-card')
        :attr('data-name', name)
        :attr('data-star', star)
        :css({
            position = 'relative',
            display = 'inline-block',
            width = '150px',
            height = '230px',
            cursor = 'pointer'
        })
    
    -- 背景
    html:tag('div')
        :css({position = 'absolute', top = '0px', left = '0px'})
        :wikitext('[[File:bg_equipment_rarity_' .. base.rarity .. '.png|150px|link=]]')
    
    -- 装备图片
    html:tag('div')
        :css({position = 'absolute', top = '43px', left = '13px'})
        :wikitext('[[File:' .. base.art .. '|124px|link=]]')
    
    -- 底部暗色遮罩
    html:tag('div')
        :css({
            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')
        :css({position = 'absolute', bottom = '10px', left = '20px'})
        :wikitext(getStarIcon(star))
    
    -- 顶层蒙版
    html:tag('div')
        :css({position = 'absolute', top = '0px', left = '0px'})
        :wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]')
    
    return tostring(html)
end

-- 生成装备弹窗HTML
local function generateEquipmentModal(name, star)
    local equip = equipment_data[name]
    if not equip then
        return ""
    end
    
    local base = equip.base
    local level = equip[star] or equip[1]
    
    local html = mw.html.create('div')
        :addClass('equipment-modal')
        :css({
            position = 'relative',
            display = 'inline-block',
            width = '368px',
            height = '335px',
            ['background-color'] = '#343434',
            ['border-radius'] = '9px'
        })
    
    -- 背景
    html:tag('div')
        :css({position = 'absolute', top = '0px', left = '0px'})
        :wikitext('[[File:bg_collection_rarity_' .. base.rarity .. '.png|link=]]')
    
    -- 装备图片
    html:tag('div')
        :css({position = 'absolute', top = '40px', left = '128px'})
        :wikitext('[[File:' .. base.art .. '|124px|link=]]')
    
    -- 分隔线遮罩
    html:tag('div')
        :css({
            position = 'absolute',
            top = '167px',
            left = '0px',
            width = '368px',
            height = '35px',
            ['background-color'] = 'rgba(0,0,0,0.5)',
            ['border-radius'] = '0px 0px 8px 8px'
        })
    
    -- 星级
    html:tag('div')
        :css({position = 'absolute', top = '173px', left = '128px'})
        :wikitext(getStarIcon(star))
    
    -- 装备类型图标
    html:tag('div')
        :css({position = 'absolute', top = '205px', left = '5px', color = 'white'})
        :wikitext('[[File:icon_equip_' .. base.type .. '_' .. base.rarity .. '.png|25px|link=]]')
    
    -- 装备名称
    html:tag('div')
        :css({position = 'absolute', top = '209px', left = '33px', color = 'white'})
        :wikitext(name)
    
    -- 属性背景
    html:tag('div')
        :css({
            position = 'absolute',
            top = '235px',
            left = '9px',
            width = '350px',
            height = '35px',
            ['background-color'] = 'rgba(255,255,255,0.3)',
            ['border-radius'] = '2px'
        })
    
    -- 属性类型
    html:tag('div')
        :css({position = 'absolute', top = '242px', left = '14px', color = 'white'})
        :wikitext(base.value_type)
    
    -- 属性值
    html:tag('div')
        :css({position = 'absolute', top = '242px', right = '14px', color = 'white'})
        :wikitext(level.value)
    
    -- 描述
    html:tag('div')
        :css({position = 'absolute', top = '277px', left = '10px', color = 'white'})
        :wikitext(level.desc_global)
    
    return tostring(html)
end

-- 主函数
function p.show(frame)
    -- 直接使用 frame.args 而不是 getParent().args
    local args = frame.args
    
    -- 如果 frame.args 为空,尝试使用 getParent().args(用于模板调用)
    if not args[1] and not args.name then
        args = frame:getParent().args
    end
    
    local name = args[1] or args.name or ""
    local star = tonumber(args[2] or args.star or 1)
    
    -- 去除可能的空格
    name = mw.text.trim(name)
    
    if name == "" then
        return "错误: 未指定装备名称"
    end
    
    -- 检查装备是否存在
    if not equipment_data[name] then
        return "错误: 装备不存在 - " .. name
    end
    
    local card = generateEquipmentCard(name, star)
    local modal = generateEquipmentModal(name, star)
    
    return card .. '<div class="equipment-modal-container" style="display:none;">' .. modal .. '</div>'
end

return p