模块

模块:装备

来自卡厄思梦境WIKI

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

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

local p = {}

-- 调试函数
function p.debug(frame)
    local args = frame:getParent().args
    local result = "调试信息:\n"
    
    for k, v in pairs(args) do
        result = result .. "key [" .. tostring(k) .. "] = [" .. tostring(v) .. "]\n"
    end
    
    return "<pre>" .. result .. "</pre>"
end

-- 主函数
function p.show(frame)
    -- 直接使用 frame.args 而不是 frame:getParent().args
    local args = frame.args
    
    -- 如果 frame.args 为空,则尝试 getParent
    if not next(args) then
        args = frame:getParent().args
    end
    
    local name = args[1] or args['name']
    local level = args[2] or args['level'] or "1"
    
    -- 去除空白
    if name then
        name = mw.text.trim(name)
    end
    if level then
        level = mw.text.trim(level)
    end
    
    if not name or name == "" then
        return "错误:未指定装备名称 (请先使用 {{#invoke:装备|debug|窃取者的短刀|1}} 调试)"
    end
    
    local data = mw.loadData("模块:装备/data")
    local equipData = data[name]
    
    if not equipData then
        return "错误:未找到装备 [" .. name .. "]"
    end
    
    local base = equipData.base
    local levelData = equipData[level]
    
    if not levelData then
        return "错误:未找到等级数据 " .. level
    end
    
    local rarity = base.rarity
    local art = base.art
    local value_type = base.value_type
    local value = levelData.value
    local desc = levelData.desc_global
    
    -- 生成卡片HTML
    local html = mw.html.create('div')
        :attr('class', 'equipment-card')
        :css('position', 'relative')
        :css('display', 'inline-block')
        :css('width', '150px')
        :css('height', '230px')
        :css('cursor', 'pointer')
        
    html:tag('div')
        :css('position', 'absolute')
        :css('top', '0px')
        :css('left', '0px')
        :wikitext('[[File:bg_equipment_rarity_' .. rarity .. '.png|150px|link=]]')
    
    html:tag('div')
        :css('position', 'absolute')
        :css('top', '43px')
        :css('left', '13px')
        :wikitext('[[File:' .. art .. '|124px|link=]]')
    
    html:tag('div')
        :css('position', 'absolute')
        :css('bottom', '5px')
        :css('left', '5px')
        :css('width', '140px')
        :css('height', '35px')
        :css('background-color', 'rgba(0,0,0,0.5)')
        :css('border-radius', '0px 0px 8px 8px')
    
    html:tag('div')
        :css('position', 'absolute')
        :css('bottom', '10px')
        :css('left', '20px')
        :wikitext('[[File:icon_star_rating_' .. level .. '.png|link=]]')
    
    html:tag('div')
        :css('position', 'absolute')
        :css('top', '0px')
        :css('left', '0px')
        :wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]')
    
    -- 生成弹窗HTML
    local popup = mw.html.create('div')
        :attr('class', 'equipment-popup')
        :css('display', 'none')
        :css('position', 'fixed')
        :css('top', '50%')
        :css('left', '50%')
        :css('transform', 'translate(-50%, -50%)')
        :css('z-index', '1000')
        :css('width', '368px')
        :css('height', '335px')
        :css('background-color', '#343434')
        :css('border-radius', '9px')
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '0px')
        :css('left', '0px')
        :wikitext('[[File:bg_collection_rarity_' .. rarity .. '.png|link=]]')
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '40px')
        :css('left', '128px')
        :wikitext('[[File:' .. art .. '|124px|link=]]')
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '167px')
        :css('left', '0px')
        :css('width', '368px')
        :css('height', '35px')
        :css('background-color', 'rgba(0,0,0,0.5)')
        :css('border-radius', '0px 0px 8px 8px')
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '173px')
        :css('left', '128px')
        :wikitext('[[File:icon_star_rating_' .. level .. '.png|link=]]')
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '205px')
        :css('left', '5px')
        :css('color', 'white')
        :wikitext('[[File:icon_equip_' .. base.type .. '_' .. rarity .. '.png|25px|link=]]')
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '209px')
        :css('left', '33px')
        :css('color', 'white')
        :wikitext(name)
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '235px')
        :css('left', '9px')
        :css('width', '350px')
        :css('height', '35px')
        :css('background-color', 'rgba(255,255,255,0.3)')
        :css('border-radius', '2px')
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '242px')
        :css('left', '14px')
        :css('color', 'white')
        :wikitext(value_type)
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '242px')
        :css('right', '14px')
        :css('color', 'white')
        :wikitext(tostring(value))
    
    popup:tag('div')
        :css('position', 'absolute')
        :css('top', '277px')
        :css('left', '10px')
        :css('right', '10px')
        :css('color', 'white')
        :css('font-size', '13px')
        :css('line-height', '1.3')
        :wikitext(desc)
    
    popup:tag('div')
        :attr('class', 'equipment-popup-close')
        :css('position', 'absolute')
        :css('top', '5px')
        :css('right', '10px')
        :css('color', 'white')
        :css('font-size', '20px')
        :css('cursor', 'pointer')
        :wikitext('×')
    
    local container = mw.html.create('div')
        :css('display', 'inline-block')
        :node(html)
        :node(popup)
    
    return tostring(container)
end

return p