Module:沙盒/Economy666/CL:修订间差异
Economy666(讨论 | 贡献) 小无编辑摘要 |
Economy666(讨论 | 贡献) (designerLink) |
||
第23行: | 第23行: | ||
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行: | 第44行: | ||
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行: | 第50行: | ||
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行: | 第57行: | ||
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 | ||
第87行: | 第87行: | ||
local artist = '' | local artist = '' | ||
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 | ||
第119行: | 第120行: | ||
end | end | ||
function p.designerLink( | function p.designerLink(designerName) | ||
if | if designerName then designerName=tostring(designerName) else return end | ||
local | local DL = mw.loadJsonData 'User:Economy666/DesignersList.json' | ||
local | local CDL = DL.complex | ||
local | local SDL = DL.simple | ||
local theType = ' 谱师' | |||
local designer = '' | |||
local designer_list = CDL[designerName] | |||
if designer_list then | |||
if designer_list.__FullData__ then | |||
designer = fullCL(theType, designer_list.__FullData__) | |||
local | |||
local | |||
if | |||
if | |||
else | else | ||
designer = defaultCL(theType, designerName, designer_list) | |||
end | |||
else | |||
designer=designerName | |||
local current='' | |||
current = designerName | |||
for display,name in pairs(SDL) do | |||
if string.find(current, display) then | |||
current=string.gsub(current, display, '') | |||
designer=string.gsub(designer, display, langLink(theType, name, display)) | |||
end | end | ||
end | end | ||
end | end | ||
return | return designer | ||
end | end | ||
function p. | function p.designerShowAll() | ||
local lines = '' | local lines = 'Designer Show All:<br>' | ||
local slst = mw.loadJsonData 'Template:Songlist.json' | local slst = mw.loadJsonData 'Template:Songlist.json' | ||
local Designers = {} | local Designers = {} | ||
for _,song in pairs(slst.songs) do | for _,song in pairs(slst.songs) do | ||
for _,level in pairs(song.difficulties) do | for _,level in pairs(song.difficulties) do | ||
local name = level.chartDesigner | |||
Designers[name] = 1 | |||
end | end | ||
end | end | ||
for | for name in pairs(Designers) do | ||
lines = lines .. p.designerLink(name) .. '<br>' | lines = lines .. p.designerLink(name) .. '<br>' | ||
end | end |
2024年7月23日 (二) 20:37的版本
可在Module:沙盒/Economy666/CL/doc创建此模块的帮助文档
local p = {}
-- local mad = require 'Module:AnotherData'
local NotJaArtist = {['旅人E']=''}
local function link(l, d)
if d then
return '[[' .. l .. '|' .. d .. ']]'
else
return '[[' .. l .. ']]'
end
end
local function formatLangText(text)
if not text then return text end
if NotJaArtist[text] then return text end
return mw.ustring.gsub(
text, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+',
function(v) return ('<span lang="ja">-{%s}-</span>'):format(v) end
)
end
local function langLink(theType, __link, display)
if display then
return link(theType..'列表#' .. __link, formatLangText(display))
else
return link(theType..'列表#' .. __link, formatLangText(__link))
end
end
local function fullCL(theType, __FullData__)
local artist = ''
for _, data in ipairs(__FullData__) do
local display_lang = data.zh and data.display or formatLangText(data.display)
if data.link then
artist = artist .. langLink(theType, data.link, data.display)
else
artist = artist .. (display_lang or '')
end
end
return artist
end
local function defaultCL(theType, text, artist_list)
local temp_text = text
local link_placeholders = {}
local placeholder_count = 0
for theLink, display in pairs(artist_list) do
if type(display) == 'string' then
local link_text = langLink(theType, theLink, display)
local placeholder = "__LINK_PLACEHOLDER_" .. placeholder_count .. "__"
link_placeholders[placeholder] = link_text
temp_text = string.gsub(temp_text, display, placeholder)
placeholder_count = placeholder_count + 1
elseif type(display)=='table' then
for _,dis in pairs(display) do
local link_text = langLink(theType, theLink, 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
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
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 CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json'
-- local CALv2 = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json'
local artist = ''
local artist_list = CALv2[artistName]
local theType = '曲师'
if artist_list then
if artist_list.__FullData__ then
artist = fullCL(theType, artist_list.__FullData__)
else
artist = defaultCL(theType, artistName, artist_list)
end
else
artist = langLink(theType, artistName)
end
return artist
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
function p.artistShowAll()
local lines = '123'
local calNew = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json'
for name,_ in pairs(calNew) do
lines = lines .. p.artistLink(name) .. '<br>'
end
return lines
end
function p.designerLink(designerName)
if designerName then designerName=tostring(designerName) else return end
local DL = mw.loadJsonData 'User:Economy666/DesignersList.json'
local CDL = DL.complex
local SDL = DL.simple
local theType = '谱师'
local designer = ''
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=designerName
local current=''
current = designerName
for display,name in pairs(SDL) do
if string.find(current, display) then
current=string.gsub(current, display, '')
designer=string.gsub(designer, display, langLink(theType, name, display))
end
end
end
return designer
end
function p.designerShowAll()
local lines = 'Designer Show All:<br>'
local slst = mw.loadJsonData 'Template:Songlist.json'
local Designers = {}
for _,song in pairs(slst.songs) do
for _,level in pairs(song.difficulties) do
local name = level.chartDesigner
Designers[name] = 1
end
end
for name in pairs(Designers) do
lines = lines .. p.designerLink(name) .. '<br>'
end
return lines
end
function p.packLink(packName, short, ns)
-- 曲包名称转换成链接
-- short
-- true 简短(x Collaboration y)
-- false 完整(x Collaboration - Collaboration y)
-- ns 适用于Arcaea和Memory Archive曲包
-- true NS版曲包
-- false 移动版曲包
local discrete_pack = {['Arcaea']='曲包', ['Memory Archive']=''}
-- 分离双平台页的曲包,value为后缀附加内容: '曲包'->' (xx版曲包)' ; ''->' (xx版)'
local cc = 'Collaboration %- Collaboration'
local ccl = 'Collaboration#Collaboration'
local linkFlag = ''
if discrete_pack[packName] then
if ns then
linkFlag = (' (NS版%s)'):format(discrete_pack[packName])
else
linkFlag = (' (移动版%s)'):format(discrete_pack[packName])
end
end
local packLink = string.gsub(packName, cc, ccl) .. linkFlag
local packDisplay
if short then
local ccd = 'Collaboration'
packDisplay = string.gsub(packName, cc, ccd)
else
packDisplay = packName
end
local pack = link(packLink, packDisplay)
return pack
end
function p.packLinkFrame(frame)
if frame then
local name = frame.args['name'] or nil
local short = frame.args['short'] or nil
local ns = frame.args['ns'] or nil
return p.packLink(name, short, ns)
else
return 'none'
end
end
return p