模块

装备:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
第28行: 第28行:
     end
     end
      
      
     -- 生成装备卡片HTML
     -- 生成装备卡片HTML,添加data属性用于JavaScript识别
     local html = '<div class="equipment-card" style="position: relative; display: inline-block; width:150px; height: 230px;" data-equipment="' .. name .. '" data-level="' .. level .. '">'
     local html = '<span class="equipment-card-wrapper" data-equipment-name="' .. mw.text.encode(name) .. '" data-equipment-level="' .. level .. '">'
    html = html .. '<div style="position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;">'
     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: 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; top: 43px; left: 13px;">[[File:' .. base.art .. '|124px|link=]]</div>'
第37行: 第38行:
     html = html .. '</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 desc = parseText(levelData.desc_global)
     local encodedName = mw.uri.encode(name)
     html = html .. '<div class="equipment-popup-data" style="display:none;">'
   
     html = html .. '<div data-rarity="' .. base.rarity .. '" '
    -- 生成弹窗HTML
     html = html .. 'data-art="' .. base.art .. '" '
    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 .. 'data-level="' .. level .. '" '
     html = html .. '<div style="position: relative; display: inline-block; width:368px; height: 335px; background-color: #343434; border-radius: 9px">'
     html = html .. 'data-type="' .. base.type .. '" '
    html = html .. '<div style="position: absolute; top: 0px; left: 0px;">[[File:bg_collection_rarity_' .. base.rarity .. '.png|link=]]</div>'
     html = html .. 'data-name="' .. mw.text.encode(name) .. '" '
     html = html .. '<div style="position: absolute; top: 40px; left: 128px;">[[File:' .. base.art .. '|124px|link=]]</div>'
     html = html .. 'data-value-type="' .. mw.text.encode(base.value_type) .. '" '
     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 .. 'data-value="' .. levelData.value .. '" '
    html = html .. '<div style="position: absolute; top: 173px; left: 128px;">[[File:icon_star_rating_' .. level .. '.png|link=]]</div>'
     html = html .. 'data-desc="' .. mw.text.encode(desc) .. '">'
     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>'
     html = html .. '</div></div>'
    html = html .. '</span>'
      
      
     return frame:preprocess(html)
     return frame:preprocess(html)
end
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)
function p.list(frame)
     local result = {}
     local result = {}
     for name, _ in pairs(equipmentData) do
     for name, _ in pairs(equipmentData) do
        -- 创建一个新的frame对象用于传递参数
         local newFrame = {
         local newFrame = {
             args = {name = name, level = "1"},
             args = {name = name, level = "1"},
             preprocess = frame.preprocess
             preprocess = frame.preprocess
         }
         }
         table.insert(result, p.show(newFrame))
         table.insert(result, p.card(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
     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")
     return table.concat(result, "\n")
end
end


return p
return p

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

此模块的文档可以在模块:装备/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,添加data属性用于JavaScript识别
    local html = '<span class="equipment-card-wrapper" data-equipment-name="' .. mw.text.encode(name) .. '" data-equipment-level="' .. level .. '">'
    html = html .. '<div style="position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;">'
    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>'
    
    -- 生成隐藏的弹窗数据
    local desc = parseText(levelData.desc_global)
    html = html .. '<div class="equipment-popup-data" style="display:none;">'
    html = html .. '<div data-rarity="' .. base.rarity .. '" '
    html = html .. 'data-art="' .. base.art .. '" '
    html = html .. 'data-level="' .. level .. '" '
    html = html .. 'data-type="' .. base.type .. '" '
    html = html .. 'data-name="' .. mw.text.encode(name) .. '" '
    html = html .. 'data-value-type="' .. mw.text.encode(base.value_type) .. '" '
    html = html .. 'data-value="' .. levelData.value .. '" '
    html = html .. 'data-desc="' .. mw.text.encode(desc) .. '">'
    html = html .. '</div></div>'
    html = html .. '</span>'
    
    return frame:preprocess(html)
end

-- 生成装备列表
function p.list(frame)
    local result = {}
    for name, _ in pairs(equipmentData) do
        local newFrame = {
            args = {name = name, level = "1"},
            preprocess = frame.preprocess
        }
        table.insert(result, p.card(newFrame))
    end
    return table.concat(result, "\n")
end

return p