模块

模块:装备

来自卡厄思梦境WIKI

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

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

local Equipment = {}

-- 从数据模块加载装备数据
local equipmentData = require("模块:装备/data")

-- 生成装备显示HTML
function Equipment.renderEquipment(equipName, level)
    level = level or "1"  -- 默认等级为1
    
    local equip = equipmentData[equipName]
    if not equip then
        return "<div class='error'>找不到装备:" .. equipName .. "</div>"
    end
    
    local base = equip.base
    local levelData = equip[level]
    
    if not levelData then
        return "<div class='error'>找不到装备等级:" .. level .. "</div>"
    end
    
    -- 生成装备卡片HTML
    local html = [=[
<div class="equipment-card" data-equip-name="]=] .. equipName .. [=[" data-equip-level="]=] .. level .. [=[" style="position: relative; display: inline-block; width:150px; height: 230px;">
  <div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_]=] .. base.rarity .. [=[.png|150px|link=]]</div>
  <div style="position: absolute; top: 43px; left: 13px;">[[File:]=] .. base.art .. [=[|124px|link=]]</div>
  <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>
  <div style="position: absolute; bottom: 10px; left: 20px; ">[[File:icon_star_rating_]=] .. level .. [=[.png|link=]]</div>
  <div style="position: absolute; top: 0px; left: 0px;">[[File:equipment_顶层蒙版.png|150px|link=]]</div>
</div>
]=]

    return html
end

-- 生成装备详情弹窗HTML
function Equipment.renderEquipmentDetail(equipName, level)
    level = level or "1"  -- 默认等级为1
    
    local equip = equipmentData[equipName]
    if not equip then
        return "<div class='error'>找不到装备:" .. equipName .. "</div>"
    end
    
    local base = equip.base
    local levelData = equip[level]
    
    if not levelData then
        return "<div class='error'>找不到装备等级:" .. level .. "</div>"
    end
    
    -- 生成装备详情弹窗HTML
    local html = [=[
<div class="equipment-detail" style="position: relative; display: inline-block; width:368px; height: 335px; background-color: #343434; border-radius: 9px">
  <div style="position: absolute; top: 0px; left: 0px;">[[File:bg_collection_rarity_]=] .. base.rarity .. [=[.png|link=]]</div>
  <div style="position: absolute; top: 40px; left: 128px;">[[File:]=] .. base.art .. [=[|124px|link=]]</div>
  <div style="position: absolute; top: 167px; left: 0px; width: 368px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px"></div>
  <div style="position: absolute; top: 173px; left: 128px; ">[[File:icon_star_rating_]=] .. level .. [=[.png|link=]]</div>
  <div style="position: absolute; top: 205px; left: 5px; color: white">[[File:icon_equip_]=] .. base.type .. [=[_]=] .. base.rarity .. [=[.png|25px|link=]]</div>
  <div style="position: absolute; top: 209px; left: 33px; color: white">]=] .. equipName .. [=[</div>
  <div style="position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px"></div>
  <div style="position: absolute; top: 242px; left: 14px; color: white">]=] .. base.value_type .. [=[</div>
  <div style="position: absolute; top: 242px; right: 14px; color: white">]=] .. levelData.value .. [=[</div>
  <div style="position: absolute; top: 277px; left: 10px; color: white">]=] .. levelData.desc_global .. [=[</div>
</div>
]=]

    return html
end

-- 生成装备列表
function Equipment.renderEquipmentList(filter)
    filter = filter or {}
    local html = "<div class='equipment-list'>"
    
    for equipName, equipData in pairs(equipmentData) do
        -- 应用筛选条件
        local shouldShow = true
        if filter.rarity and equipData.base.rarity ~= filter.rarity then
            shouldShow = false
        end
        if filter.type and equipData.base.type ~= filter.type then
            shouldShow = false
        end
        if filter.area and equipData.base.area ~= filter.area then
            shouldShow = false
        end
        
        if shouldShow then
            html = html .. Equipment.renderEquipment(equipName, "1") -- 默认显示1级
        end
    end
    
    html = html .. "</div>"
    return html
end

-- 列出所有可用的装备名称
function Equipment.listEquipmentNames()
    local names = {}
    for equipName, _ in pairs(equipmentData) do
        table.insert(names, equipName)
    end
    return names
end

-- 获取装备数据(供其他模块使用)
function Equipment.getEquipmentData(equipName, level)
    level = level or "1"  -- 默认等级为1
    
    local equip = equipmentData[equipName]
    if not equip then
        return nil
    end
    
    local levelData = equip[level]
    if not levelData then
        return nil
    end
    
    -- 返回装备基本数据和指定等级的数据
    return {
        base = equip.base,
        level = levelData,
        name = equipName,
        level_num = level
    }
end

return Equipment