模块

装备:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
第1行: 第1行:
local Equipment = {}
local equipment = {}
local data = mw.loadData('Module:装备/data') -- 从数据模块加载


-- 从数据模块加载装备数据
-- 主函数,接收参数:装备名, 星级(默认1)
local equipmentData = require("模块:装备/data")
function equipment.show(frame)
 
     local args = frame.args
-- 生成装备显示HTML
     local name = args[1] or args.name
function Equipment.renderEquipment(equipName, level)
    local star = tonumber(args[2] or args.star or 1)
     -- 检查参数类型
     if type(equipName) ~= "string" then
        return "<div class='error'>装备名称必须是字符串</div>"
    end
      
      
     level = level or "1" -- 默认等级为1
     if not name then return '<span style="color:red">未指定装备名</span>' end
     if type(level) ~= "string" then
    local eq = data[name]
        level = tostring(level)
     if not eq then return '<span style="color:red">装备「' .. name .. '」不存在</span>' end
    end
      
      
     local equip = equipmentData[equipName]
     local base = eq.base
     if not equip then
    local level = eq[tostring(star)] or eq["1"]
        return "<div class='error'>找不到装备:" .. equipName .. "</div>"
     if not level then star = 1; level = eq["1"] end
    end
      
      
     local base = equip.base
     local art = base.art or "relic_placeholder.png"
     local levelData = equip[level]
    local rarity = base.rarity or "蓝"
    local type_icon = "icon_equip_" .. (base.type or "武器") .. "_" .. rarity .. ".png"
    local value_type = base.value_type or "属性"
    local value = level.value or 0
     local desc = level.desc_global or ""
      
      
     if not levelData then
     -- 生成星级图标(1~5星)
        return "<div class='error'>找不到装备等级:" .. level .. "</div>"
    local star_img = "icon_star_rating_" .. star .. ".png"
    end
      
      
     -- 生成装备卡片HTML
     -- 主卡片HTML(点击触发弹窗)
     local 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 class="equipment-card" data-equip-name="]=] .. mw.text.encode(name) .. [=[" data-star="]=] .. star .. [=[">
  <div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_]=] .. base.rarity .. [=[.png|150px|link=]]</div>
    <div style="position: relative; display: inline-block; width:150px; height: 230px;">
  <div style="position: absolute; top: 43px; left: 13px;">[[File:]=] .. base.art .. [=[|124px|link=]]</div>
        <div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_]=] .. rarity .. [=[.png|150px|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; top: 43px; left: 13px;">[[File:]=] .. art .. [=[|124px|link=]]</div>
  <div style="position: absolute; bottom: 10px; left: 20px; ">[[File:icon_star_rating_]=] .. level .. [=[.png|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; top: 0px; left: 0px;">[[File:equipment_顶层蒙版.png|150px|link=]]</div>
        <div style="position: absolute; bottom: 10px; left: 20px;">[[File:]=] .. star_img .. [=[|link=]]</div>
        <div style="position: absolute; top: 0px; left: 0px;">[[File:equipment_顶层蒙版.png|150px|link=]]</div>
    </div>
</div>
</div>
]=]
]=]
    return html
end
-- 生成装备详情弹窗HTML
function Equipment.renderEquipmentDetail(equipName, level)
    -- 检查参数类型
    if type(equipName) ~= "string" then
        return "<div class='error'>装备名称必须是字符串</div>"
    end
      
      
    level = level or "1"  -- 默认等级为1
    if type(level) ~= "string" then
        level = tostring(level)
    end
   
    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
     return html
end
end


-- 生成装备列表
equipment.main = equipment.show -- 兼容 #invoke:装备
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)
    -- 检查参数类型
    if type(equipName) ~= "string" then
        return nil
    end
   
    level = level or "1"  -- 默认等级为1
    if type(level) ~= "string" then
        level = tostring(level)
    end
   
    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
return equipment

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

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

local equipment = {}
local data = mw.loadData('Module:装备/data') -- 从数据模块加载

-- 主函数,接收参数:装备名, 星级(默认1)
function equipment.show(frame)
    local args = frame.args
    local name = args[1] or args.name
    local star = tonumber(args[2] or args.star or 1)
    
    if not name then return '<span style="color:red">未指定装备名</span>' end
    local eq = data[name]
    if not eq then return '<span style="color:red">装备「' .. name .. '」不存在</span>' end
    
    local base = eq.base
    local level = eq[tostring(star)] or eq["1"]
    if not level then star = 1; level = eq["1"] end
    
    local art = base.art or "relic_placeholder.png"
    local rarity = base.rarity or "蓝"
    local type_icon = "icon_equip_" .. (base.type or "武器") .. "_" .. rarity .. ".png"
    local value_type = base.value_type or "属性"
    local value = level.value or 0
    local desc = level.desc_global or ""
    
    -- 生成星级图标(1~5星)
    local star_img = "icon_star_rating_" .. star .. ".png"
    
    -- 主卡片HTML(点击触发弹窗)
    local html = [=[
<div class="equipment-card" data-equip-name="]=] .. mw.text.encode(name) .. [=[" data-star="]=] .. star .. [=[">
    <div style="position: relative; display: inline-block; width:150px; height: 230px;">
        <div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_]=] .. rarity .. [=[.png|150px|link=]]</div>
        <div style="position: absolute; top: 43px; left: 13px;">[[File:]=] .. 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:]=] .. star_img .. [=[|link=]]</div>
        <div style="position: absolute; top: 0px; left: 0px;">[[File:equipment_顶层蒙版.png|150px|link=]]</div>
    </div>
</div>
]=]
    
    return html
end

equipment.main = equipment.show -- 兼容 #invoke:装备

return equipment