957
个编辑
Economy666(讨论 | 贡献) 小 (zh vocal) |
Economy666(讨论 | 贡献) (Module:沙盒/Economy666/CL) |
||
第1行: | 第1行: | ||
local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json' | |||
local DL = mw.loadJsonData 'User:Economy666/DesignersList.json' | |||
local CDL = DL.complex | |||
local SDL = DL.simple | |||
local p = {} | local p = {} | ||
第23行: | 第28行: | ||
end | end | ||
local function langLink(__link, display) | local function langLink(theType, __link, display) | ||
if display then | if display then | ||
return link(' | return link(theType..'列表#' .. __link, formatLangText(display)) | ||
else | else | ||
return link(' | return link(theType..'列表#' .. __link, formatLangText(__link)) | ||
end | end | ||
end | end | ||
local function | local function fullCL(theType, __FullData__) | ||
local artist = '' | local artist = '' | ||
for _, data in ipairs(__FullData__) do | for _, data in ipairs(__FullData__) do | ||
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(data.link, data.display) | artist = artist .. langLink(theType, data.link, data.display) | ||
else | else | ||
artist = artist .. (display_lang or '') | artist = artist .. (display_lang or '') | ||
第44行: | 第49行: | ||
end | end | ||
local function | local function defaultCL(theType, text, artist_list) | ||
local temp_text = text | local temp_text = text | ||
local link_placeholders = {} | local link_placeholders = {} | ||
第50行: | 第55行: | ||
for theLink, display in pairs(artist_list) do | for theLink, display in pairs(artist_list) do | ||
if type(display) == 'string' then | if type(display) == 'string' then | ||
local link_text = langLink(theLink, display) | local link_text = langLink(theType, theLink, display) | ||
local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__" | local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__" | ||
link_placeholders[placeholder] = link_text | link_placeholders[placeholder] = link_text | ||
第57行: | 第62行: | ||
elseif type(display)=='table' then | elseif type(display)=='table' then | ||
for _,dis in pairs(display) do | for _,dis in pairs(display) do | ||
local link_text = langLink(theLink, dis) | local link_text = langLink(theType, theLink, dis) | ||
local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__" | local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__" | ||
link_placeholders[placeholder] = link_text | link_placeholders[placeholder] = link_text | ||
第64行: | 第69行: | ||
end | end | ||
end | 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 | end | ||
return formatted_text | |||
end | |||
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) | local formatted_text = formatLangText(temp_text) | ||
for placeholder, link_text in pairs(link_placeholders) do | for placeholder, link_text in pairs(link_placeholders) do | ||
第82行: | 第112行: | ||
if artistName then artistName=tostring(artistName) else return end | if artistName then artistName=tostring(artistName) else return end | ||
local artist_list = CALv2[artistName] | local artist_list = CALv2[artistName] | ||
local theType = '曲师' | |||
if artist_list then | if artist_list then | ||
if artist_list.__FullData__ then | if artist_list.__FullData__ then | ||
artist = | artist = fullCL(theType, artist_list.__FullData__) | ||
else | else | ||
artist = | artist = defaultCL(theType, artistName, artist_list) | ||
end | end | ||
else | else | ||
artist = langLink(artistName) | artist = langLink(theType, artistName) | ||
end | end | ||
return artist | return artist | ||
end | end | ||
function p. | local specialSong = DL.special | ||
function p.designerLink(designerName, songid) | |||
-- songid参数可选,用于最终区分"其他未确认谱师名义"与"与主线剧情相关的特殊名义" | |||
-- 不填默认归为"其他未确认谱师名义" | |||
if designerName then designerName=tostring(designerName) else return end | |||
local designer | |||
local theType = '谱师' | |||
local designer_list = CDL[designerName] | |||
if designer_list then | |||
if designer_list.__FullData__ then | |||
designer = fullCL(theType, designer_list.__FullData__) | |||
else | |||
designer = defaultCL(theType, designerName, designer_list) | |||
end | |||
else | |||
designer = defaultSDL(designerName) | |||
end | |||
if designer ~= designerName then return designer end | |||
designerName = designerName==''and ' ' or designerName | |||
if songid then | |||
if specialSong[songid] then | |||
return langLink(theType,'与主线剧情相关的特殊名义', designerName) | |||
end | |||
end | |||
return langLink(theType, '其他未确认谱师名义', designerName) | |||
end | end | ||
function p.packLink(packName, short, ns) | function p.packLink(packName, short, ns) | ||
第143行: | 第188行: | ||
local pack = link(packLink, packDisplay) | local pack = link(packLink, packDisplay) | ||
return pack | return pack | ||
end | |||
function p.artistLinkFrame(frame) | |||
local name | |||
if frame and frame.args[1] then | |||
name = frame.args[1] | |||
else | |||
return '' | |||
end | |||
local al = p.artistLink(name) | |||
return al | |||
end | end | ||
第155行: | 第211行: | ||
end | end | ||
end | end | ||
return p | return p |
个编辑