956
次編輯
Economy666(留言 | 貢獻) (添加fullVersionNum(ver, date);优化) |
Economy666(留言 | 貢獻) (添加缓存;优化fullVersionNum();支持特定文本不进行日文格式化) |
||
行 3: | 行 3: | ||
-- local mad = require 'Module:AnotherData' | -- local mad = require 'Module:AnotherData' | ||
local memory = {} | |||
local | local function getMemory(enType, name) | ||
if memory[enType] then | |||
if memory[enType][name] then | |||
return memory[enType][name] | |||
end | |||
else | |||
memory[enType] = {} | |||
end | |||
end | |||
local function link(l, d) | local function link(l, d) | ||
行 16: | 行 25: | ||
local function formatLangText(text) | local function formatLangText(text) | ||
if not text then return text end | if not text then return text end | ||
return mw.ustring.gsub( | return mw.ustring.gsub( | ||
text, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', | text, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', | ||
行 23: | 行 31: | ||
end | end | ||
local function langLink(theType, __link, display) | local function langLink(theType, __link, display, noForm) | ||
local dis = display or __link | |||
local disForm = noForm and dis or formatLangText(dis) | |||
return link(theType..'列表#' .. __link, disForm) | |||
end | end | ||
行 36: | 行 42: | ||
local display_lang = data.zh and data.display or formatLangText(data.display) | local display_lang = data.zh and data.display or formatLangText(data.display) | ||
if data.link then | if data.link then | ||
artist = artist .. langLink(theType, data.link, | artist = artist .. langLink(theType, data.link, display_lang, true) | ||
else | else | ||
artist = artist .. (display_lang or '') | artist = artist .. (display_lang or '') | ||
行 74: | 行 80: | ||
local CALv2 | local CALv2 | ||
function | local function findArtist(artistName) | ||
CALv2 = CALv2 or mw.loadJsonData 'Template:ComplexArtistsList.json' | CALv2 = CALv2 or mw.loadJsonData 'Template:ComplexArtistsList.json' | ||
行 95: | 行 94: | ||
artist = langLink(theType, artistName) | artist = langLink(theType, artistName) | ||
end | end | ||
return artist | |||
end | |||
function p.artistLink(artistName) | |||
-- 将songlist中纯文本形式的曲师名称转换为带一个或多个链接的曲师名称,同时进行日文转换 | |||
-- 输入:曲师名称(需要与songlist内完全一致,或仅存在空格差异)(不要手打!!) | |||
-- 返回:带链接的曲师名称 | |||
-- 若预期返回多个链接,实际返回一个链接;或曲师使用了马甲未能正确识别,请在 Template:ComplexArtistsList.json 添加新规则 | |||
-- 注意事项:json转义符,如曲师名称有 " 需要写成 \"(点名Gram(DJ Genki)); | |||
-- lua匹配转义符,CALv2使用匹配简化结构,注意默认格式下value即显示部分(冒号右侧) . * 等符号需要在之前添加%转义 | |||
if artistName then artistName=tostring(artistName) else return end | |||
local artist = getMemory('artist', artistName) | |||
if artist then return artist end | |||
artist = findArtist(artistName) | |||
memory.artist[artistName] = artist | |||
return artist | return artist | ||
end | end | ||
local DL | local DL | ||
function | local function findDesigner(designerName) | ||
DL = DL or mw.loadJsonData 'Template:DesignersList.json' | DL = DL or mw.loadJsonData 'Template:DesignersList.json' | ||
local CDL = DL.complex | local CDL = DL.complex | ||
local SDL = DL.simple | local SDL = DL.simple | ||
local theType = '谱师' | |||
local function defaultSDL(text) | local function defaultSDL(text) | ||
local temp_text = text | local temp_text = text | ||
local link_placeholders = {} | local link_placeholders = {} | ||
行 151: | 行 162: | ||
end | end | ||
return langLink(theType, '其他未确认谱师名义', designerName) | return langLink(theType, '其他未确认谱师名义', designerName) | ||
end | |||
function p.designerLink(designerName, songid) | |||
-- songid参数可选,用于最终区分"其他未确认谱师名义"与"与主线剧情相关的特殊名义" | |||
-- 不填默认归为"其他未确认谱师名义" | |||
if designerName then designerName=tostring(designerName) else return end | |||
local designer = getMemory('designer', designerName) | |||
if designer then return designer end | |||
local designer = findDesigner(designerName) | |||
memory.designer[designerName] = designer | |||
return designer | |||
end | end | ||
行 162: | 行 184: | ||
-- true NS版曲包 | -- true NS版曲包 | ||
-- false 移动版曲包 | -- false 移动版曲包 | ||
if packName then packName=tostring(packName) else return end | |||
local class = 'pack_'..(ns and 'ns' or 'mobile')..(short and '_short' or '') | |||
local pack = getMemory(class, packName) | |||
if pack then return pack end | |||
local discrete_pack = {['Arcaea']='曲包', ['Memory Archive']=''} | local discrete_pack = {['Arcaea']='曲包', ['Memory Archive']=''} | ||
行 186: | 行 212: | ||
end | end | ||
local pack = link(packLink, packDisplay) | local pack = link(packLink, packDisplay) | ||
memory[class][packName] = pack | |||
return pack | return pack | ||
end | end | ||
行 191: | 行 219: | ||
local lang, VT | local lang, VT | ||
function p.fullVersionNum(ver, date) | function p.fullVersionNum(ver, date) | ||
lang = lang or mw.language.getContentLanguage() | local verClass = math.floor(date/100) | ||
local verData = getMemory('ver', verClass) | |||
if verData then return verData[1], verData[2], 'Memory' end | |||
local function findVer() | |||
lang = lang or mw.language.getContentLanguage() | |||
-- VT = VT or mw.loadJsonData 'Template:VersionTime.json' | |||
VT = VT or mw.text.jsonDecode(mw.title.new('Template:VersionTime.json'):getContent()) | |||
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 | |||
if #dates ~= #version then return ver,yml end | |||
local l, r = 1, #dates | |||
while l < r do | |||
local m = math.floor((l + r) / 2) | |||
if dates[m] < ymd then | |||
l = m + 1 | |||
else | |||
r = m | |||
end | |||
end | end | ||
return ver.. '.' ..version[l], dates[l] | |||
end | end | ||
verData={} | |||
verData[1], verData[2] = findVer() | |||
memory.ver[verClass] = verData | |||
return verData[1], verData[2] | |||
end | end | ||
return p | return p |
次編輯