此处公告通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告
本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~
编辑帮助:目录 • BWIKI反馈留言板
此处公告通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告。本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~
模块:CharacterList
此模块的文档可以在模块:CharacterList/doc创建
local p = {}
-- 角色数据,仅记录名字和稀有度分类
local characterData = {
ssr = {"楚子航", "恺撒", "夏弥", "陈墨瞳", "上杉绘梨衣", "源稚女", "苏恩曦", "风间琉璃", "上杉越", "康斯坦丁", "诺顿", "昂热", "守夜人", "源稚生", "帕西", "诺玛", "芬格尔", "王将", "路鸣泽", "路明非", "酒德麻衣", "零"},
sr = {},
r = {}
}
-- 生成角色头像HTML
local function generateCharacterHTML(rarity, characters)
local html = {}
table.insert(html, string.format('<div class="characterList-row %s" style="flex-wrap:wrap">', rarity))
for _, name in ipairs(characters) do
-- 获取角色的JSON数据
local dataPage = mw.title.new('Data:ch/' .. name .. '.json')
local Data = mw.text.jsonDecode(dataPage:getContent() or '{}')
-- 提取角色信息,确保字段存在
local plotDrawing = Data.info and Data.info.plotdrawing or ""
local type_en = Data.info and Data.info.type_en or "unknown" -- 使用英文版本
local element = Data.info and Data.info.element or "未知元素"
local iconElement = Data.info and Data.info.element_en or "未知元素"
-- 根据 type_en 确定图标大小和类型
local iconSize = 22 -- 默认大小
local iconFile = "support" -- 默认图标类型
if type_en == "attack" then
iconSize = 25
iconFile = "attack"
elseif type_en == "defense" then
iconSize = 24
iconFile = "defense"
end
-- 使用 plotDrawing 控制立绘,并添加类型和元素信息
local characterImage = string.format('[[File:characterCard_%s%s.png|136px|link=%s]]', name, plotDrawing, name)
-- 动态设置图标和大小
local iconHTML = string.format(
'<div class="filter-no" style="width:%dpx;">[[file:icon_%s.png|%dpx]]<br/>[[file:icon_filter_%s.png|link=]]</div>',
iconSize, iconFile, iconSize, iconElement
)
-- 拼接角色HTML
local characterInfo = string.format(
'<div class="characterList-item" data-rarity="%s" data-type="%s" data-element="%s"><div class="characterList-item-image">%s<div class="characterList-item-deco"></div><div class="characterList-item-info">[[%s]]</div><div style="position:absolute;top:0;right:0;">%s</div></div></div>',
rarity, type_en, element, characterImage, name, iconHTML
)
table.insert(html, characterInfo)
end
table.insert(html, '</div>')
return table.concat(html)
end
-- 生成筛选器 HTML
local function generateFilterHTML()
return [[
]]
end
-- 主函数,生成筛选器和所有角色头像的 HTML
function p.characterList()
local html = {}
-- 添加筛选器
table.insert(html, generateFilterHTML())
-- 遍历每个稀有度,生成对应的头像列表
for rarity, characters in pairs(characterData) do
table.insert(html, generateCharacterHTML(rarity, characters))
end
return table.concat(html)
end
return p