战斗员图鉴:修订间差异
来自卡厄思梦境WIKI
创建页面,内容为“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…” |
小无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
-- | -- 获取所有战斗员模块的函数 | ||
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 | ||
-- | -- 获取职业图标文件名 | ||
function p.getJobIcon(job) | |||
if | if job then | ||
return "" | return "icon_职业_" .. job .. ".png" | ||
else | |||
return "icon_职业_未知.png" | |||
end | end | ||
end | end | ||
-- | -- 获取属性图标文件名 | ||
function p.getAttributeIcon(attribute) | |||
if | if attribute then | ||
return "" | return "icon_属性_" .. attribute .. ".png" | ||
else | |||
return "icon_属性_未知.png" | |||
end | end | ||
end | end | ||
-- | -- 获取角色立绘文件名 | ||
function p.getCharacterImage(characterName) | |||
return "战斗员图鉴_" .. characterName .. ".png" | return "战斗员图鉴_" .. characterName .. ".png" | ||
end | end | ||
-- 渲染单个角色卡片 | -- 渲染单个角色卡片 | ||
function p.renderCharacterCard(data) | |||
if not | if not data then | ||
return "" | return "" | ||
end | end | ||
local | local name = data["名称"] or "未知" | ||
local rarity = data["稀有度"] or "1" | |||
local rarity = | local job = data["职业"] or "" | ||
local | local attribute = data["属性"] or "" | ||
local attribute = | |||
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') | ||
: | :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') | ||
: | :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') | html:tag('div') | ||
: | :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') | ||
: | :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) | ||
-- 稀有度样式 | -- 稀有度样式 | ||
html:tag('div') | html:tag('div') | ||
:addClass(rarityClass) | :addClass(rarityClass) | ||
: | :css('position', 'absolute') | ||
:css('left', '0px') | |||
:css('bottom', '0px') | |||
:css('z-index', '2') | |||
-- 顶层蒙版 | -- 顶层蒙版 | ||
html:tag('div') | html:tag('div') | ||
: | :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 p.show(frame) | ||
local | 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) | |||
if | else | ||
return "错误:找不到角色数据 - " .. targetCharacter | |||
end | end | ||
end | end | ||
-- 显示所有角色 | |||
local result = {} | |||
local characters = p.getAllCharacters() | |||
-- | |||
local | |||
local | |||
-- 添加容器样式 | |||
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 | ||
end | end | ||
return | 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