901
个编辑
Economy666(讨论 | 贡献) 小无编辑摘要 |
Economy666(讨论 | 贡献) (添加fullVersionNum(ver, date);优化) |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
第78行: | 第73行: | ||
end | end | ||
local | local CALv2 | ||
function p.artistLink(artistName) | function p.artistLink(artistName) | ||
-- 将songlist中纯文本形式的曲师名称转换为带一个或多个链接的曲师名称,同时进行日文转换 | -- 将songlist中纯文本形式的曲师名称转换为带一个或多个链接的曲师名称,同时进行日文转换 | ||
第110行: | 第81行: | ||
-- 注意事项:json转义符,如曲师名称有 " 需要写成 \"(点名Gram(DJ Genki)); | -- 注意事项:json转义符,如曲师名称有 " 需要写成 \"(点名Gram(DJ Genki)); | ||
-- lua匹配转义符,CALv2使用匹配简化结构,注意默认格式下value即显示部分(冒号右侧) . * 等符号需要在之前添加%转义 | -- lua匹配转义符,CALv2使用匹配简化结构,注意默认格式下value即显示部分(冒号右侧) . * 等符号需要在之前添加%转义 | ||
if artistName then artistName=tostring(artistName) else return end | if artistName then artistName=tostring(artistName) else return end | ||
CALv2 = CALv2 or mw.loadJsonData 'Template:ComplexArtistsList.json' | |||
local artist_list = CALv2[artistName] | local artist_list = CALv2[artistName] | ||
第127行: | 第98行: | ||
end | end | ||
local | local DL | ||
function p.designerLink(designerName, songid) | function p.designerLink(designerName, songid) | ||
-- songid参数可选,用于最终区分"其他未确认谱师名义"与"与主线剧情相关的特殊名义" | -- songid参数可选,用于最终区分"其他未确认谱师名义"与"与主线剧情相关的特殊名义" | ||
-- 不填默认归为"其他未确认谱师名义" | -- 不填默认归为"其他未确认谱师名义" | ||
if designerName then designerName=tostring(designerName) else return end | if designerName then designerName=tostring(designerName) else return end | ||
DL = DL or mw.loadJsonData 'Template:DesignersList.json' | |||
local CDL = DL.complex | |||
local SDL = DL.simple | |||
local function defaultSDL(text) | |||
local theType = '谱师' | |||
local temp_text = text | |||
local link_placeholders = {} | |||
local placeholder_count = 0 | |||
for _,data in ipairs(SDL) do | |||
local dis = data.display | |||
local name = data.link | |||
if string.find(temp_text, dis) then | |||
local link_text = langLink(theType, name, dis) | |||
local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__" | |||
link_placeholders[placeholder] = link_text | |||
temp_text = string.gsub(temp_text, dis, placeholder) | |||
placeholder_count = placeholder_count + 1 | |||
end | |||
end | |||
if placeholder_count == 0 then return text end | |||
local formatted_text = formatLangText(temp_text) | |||
for placeholder, link_text in pairs(link_placeholders) do | |||
formatted_text = string.gsub(formatted_text, placeholder, link_text) | |||
end | |||
return formatted_text | |||
end | |||
local designer | local designer | ||
local theType = '谱师' | local theType = '谱师' | ||
第147行: | 第146行: | ||
designerName = designerName==''and ' ' or designerName | designerName = designerName==''and ' ' or designerName | ||
if songid then | if songid then | ||
if | if DL.special[songid] then | ||
return langLink(theType,'与主线剧情相关的特殊名义', designerName) | return langLink(theType,'与主线剧情相关的特殊名义', designerName) | ||
end | end | ||
第188行: | 第187行: | ||
local pack = link(packLink, packDisplay) | local pack = link(packLink, packDisplay) | ||
return pack | return pack | ||
end | |||
local lang, VT | |||
function p.fullVersionNum(ver, date) | |||
lang = lang or mw.language.getContentLanguage() | |||
VT = VT or mw.loadJsonData 'Template:VersionTime.json' | |||
local ymd = tonumber(lang:formatDate('ymd', '@' .. date)) - 1 | |||
local vt | |||
if VT[ver] then vt=VT[ver] else return ver, ymd end | |||
local dates = vt.time | |||
local version = vt.ver | |||
local nDates = {} | |||
for _,d in ipairs(dates) do | |||
table.insert(nDates,d) | |||
end | |||
if ymd > nDates[#nDates] then return ver, ymd end | |||
if #nDates == 1 then return ver.. '.' ..version[1], dates[1] end | |||
local l, r = 1, #nDates | |||
while l < r do | |||
local m = math.floor((l + r) / 2) | |||
if dates[m] < ymd then | |||
l = m + 1 | |||
else | |||
r = m | |||
end | |||
end | |||
return ver.. '.' ..version[l], dates[l] | |||
end | end | ||
个编辑