Module:Sandbox/SongLink
可在Module:Sandbox/SongLink/doc创建此模块的帮助文档
local p = {}
local getArgs = require('Module:Arguments').getArgs
local songList = require("Module:LoadJson").Songlist()["songs"]
local l = {
["#1f1e33"] = "#1f1e33",
["AI[UE]OON"] = "AI[UE]OON",
["Last | Eternity"] = "Last",
["Last | Moment"] = "Last"
}
local n = {
["Last | Eternity"] = "Last \| Eternity",
["Last | Moment"] = "Last \| Moment"
}
function p.fixLink(name)
if l[name] then
return l[name]
else return name end
end
function p.fixDisplay(name)
if n[name] then
return n[name]
else return name end
end
function p.link(frame)
local args = getArgs(frame)
local songName = args[1] -- 既可以是 id,也可以是曲名,甚至是 Beyond 曲名
local isBeyond = args[2]
if not isBeyond then isBeyond = false end
local song = nil
local hasBeyondSpecialName = false
for i,k in pairs(songList) do
if k.id == songName then
song = k
break
end
if k.title_localized.en == songName then
song = k
break
end
if k.difficulties[4] and k.difficulties[4].title_localized
and k.difficulties[4].title_localized.en == songName then
hasBeyondSpecialName = true
isBeyond = true
song = k
end
end
if not song then error("未找到歌曲") end
if isBeyond and (not song.difficulties[4]) then error("曲目没有 Beyond 难度") end
if isBeyond and song.difficulties[4].title_localized then hasBeyondSpecialName = true end
local linkTo = p.fixLink(song.title_localized.en)
local display = song.title_localized.en
if hasBeyondSpecialName then
display = song.difficulties[4].title_localized.en
end
local display_fixed = p.fixDisplay(display)
local function fixTooltip(innerText, tooltip)
if not tooltip then
return "<span title=\"" .. innerText .."\">" .. innerText .. "</span>"
else
return "<span title=\"" .. tooltip .."\">" .. innerText .. "</span>"
end
end
if not(display == linkTo) then
if not (display_fixed == display) then
display = fixTooltip(display_fixed, display)
else display = fixTooltip(display) end
end
if linkTo == display then
return "[[" .. linkTo .. "|" .. display .. "]]"
else return "[[" .. linkTo .. "]]" end
end
return p