此处为全站公告,通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告。
本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~
编辑全站公告 • 编辑帮助:目录 • BWIKI反馈留言板
全站通知:
模块:Affinity
刷
历
编
跳到导航
跳到搜索
此模块的文档可以在模块:Affinity/doc创建
local p = {}
local function formatSkillDesc(desc)
if not desc then return "" end
desc = tostring(desc)
desc = desc:gsub("\\u000b", "<br>")
desc = desc:gsub('\r\n', '<br>')
desc = desc:gsub('\n', '<br>')
desc = desc:gsub(string.char(11), "<br>")
desc = desc:gsub("##([^#]+)#%d+#", "%1")
desc = desc:gsub("<[Cc]olor=[^>]+>", '<span style="color:#fb8037;">')
desc = desc:gsub("</[Cc]olor>", "</span>")
desc = desc:gsub("<sprite name=\"acrchives_certified_richtext\">","[[file:默契_肯定.png|link=|35px]]")
desc = desc:gsub("<sprite name=\"acrchives_falsified_richtext\">","[[file:默契_存疑.png|link=|35px]]")
return desc
end
function p.main(frame)
local args = frame.args or {}
local char = args[1] or ""
local AffinityType = args[2] or ""
local IdTitle = mw.title.new('Mediawiki:Char.json')
local itemcontent = IdTitle and IdTitle:getContent() or nil
local IdData = mw.text.jsonDecode(itemcontent) or {}
local rawId = IdData[char]
if not rawId then
return "角色不存在"
end
local id = tostring(rawId)
local title = mw.title.new('Mediawiki:char/' .. id .. '.json')
local content = title and title:getContent() or nil
local data = mw.text.jsonDecode(content or '{}')
local rawContent = content or ''
if AffinityType == '档案' then
local story = data.story or {}
local parts = {}
for i = 2, 13 do
local key = 'ArchiveContent' .. i
local item = story[key]
local title = ''
local desc = ''
if type(item) == 'table' then
title = item.title or ''
desc = item.desc or ''
else
title = ''
desc = item or ''
end
title = formatSkillDesc(title)
desc = formatSkillDesc(desc)
table.insert(parts, '<div class="sora_sora_affinity_archives_box ">')
table.insert(parts, '<div class="sora_sora_affinity_archives_title">' .. title .. '</div>')
table.insert(parts, '<div class="sora_sora_affinity_archives_desc">' .. desc .. '</div>')
table.insert(parts, '</div>')
end
return table.concat(parts, '\n')
end
if AffinityType == '语音' then
local voice = data.Voice or {}
local sections = {
{ key = 'Daily_Voice', cls = 'sora_sora_affinity_voice_daily', title = '日常语音' },
{ key = 'Combat_Voice', cls = 'sora_sora_affinity_voice_combat', title = '战斗语音' },
{ key = 'other_voice', cls = 'sora_sora_affinity_voice_other', title = '祝福语音' },
}
local parts = {}
for _, sec in ipairs(sections) do
local secdata = voice[sec.key] or {}
local keys = {}
local function extractTopLevelKeys(raw, objKey)
if not raw or raw == '' then return nil end
local pattern = '"' .. objKey .. '"%s*:%s*{'
local s, e = raw:find(pattern)
if not s then return nil end
local openPos = raw:find('{', e)
if not openPos then return nil end
local depth = 1
local i = openPos + 1
local len = #raw
local out = {}
while i <= len do
local c = raw:sub(i,i)
if c == '{' then
depth = depth + 1
i = i + 1
elseif c == '}' then
depth = depth - 1
if depth == 0 then break end
i = i + 1
elseif c == '"' and depth == 1 then
local j = i + 1
while j <= len do
local ch = raw:sub(j,j)
if ch == '"' then break end
if ch == '\\' then j = j + 2 else j = j + 1 end
end
if j > len then break end
local keyname = raw:sub(i+1, j-1)
table.insert(out, keyname)
local colonPos = raw:find(':', j)
if not colonPos then i = j + 1 else i = colonPos + 1 end
else
i = i + 1
end
end
return out
end
local ordered = extractTopLevelKeys(rawContent, sec.key)
if ordered and #ordered > 0 then
keys = ordered
else
for k, _ in pairs(secdata) do table.insert(keys, k) end
table.sort(keys, function(a, b)
local pa, na = a:match("^(.-)(%d+)$")
local pb, nb = b:match("^(.-)(%d+)$")
if pa and pb then
if pa == pb then
return tonumber(na) < tonumber(nb)
else
return pa < pb
end
end
return a < b
end)
end
if #keys > 0 then
table.insert(parts, '<div class="' .. sec.cls .. '">')
table.insert(parts, '<div class="' .. sec.cls .. '_title"><span>' .. sec.title .. '</span></div>')
for _, k in ipairs(keys) do
local item = secdata[k]
local ititle = ''
local desc = ''
if type(item) == 'table' then
ititle = item.title or k
desc = item.desc or ''
else
ititle = k
desc = item or ''
end
ititle = formatSkillDesc(ititle)
desc = formatSkillDesc(desc)
table.insert(parts, '<div class="sora_sora_affinity_voice_box">')
table.insert(parts, '<div class="sora_sora_affinity_voice_title">' .. ititle .. '</div>')
table.insert(parts, '<div class="sora_sora_affinity_voice_desc">' .. desc .. '</div>')
table.insert(parts, '</div>')
end
table.insert(parts, '</div>')
end
end
return table.concat(parts, '\n')
end
if AffinityType == '画廊' then
local galleryTitle = mw.title.new('Mediawiki:Gallery.json')
local galleryContent = galleryTitle and galleryTitle:getContent() or nil
local galleryData = mw.text.jsonDecode(galleryContent or '{}')
local galleryForChar = galleryData[id] or galleryData[tonumber(id)] or {}
if next(galleryForChar) == nil then
local tid = id and tostring(id):gsub('%s+', '') or nil
if tid then
for k, v in pairs(galleryData) do
if tostring(k) == tid or tostring(k) == tostring(tonumber(tid) or tid) then
galleryForChar = v or {}
break
end
end
end
end
local function extractTopLevelKeys(raw, objKey)
if not raw or raw == '' then return nil end
local pattern = '"' .. objKey .. '"%s*:%s*{'
local s, e = raw:find(pattern)
if not s then return nil end
local openPos = raw:find('{', e)
if not openPos then return nil end
local depth = 1
local i = openPos + 1
local len = #raw
local out = {}
while i <= len do
local c = raw:sub(i,i)
if c == '{' then
depth = depth + 1
i = i + 1
elseif c == '}' then
depth = depth - 1
if depth == 0 then break end
i = i + 1
elseif c == '"' and depth == 1 then
local j = i + 1
while j <= len do
local ch = raw:sub(j,j)
if ch == '"' then break end
if ch == '\\' then j = j + 2 else j = j + 1 end
end
if j > len then break end
local keyname = raw:sub(i+1, j-1)
table.insert(out, keyname)
local colonPos = raw:find(':', j)
if not colonPos then i = j + 1 else i = colonPos + 1 end
else
i = i + 1
end
end
return out
end
local keys = {}
local ordered = extractTopLevelKeys(galleryContent, id)
if ordered and #ordered > 0 then
keys = ordered
else
for k, _ in pairs(galleryForChar) do table.insert(keys, k) end
table.sort(keys)
end
local enName = tostring(data.EnName or data.enName or data.En or char or id)
local parts = {}
for idx, keyName in ipairs(keys) do
table.insert(parts, '<div class="sora_sora_affinity_gallery_title"><span>形象' .. tostring(idx) .. '</span></div>')
local val = galleryForChar[keyName]
local entries = {}
if type(val) == 'number' or (type(val) == 'string' and tonumber(val)) then
local count = tonumber(val)
local suffix = (keyName == 'normal') and '' or ('_' .. keyName)
for n = 2, count + 1 do
local numstr = string.format('%02d', n)
table.insert(entries, enName .. suffix .. '_' .. numstr .. '.png')
end
elseif type(val) == 'table' then
local isStringList = true
for i, v in ipairs(val) do
if type(v) ~= 'string' then isStringList = false break end
end
if isStringList and #val > 0 then
for _, v in ipairs(val) do
table.insert(entries, v)
end
else
local count = tonumber(val.count) or tonumber(val["count"]) or #val
if count and count > 0 then
local suffix = (keyName == 'normal') and '' or ('_' .. keyName)
for n = 2, count + 1 do
local numstr = string.format('%02d', n)
table.insert(entries, enName .. suffix .. '_' .. numstr .. '.png')
end
end
end
end
if #entries > 0 then
table.insert(parts, '<ul class="sora_sora_affinity_gallery_img_box">')
for _, fname in ipairs(entries) do
table.insert(parts, '<li><div class="sora_sora_affinity_gallery_img">' .. '[[file:' .. fname .. '|link=]]</div></li>')
end
table.insert(parts, '</ul>')
end
end
return table.concat(parts, '\n')
end
end
return p

沪公网安备 31011002002714 号