模块

战斗员图鉴:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
创建页面,内容为“local p = {} -- 根据稀有度获取对应的CSS类 local function getRarityClass(rarity) return "rarity-" .. (rarity or "1") end -- 根据职业名称获取图标文件名 local function getProfessionIcon(profession) if not profession or profession == "" then return "" end return "icon_职业_" .. profession .. ".png" end -- 根据属性名称获取图标文件名 local function getAttributeIcon(attribute) if not attribute or at…”
 
律Rhyme留言 | 贡献
无编辑摘要
第1行: 第1行:
local p = {}
local p = {}


-- 根据稀有度获取对应的CSS类
-- 获取所有战斗员模块的函数
local function getRarityClass(rarity)
function p.getAllCharacters()
    -- 这里需要手动维护角色列表,因为MediaWiki无法直接枚举所有模块
    -- 你需要在添加新角色时更新这个列表
    local characters = {
        "蕾欧娜",
        -- 在这里添加其他角色名称
    }
    return characters
end
 
-- 安全地加载角色数据
function p.loadCharacterData(characterName)
    local success, characterModule = pcall(require, "模块:战斗员/" .. characterName)
    if success and characterModule and characterModule.data then
        return characterModule.data
    else
        return nil
    end
end
 
-- 获取稀有度对应的CSS类
function p.getRarityClass(rarity)
     return "rarity-" .. (rarity or "1")
     return "rarity-" .. (rarity or "1")
end
end


-- 根据职业名称获取图标文件名
-- 获取职业图标文件名
local function getProfessionIcon(profession)
function p.getJobIcon(job)
     if not profession or profession == "" then
     if job then
         return ""
        return "icon_职业_" .. job .. ".png"
    else
         return "icon_职业_未知.png"
     end
     end
    return "icon_职业_" .. profession .. ".png"
end
end


-- 根据属性名称获取图标文件名
-- 获取属性图标文件名
local function getAttributeIcon(attribute)
function p.getAttributeIcon(attribute)
     if not attribute or attribute == "" then
     if attribute then
         return ""
        return "icon_属性_" .. attribute .. ".png"
    else
         return "icon_属性_未知.png"
     end
     end
    return "icon_属性_" .. attribute .. ".png"
end
end


-- 获取角色图片文件名
-- 获取角色立绘文件名
local function getCharacterImage(characterName)
function p.getCharacterImage(characterName)
     return "战斗员图鉴_" .. characterName .. ".png"
     return "战斗员图鉴_" .. characterName .. ".png"
end
end


-- 渲染单个角色卡片
-- 渲染单个角色卡片
local function renderCharacterCard(characterName, data)
function p.renderCharacterCard(data)
     if not data or not data.data then
     if not data then
         return ""
         return ""
     end
     end
      
      
     local charData = data.data
     local name = data["名称"] or "未知"
    local name = charData["名称"] or characterName
     local rarity = data["稀有度"] or "1"
     local rarity = charData["稀有度"] or "1"
     local job = data["职业"] or ""
     local profession = charData["职业"] or ""
     local attribute = data["属性"] or ""
     local attribute = charData["属性"] or ""
   
    local jobIcon = p.getJobIcon(job)
    local attributeIcon = p.getAttributeIcon(attribute)
    local characterImage = p.getCharacterImage(name)
    local rarityClass = p.getRarityClass(rarity)
      
      
     local html = mw.html.create('div')
     local html = mw.html.create('div')
         :attr('style', 'position: relative; width: 150px; height: 280px; overflow: hidden; display: inline-block; margin: 5px;')
         :css('position', 'relative')
        :css('width', '150px')
        :css('height', '280px')
        :css('overflow', 'hidden')
        :css('display', 'inline-block')
        :css('margin', '5px')
      
      
     -- 背景
     -- 背景
     html:tag('div')
     html:tag('div')
         :attr('style', 'position: absolute; top: 0px; left: 0px; width: 150px; height: 280px; background-color:#2a2f40; border-radius: 0px 25px 0px 0px; z-index: 0;')
         :css('position', 'absolute')
        :css('top', '0px')
        :css('left', '0px')
        :css('width', '150px')
        :css('height', '280px')
        :css('background-color', '#2a2f40')
        :css('border-radius', '0px 25px 0px 0px')
        :css('z-index', '0')
      
      
     -- 职业图标
     -- 职业图标
     if profession ~= "" then
     html:tag('div')
         local professionIcon = getProfessionIcon(profession)
         :css('position', 'absolute')
         html:tag('div')
         :css('top', '5px')
            :attr('style', 'position: absolute; top: 5px; left: 5px; z-index: 1;')
        :css('left', '5px')
            :wikitext('[[File:' .. professionIcon .. '|25px|link=]]')
        :css('z-index', '1')
    end
        :wikitext('[[File:' .. jobIcon .. '|25px|link=]]')
      
      
     -- 属性图标
     -- 属性图标
     if attribute ~= "" then
     html:tag('div')
        local attributeIcon = getAttributeIcon(attribute)
        :css('position', 'absolute')
        html:tag('div')
        :css('top', '35px')
            :attr('style', 'position: absolute; top: 35px; left: 5px; z-index: 1;')
        :css('left', '5px')
            :wikitext('[[File:' .. attributeIcon .. '|25px|link=]]')
        :css('z-index', '1')
    end
        :wikitext('[[File:' .. attributeIcon .. '|25px|link=]]')
      
      
     -- 角色图片
     -- 角色立绘
    local characterImage = getCharacterImage(name)
     html:tag('div')
     html:tag('div')
         :attr('style', 'position: absolute; bottom: 0px; left: 0px; z-index: 1;')
         :css('position', 'absolute')
        :css('bottom', '0px')
        :css('left', '0px')
        :css('z-index', '1')
         :wikitext('[[File:' .. characterImage .. '|150px|link=]]')
         :wikitext('[[File:' .. characterImage .. '|150px|link=]]')
      
      
     -- 角色名称背景
     -- 角色名称背景
     html:tag('div')
     html:tag('div')
         :attr('style', 'position: absolute; bottom: 5px; left: 0px; width: 150px; height: 30px; background-color: rgba(0, 0, 0, 0.5); color: white; text-align: right; padding-right: 8px; padding-top: 3px; z-index: 2;')
         :css('position', 'absolute')
        :css('bottom', '5px')
        :css('left', '0px')
        :css('width', '150px')
        :css('height', '30px')
        :css('background-color', 'rgba(0, 0, 0, 0.5)')
        :css('color', 'white')
        :css('text-align', 'right')
        :css('padding-right', '8px')
        :css('padding-top', '3px')
        :css('z-index', '2')
         :wikitext(name)
         :wikitext(name)
      
      
     -- 稀有度样式
     -- 稀有度样式
    local rarityClass = getRarityClass(rarity)
     html:tag('div')
     html:tag('div')
         :addClass(rarityClass)
         :addClass(rarityClass)
         :attr('style', 'position: absolute; left: 0px; bottom: 0px; z-index: 2;')
         :css('position', 'absolute')
        :css('left', '0px')
        :css('bottom', '0px')
        :css('z-index', '2')
      
      
     -- 顶层蒙版
     -- 顶层蒙版
     html:tag('div')
     html:tag('div')
         :attr('style', 'position: absolute; left: 0px; bottom: 0px; z-index: 99;')
         :css('position', 'absolute')
        :css('left', '0px')
        :css('bottom', '0px')
        :css('z-index', '99')
         :wikitext('[[File:战斗员图鉴_顶层蒙版.png|link=]]')
         :wikitext('[[File:战斗员图鉴_顶层蒙版.png|link=]]')
      
      
第87行: 第143行:
end
end


-- 获取所有角色模块
-- 主函数
local function getAllCharacters()
function p.show(frame)
     local characters = {}
    local args = frame:getParent().args
     local targetCharacter = args[1] or args["角色"] or ""
      
      
     -- 获取所有以"模块:战斗员/"开头的页面
     -- 如果指定了角色名,只显示该角色
    local pages = {}
    if targetCharacter ~= "" then
   
        local data = p.loadCharacterData(targetCharacter)
    -- 使用API查询所有相关页面
         if data then
    for title, content in pairs(mw.loadData('Module:CharacterList') or {}) do
             return p.renderCharacterCard(data)
         if mw.ustring.match(title, '^模块:战斗员/') then
        else
             local characterName = mw.ustring.gsub(title, '^模块:战斗员/', '')
             return "错误:找不到角色数据 - " .. targetCharacter
             table.insert(characters, characterName)
         end
         end
     end
     end
      
      
     return characters
     -- 显示所有角色
end
     local result = {}
 
     local characters = p.getAllCharacters()
-- 主函数
function p.main(frame)
     local args = frame:getParent().args
     local targetCharacter = args[1] and mw.text.trim(args[1]) or nil
      
      
     local result = mw.html.create('div')
     -- 添加容器样式
        :attr('style', 'text-align: left;')
    table.insert(result, '<div style="display: flex; flex-wrap: wrap; gap: 10px;">')
      
      
     if targetCharacter and targetCharacter ~= "" then
     for _, characterName in ipairs(characters) do
        -- 显示单个角色
        local data = p.loadCharacterData(characterName)
        local moduleName = "模块:战斗员/" .. targetCharacter
        if data then
        local success, data = pcall(mw.loadData, moduleName)
            table.insert(result, p.renderCharacterCard(data))
       
        if success then
            result:wikitext(renderCharacterCard(targetCharacter, data))
        else
            result:wikitext("错误:找不到角色 " .. targetCharacter .. " 的数据模块")
        end
    else
        -- 显示所有角色
        local characters = getAllCharacters()
       
        if #characters == 0 then
            result:wikitext("没有找到任何角色数据")
            return tostring(result)
        end
       
        for _, characterName in ipairs(characters) do
            local moduleName = "模块:战斗员/" .. characterName
            local success, data = pcall(mw.loadData, moduleName)
           
            if success then
                result:wikitext(renderCharacterCard(characterName, data))
            end
         end
         end
     end
     end
      
      
     return tostring(result)
    table.insert(result, '</div>')
   
     return table.concat(result, '\n')
end
 
-- 直接调用函数(用于其他模块调用)
function p.showCharacter(characterName)
    local data = p.loadCharacterData(characterName)
    return p.renderCharacterCard(data)
end
 
-- 获取角色数据函数(用于其他模块调用)
function p.getCharacterData(characterName)
    return p.loadCharacterData(characterName)
end
end


return p
return p

2025年9月24日 (三) 20:47的版本

此模块的文档可以在模块:战斗员图鉴/doc创建

local p = {}

-- 获取所有战斗员模块的函数
function p.getAllCharacters()
    -- 这里需要手动维护角色列表,因为MediaWiki无法直接枚举所有模块
    -- 你需要在添加新角色时更新这个列表
    local characters = {
        "蕾欧娜",
        -- 在这里添加其他角色名称
    }
    return characters
end

-- 安全地加载角色数据
function p.loadCharacterData(characterName)
    local success, characterModule = pcall(require, "模块:战斗员/" .. characterName)
    if success and characterModule and characterModule.data then
        return characterModule.data
    else
        return nil
    end
end

-- 获取稀有度对应的CSS类
function p.getRarityClass(rarity)
    return "rarity-" .. (rarity or "1")
end

-- 获取职业图标文件名
function p.getJobIcon(job)
    if job then
        return "icon_职业_" .. job .. ".png"
    else
        return "icon_职业_未知.png"
    end
end

-- 获取属性图标文件名
function p.getAttributeIcon(attribute)
    if attribute then
        return "icon_属性_" .. attribute .. ".png"
    else
        return "icon_属性_未知.png"
    end
end

-- 获取角色立绘文件名
function p.getCharacterImage(characterName)
    return "战斗员图鉴_" .. characterName .. ".png"
end

-- 渲染单个角色卡片
function p.renderCharacterCard(data)
    if not data then
        return ""
    end
    
    local name = data["名称"] or "未知"
    local rarity = data["稀有度"] or "1"
    local job = data["职业"] or ""
    local attribute = data["属性"] or ""
    
    local jobIcon = p.getJobIcon(job)
    local attributeIcon = p.getAttributeIcon(attribute)
    local characterImage = p.getCharacterImage(name)
    local rarityClass = p.getRarityClass(rarity)
    
    local html = mw.html.create('div')
        :css('position', 'relative')
        :css('width', '150px')
        :css('height', '280px')
        :css('overflow', 'hidden')
        :css('display', 'inline-block')
        :css('margin', '5px')
    
    -- 背景
    html:tag('div')
        :css('position', 'absolute')
        :css('top', '0px')
        :css('left', '0px')
        :css('width', '150px')
        :css('height', '280px')
        :css('background-color', '#2a2f40')
        :css('border-radius', '0px 25px 0px 0px')
        :css('z-index', '0')
    
    -- 职业图标
    html:tag('div')
        :css('position', 'absolute')
        :css('top', '5px')
        :css('left', '5px')
        :css('z-index', '1')
        :wikitext('[[File:' .. jobIcon .. '|25px|link=]]')
    
    -- 属性图标
    html:tag('div')
        :css('position', 'absolute')
        :css('top', '35px')
        :css('left', '5px')
        :css('z-index', '1')
        :wikitext('[[File:' .. attributeIcon .. '|25px|link=]]')
    
    -- 角色立绘
    html:tag('div')
        :css('position', 'absolute')
        :css('bottom', '0px')
        :css('left', '0px')
        :css('z-index', '1')
        :wikitext('[[File:' .. characterImage .. '|150px|link=]]')
    
    -- 角色名称背景
    html:tag('div')
        :css('position', 'absolute')
        :css('bottom', '5px')
        :css('left', '0px')
        :css('width', '150px')
        :css('height', '30px')
        :css('background-color', 'rgba(0, 0, 0, 0.5)')
        :css('color', 'white')
        :css('text-align', 'right')
        :css('padding-right', '8px')
        :css('padding-top', '3px')
        :css('z-index', '2')
        :wikitext(name)
    
    -- 稀有度样式
    html:tag('div')
        :addClass(rarityClass)
        :css('position', 'absolute')
        :css('left', '0px')
        :css('bottom', '0px')
        :css('z-index', '2')
    
    -- 顶层蒙版
    html:tag('div')
        :css('position', 'absolute')
        :css('left', '0px')
        :css('bottom', '0px')
        :css('z-index', '99')
        :wikitext('[[File:战斗员图鉴_顶层蒙版.png|link=]]')
    
    return tostring(html)
end

-- 主函数
function p.show(frame)
    local args = frame:getParent().args
    local targetCharacter = args[1] or args["角色"] or ""
    
    -- 如果指定了角色名,只显示该角色
    if targetCharacter ~= "" then
        local data = p.loadCharacterData(targetCharacter)
        if data then
            return p.renderCharacterCard(data)
        else
            return "错误:找不到角色数据 - " .. targetCharacter
        end
    end
    
    -- 显示所有角色
    local result = {}
    local characters = p.getAllCharacters()
    
    -- 添加容器样式
    table.insert(result, '<div style="display: flex; flex-wrap: wrap; gap: 10px;">')
    
    for _, characterName in ipairs(characters) do
        local data = p.loadCharacterData(characterName)
        if data then
            table.insert(result, p.renderCharacterCard(data))
        end
    end
    
    table.insert(result, '</div>')
    
    return table.concat(result, '\n')
end

-- 直接调用函数(用于其他模块调用)
function p.showCharacter(characterName)
    local data = p.loadCharacterData(characterName)
    return p.renderCharacterCard(data)
end

-- 获取角色数据函数(用于其他模块调用)
function p.getCharacterData(characterName)
    return p.loadCharacterData(characterName)
end

return p