模块

装备:修订间差异

来自卡厄思梦境WIKI

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


function equipment.show(frame)
-- 辅助函数:解析文本格式
local function parseText(text)
    if not text then return "" end
    -- 将 {{文本|橙|数值}} 格式转换为HTML
    text = text:gsub("{{文本|橙|([^}]+)}}", '<span style="color:#ff9500">%1</span>')
    return text
end
 
-- 生成单个装备卡片
function p.card(frame)
     local args = frame.args
     local args = frame.args
     local name = args[1] or args.name
     local name = args[1] or args.name
     local star = tonumber(args[2] or args.star or 1)
     local level = args[2] or args.level or "1"
   
    if not name or not equipmentData[name] then
        return "装备不存在"
    end
   
    local equip = equipmentData[name]
    local base = equip.base
    local levelData = equip[level]
   
    if not levelData then
        return "等级数据不存在"
    end
   
    -- 生成装备卡片HTML
    local html = '<div class="equipment-card" style="position: relative; display: inline-block; width:150px; height: 230px;" data-equipment="' .. name .. '" data-level="' .. level .. '">'
    html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_' .. base.rarity .. '.png|150px|link=]]</div>'
    html = html .. '<div style="position: absolute; top: 43px; left: 13px;">[[File:' .. base.art .. '|124px|link=]]</div>'
    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>'
    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>'
   
    return frame:preprocess(html)
end


     if not name then return '<span style="color:red">未指定装备名</span>' end
-- 生成装备详情弹窗
     local eq = data[name]
function p.popup(frame)
     if not eq then return '<span style="color:red">装备「' .. name .. '」不存在</span>' end
    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 equipmentData[name] then
        return "装备不存在"
    end
   
    local equip = equipmentData[name]
    local base = equip.base
    local levelData = equip[level]
   
    if not levelData then
        return "等级数据不存在"
    end
   
    local desc = parseText(levelData.desc_global)
    local encodedName = mw.uri.encode(name)
   
    -- 生成弹窗HTML
    local html = '<div class="equipment-popup" id="popup-' .. encodedName .. '-' .. level .. '" style="display:none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">'
    html = html .. '<div style="position: relative; display: inline-block; width:368px; height: 335px; background-color: #343434; border-radius: 9px">'
    html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_collection_rarity_' .. base.rarity .. '.png|link=]]</div>'
    html = html .. '<div style="position: absolute; top: 40px; left: 128px;">[[File:' .. base.art .. '|124px|link=]]</div>'
    html = html .. '<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>'
    html = html .. '<div style="position: absolute; top: 173px; left: 128px;">[[File:icon_star_rating_' .. level .. '.png|link=]]</div>'
     html = html .. '<div style="position: absolute; top: 205px; left: 5px; color: white">[[File:icon_equip_' .. base.type .. '_' .. base.rarity .. '.png|25px|link=]]</div>'
     html = html .. '<div style="position: absolute; top: 209px; left: 33px; color: white">' .. name .. '</div>'
    html = html .. '<div style="position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px"></div>'
    html = html .. '<div style="position: absolute; top: 242px; left: 14px; color: white">' .. base.value_type .. '</div>'
    html = html .. '<div style="position: absolute; top: 242px; right: 14px; color: white">' .. tostring(levelData.value) .. '</div>'
    html = html .. '<div style="position: absolute; top: 277px; left: 10px; right: 10px; color: white">' .. desc .. '</div>'
    html = html .. '</div></div>'
   
    return frame:preprocess(html)
end


     local base = eq.base
-- 生成装备卡片和弹窗的组合
     local level = eq[tostring(star)] or eq["1"]
function p.show(frame)
     if not level then star = 1; level = eq["1"] end
    local args = frame.args
     local name = args[1] or args.name
     local level = args[2] or args.level or "1"
      
    local card = p.card(frame)
    local popup = p.popup(frame)
   
    return card .. popup
end


     local art = base.art or "relic_placeholder.png"
-- 批量显示装备
     local rarity = base.rarity or ""
function p.list(frame)
    local type_icon = "icon_equip_" .. (base.type or "武器") .. "_" .. rarity .. ".png"
     local result = {}
     local value_type = base.value_type or "属性"
     for name, _ in pairs(equipmentData) do
     local value = level.value or 0
        -- 创建一个新的frame对象用于传递参数
    local desc = level.desc_global or ""
        local newFrame = {
            args = {name = name, level = "1"},
            preprocess = frame.preprocess
        }
        table.insert(result, p.show(newFrame))
     end
     return table.concat(result, "\n")
end


    -- 星级图片
-- 显示指定区域的装备
     local star_img = "icon_star_rating_" .. star .. ".png"
function p.areaList(frame)
    local args = frame.args
     local area = args[1] or args.area
   
    if not area then
        return "请指定区域"
    end
   
    local result = {}
    for name, equip in pairs(equipmentData) do
        if equip.base.area == area then
            local newFrame = {
                args = {name = name, level = "1"},
                preprocess = frame.preprocess
            }
            table.insert(result, p.show(newFrame))
        end
    end
   
    if #result == 0 then
        return "该区域没有装备"
    end
   
    return table.concat(result, "\n")
end


    -- >>> 主卡片HTML + 弹窗HTML 一起输出 <<<
-- 显示指定稀有度的装备
     local html = [=[
function p.rarityList(frame)
<div class="equipment-wrapper" style="display: inline-block; position: relative;">
     local args = frame.args
     <!-- 小卡片 -->
     local rarity = args[1] or args.rarity
    <div class="equipment-card" style="position: relative; width:150px; height:230px; cursor: pointer;" onclick="openEquipPopup(this)">
   
        <div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_]=] .. rarity .. [=[.png|150px|link=]]</div>
    if not rarity then
        <div style="position: absolute; top: 43px; left: 13px;">[[File:]=] .. art .. [=[|124px|link=]]</div>
         return "请指定稀有度"
        <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>
    end
         <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>
     local result = {}
     </div>
     for name, equip in pairs(equipmentData) do
 
         if equip.base.rarity == rarity then
     <!-- 弹窗(默认隐藏) -->
            local newFrame = {
     <div class="equipment-popup" style="display:none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9999; width:368px; height:335px; background-color:#343434; border-radius:9px; padding:0; box-shadow:0 0 20px rgba(0,0,0,0.8);">
                args = {name = name, level = "1"},
        <div style="position: absolute; top: 8px; right: 12px; color:white; font-size:20px; font-weight:bold; cursor:pointer;" onclick="closeEquipPopup(this)">×</div>
                preprocess = frame.preprocess
         <div style="position: absolute; top: 0px; left: 0px;">[[File:bg_collection_rarity_]=] .. rarity .. [=[.png|link=]]</div>
            }
        <div style="position: absolute; top: 40px; left: 128px;">[[File:]=] .. art .. [=[|124px|link=]]</div>
            table.insert(result, p.show(newFrame))
        <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>
         end
        <div style="position: absolute; top: 173px; left: 128px;">[[File:]=] .. star_img .. [=[|link=]]</div>
    end
        <div style="position: absolute; top: 205px; left: 5px; color: white;">[[File:]=] .. type_icon .. [=[|25px|link=]]</div>
   
        <div style="position: absolute; top: 209px; left: 33px; color: white; font-weight:bold;">]=] .. name .. [=[</div>
    if #result == 0 then
        <div style="position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px"></div>
         return "该稀有度没有装备"
         <div style="position: absolute; top: 242px; left: 14px; color: white; font-size:14px;">]=] .. value_type .. [=[</div>
     end
        <div style="position: absolute; top: 242px; right: 14px; color: white; font-size:14px; font-weight:bold;">]=] .. value .. [=[</div>
      
         <div style="position: absolute; top: 277px; left: 10px; width: 348px; color: white; font-size:13px; line-height:1.4; word-wrap:break-word;">]=] .. desc .. [=[</div>
     return table.concat(result, "\n")
     </div>
 
     <!-- 遮罩层 -->
     <div class="equipment-overlay" style="display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.7); z-index:9998;" onclick="closeEquipPopup(this)"></div>
</div>
]=]
 
    return html
end
end


equipment.main = equipment.show
return p
 
return equipment

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

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

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

-- 辅助函数:解析文本格式
local function parseText(text)
    if not text then return "" end
    -- 将 {{文本|橙|数值}} 格式转换为HTML
    text = text:gsub("{{文本|橙|([^}]+)}}", '<span style="color:#ff9500">%1</span>')
    return text
end

-- 生成单个装备卡片
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 equipmentData[name] then
        return "装备不存在"
    end
    
    local equip = equipmentData[name]
    local base = equip.base
    local levelData = equip[level]
    
    if not levelData then
        return "等级数据不存在"
    end
    
    -- 生成装备卡片HTML
    local html = '<div class="equipment-card" style="position: relative; display: inline-block; width:150px; height: 230px;" data-equipment="' .. name .. '" data-level="' .. level .. '">'
    html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_equipment_rarity_' .. base.rarity .. '.png|150px|link=]]</div>'
    html = html .. '<div style="position: absolute; top: 43px; left: 13px;">[[File:' .. base.art .. '|124px|link=]]</div>'
    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>'
    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>'
    
    return frame:preprocess(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 equipmentData[name] then
        return "装备不存在"
    end
    
    local equip = equipmentData[name]
    local base = equip.base
    local levelData = equip[level]
    
    if not levelData then
        return "等级数据不存在"
    end
    
    local desc = parseText(levelData.desc_global)
    local encodedName = mw.uri.encode(name)
    
    -- 生成弹窗HTML
    local html = '<div class="equipment-popup" id="popup-' .. encodedName .. '-' .. level .. '" style="display:none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">'
    html = html .. '<div style="position: relative; display: inline-block; width:368px; height: 335px; background-color: #343434; border-radius: 9px">'
    html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_collection_rarity_' .. base.rarity .. '.png|link=]]</div>'
    html = html .. '<div style="position: absolute; top: 40px; left: 128px;">[[File:' .. base.art .. '|124px|link=]]</div>'
    html = html .. '<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>'
    html = html .. '<div style="position: absolute; top: 173px; left: 128px;">[[File:icon_star_rating_' .. level .. '.png|link=]]</div>'
    html = html .. '<div style="position: absolute; top: 205px; left: 5px; color: white">[[File:icon_equip_' .. base.type .. '_' .. base.rarity .. '.png|25px|link=]]</div>'
    html = html .. '<div style="position: absolute; top: 209px; left: 33px; color: white">' .. name .. '</div>'
    html = html .. '<div style="position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px"></div>'
    html = html .. '<div style="position: absolute; top: 242px; left: 14px; color: white">' .. base.value_type .. '</div>'
    html = html .. '<div style="position: absolute; top: 242px; right: 14px; color: white">' .. tostring(levelData.value) .. '</div>'
    html = html .. '<div style="position: absolute; top: 277px; left: 10px; right: 10px; color: white">' .. desc .. '</div>'
    html = html .. '</div></div>'
    
    return frame:preprocess(html)
end

-- 生成装备卡片和弹窗的组合
function p.show(frame)
    local args = frame.args
    local name = args[1] or args.name
    local level = args[2] or args.level or "1"
    
    local card = p.card(frame)
    local popup = p.popup(frame)
    
    return card .. popup
end

-- 批量显示装备
function p.list(frame)
    local result = {}
    for name, _ in pairs(equipmentData) do
        -- 创建一个新的frame对象用于传递参数
        local newFrame = {
            args = {name = name, level = "1"},
            preprocess = frame.preprocess
        }
        table.insert(result, p.show(newFrame))
    end
    return table.concat(result, "\n")
end

-- 显示指定区域的装备
function p.areaList(frame)
    local args = frame.args
    local area = args[1] or args.area
    
    if not area then
        return "请指定区域"
    end
    
    local result = {}
    for name, equip in pairs(equipmentData) do
        if equip.base.area == area then
            local newFrame = {
                args = {name = name, level = "1"},
                preprocess = frame.preprocess
            }
            table.insert(result, p.show(newFrame))
        end
    end
    
    if #result == 0 then
        return "该区域没有装备"
    end
    
    return table.concat(result, "\n")
end

-- 显示指定稀有度的装备
function p.rarityList(frame)
    local args = frame.args
    local rarity = args[1] or args.rarity
    
    if not rarity then
        return "请指定稀有度"
    end
    
    local result = {}
    for name, equip in pairs(equipmentData) do
        if equip.base.rarity == rarity then
            local newFrame = {
                args = {name = name, level = "1"},
                preprocess = frame.preprocess
            }
            table.insert(result, p.show(newFrame))
        end
    end
    
    if #result == 0 then
        return "该稀有度没有装备"
    end
    
    return table.concat(result, "\n")
end

return p