Module:沙盒/盐棋/Sandbox2:修订间差异
小 (pairs?) |
小 (evolve?) |
||
第1行: | 第1行: | ||
local p={} | local p = {} | ||
local W=mw | local W = mw | ||
local cfg = { | |||
prior = {single = 16383}, | |||
name = {single = 'Memory Archive'}, | |||
contest_set = {['base'] = true, ['observer'] = true, ['omatsuri'] = true}, | |||
mbIcon = '[[文件:Icon Smartphone.png|16px|link=曲目列表 (移动版)]]', | |||
nsIcon = '[[文件:Icon Nintendo switch.png|16px|link=曲目列表 (Nintendo Switch版)]]', | |||
NS_byd_set = {['tempestissimo'] = true}, | |||
display = { | |||
['ifi'] = '#1f1e33', | |||
['aiueoon'] = 'AI[UE]OON', | |||
['quon'] = 'Quon (Feryquitous)', | |||
['quonwacca'] = 'Quon (DJ Noriken)' | |||
} | |||
} | |||
function LoadJson(filename) | function LoadJson(filename) | ||
return W.text.jsonDecode(W.getCurrentFrame():expandTemplate{ title = filename }) | |||
end | end | ||
local packPrior,packName=(function () | local packPrior, packName = (function() | ||
local P, N = cfg.prior, cfg.name | |||
local P,N= | local conbine = function(rt, lf) return string.format('%s#%s - %s|%s - %s', rt, rt, lf, rt, lf) end | ||
for i, v in ipairs(LoadJson("packlist").packs) do | |||
local conbine=function(rt,lf)return | P[v.id] = i | ||
for i,v in ipairs(LoadJson("packlist").packs) do | N[v.id] = v.name_localized.en | ||
P[v.id]=i | |||
N[v.id]=v.name_localized.en | |||
if v.pack_parent then | if v.pack_parent then | ||
P[v.id]=P[v.pack_parent] | P[v.id] = P[v.pack_parent] | ||
N[v.id]=conbine(N[v.pack_parent],N[v.id]) | N[v.id] = conbine(N[v.pack_parent], N[v.id]) | ||
elseif v.custom_banner and not | elseif v.custom_banner and not cfg.contest_set[v.id] then | ||
N[v.id]=N[v.id]..' Collaboration' | N[v.id] = N[v.id] .. ' Collaboration' | ||
end | end | ||
end | end | ||
for i,v in ipairs(LoadJson("packlist NS").packs) do | for i, v in ipairs(LoadJson("packlist NS").packs) do | ||
if not N[v.id] and v.pack_parent then--single-append | if not N[v.id] and v.pack_parent then -- single-append | ||
P[v.id]=P[v.pack_parent] | P[v.id] = P[v.pack_parent] | ||
N[v.id]=conbine(N[v.pack_parent],v.name_localized.en) | N[v.id] = conbine(N[v.pack_parent], v.name_localized.en) | ||
end | end | ||
end | end | ||
for i,v in pairs(N) do | for i, v in pairs(N) do N[i] = string.format('[[%s]]', v) end | ||
return P, N | |||
return P,N | |||
end)() | end)() | ||
local songLines,songList=(function () | local songLines, songList = (function() | ||
local | -- ruin field: plat, title, NS_pack_alt | ||
local | local MP, LS, LST = {}, {}, {} | ||
local mbMark, nsMark = W.getCurrentFrame():expandTemplate{ | |||
title = ' 仅', | |||
for i,v in ipairs(LoadJson("songlist").songs) do | args = {' 移动版', '', ' 图片角标'} | ||
v.__plat={mbIcon} | }, W.getCurrentFrame():expandTemplate{ | ||
title = ' 仅', | |||
args = {'NS版', '', ' 图片角标'} | |||
} | |||
for i, v in ipairs(LoadJson("songlist").songs) do | |||
v.__plat = {cfg.mbIcon} | |||
MP[v.id] = v | |||
end | end | ||
for i,v in ipairs(LoadJson("songlist NS").songs) do | for i, v in pairs(cfg.display) do MP[i].__title = v end | ||
if | for i, v in ipairs(LoadJson("songlist NS").songs) do | ||
if MP[v.id] then | |||
if | table.insert(MP[v.id].__plat, cfg.nsIcon) | ||
if MP[v.id].set ~= v.set then | |||
MP[v.id].__NS_pack_alt = v.set | |||
end | end | ||
else | else | ||
v.__plat={nsIcon} | v.__plat = {cfg.nsIcon} | ||
MP[v.id] = v | |||
end | end | ||
end | end | ||
for i,v in pairs( | for i, v in pairs(MP) do | ||
table.insert(LST,i) | table.insert(LST, i) | ||
local page=W.title.new(v.__title or v.title_localized.en):getContent() | local page = W.title.new(v.__title or v.title_localized.en):getContent() | ||
local dur=page:match("时长%s*=%s*0?(%d:%d%d)") | local title = (v.__title and v.__title .. '|' or '') .. v.title_localized.en | ||
local | local dur = page:match("时长%s*=%s*0?(%d:%d%d)") | ||
local pack, bpm, rate = packName[v.set], v.bpm, '' | |||
if v.__NS_pack_alt then | if v.__NS_pack_alt then | ||
pack= | pack = string.format('%s%s<br />%s%s', pack, mbMark, packName[v.__NS_pack_alt], nsMark) | ||
end | end | ||
if not tonumber(bpm) then | if not tonumber(bpm) then | ||
bpm='data-sort-value='..v.bpm_base..'|'..bpm | bpm = 'data-sort-value=' .. v.bpm_base .. '|' .. bpm | ||
end | end | ||
for j,d in ipairs(v.difficulties) do | for j, d in ipairs(v.difficulties) do | ||
rate=rate..'||'..d.rating | rate = rate .. '||' .. d.rating | ||
if d.ratingPlus then | if d.ratingPlus then rate = rate .. '+' end | ||
end | end | ||
if v.difficulties[4] then | if v.difficulties[4] then | ||
if not NS_byd_set[v.id] then | if not cfg.NS_byd_set[v.id] then rate = rate .. mbMark end | ||
else | else | ||
rate=rate..'||/' | rate = rate .. '||/' | ||
end | end | ||
LS[i] = string.format( | |||
LS[i]='| | '|%s\n|[[文件:Songs %s.jpg|75px]]\n|[[%s]]\n|<span lang="ja"><!---->-{<!---->%s<!---->}-<!----></span>\n|%s\n|%s\n|0%s\n%s\n|-\n', | ||
table.concat(v.__plat), v.id, title, v.artist, pack, bpm, dur, rate:sub(2)) | |||
page = nil | |||
end | end | ||
table.sort(LST,function (a, b) | table.sort(LST, function(a, b) | ||
if packPrior[ | if packPrior[MP[a].set] ~= packPrior[MP[b].set] then | ||
return packPrior[ | return packPrior[MP[a].set] < packPrior[MP[b].set] | ||
else | else | ||
return | return MP[a].date < MP[b].date | ||
end | end | ||
end) | end) | ||
return LS,LST | return LS, LST | ||
end)() | end)() | ||
function p.main(frames) | function p.main(frames) | ||
local chart='' | local chart = '' | ||
for i,v in ipairs(songList) do | for i, v in ipairs(songList) do chart = chart .. songLines[v] end | ||
return chart | return chart | ||
end | end | ||
return p | return p |
2022年5月15日 (日) 18:02的版本
可在Module:沙盒/盐棋/Sandbox2/doc创建此模块的帮助文档
local p = {}
local W = mw
local cfg = {
prior = {single = 16383},
name = {single = 'Memory Archive'},
contest_set = {['base'] = true, ['observer'] = true, ['omatsuri'] = true},
mbIcon = '[[文件:Icon Smartphone.png|16px|link=曲目列表 (移动版)]]',
nsIcon = '[[文件:Icon Nintendo switch.png|16px|link=曲目列表 (Nintendo Switch版)]]',
NS_byd_set = {['tempestissimo'] = true},
display = {
['ifi'] = '#1f1e33',
['aiueoon'] = 'AI[UE]OON',
['quon'] = 'Quon (Feryquitous)',
['quonwacca'] = 'Quon (DJ Noriken)'
}
}
function LoadJson(filename)
return W.text.jsonDecode(W.getCurrentFrame():expandTemplate{ title = filename })
end
local packPrior, packName = (function()
local P, N = cfg.prior, cfg.name
local conbine = function(rt, lf) return string.format('%s#%s - %s|%s - %s', rt, rt, lf, rt, lf) end
for i, v in ipairs(LoadJson("packlist").packs) do
P[v.id] = i
N[v.id] = v.name_localized.en
if v.pack_parent then
P[v.id] = P[v.pack_parent]
N[v.id] = conbine(N[v.pack_parent], N[v.id])
elseif v.custom_banner and not cfg.contest_set[v.id] then
N[v.id] = N[v.id] .. ' Collaboration'
end
end
for i, v in ipairs(LoadJson("packlist NS").packs) do
if not N[v.id] and v.pack_parent then -- single-append
P[v.id] = P[v.pack_parent]
N[v.id] = conbine(N[v.pack_parent], v.name_localized.en)
end
end
for i, v in pairs(N) do N[i] = string.format('[[%s]]', v) end
return P, N
end)()
local songLines, songList = (function()
-- ruin field: plat, title, NS_pack_alt
local MP, LS, LST = {}, {}, {}
local mbMark, nsMark = W.getCurrentFrame():expandTemplate{
title = '仅',
args = {'移动版', '', '图片角标'}
}, W.getCurrentFrame():expandTemplate{
title = '仅',
args = {'NS版', '', '图片角标'}
}
for i, v in ipairs(LoadJson("songlist").songs) do
v.__plat = {cfg.mbIcon}
MP[v.id] = v
end
for i, v in pairs(cfg.display) do MP[i].__title = v end
for i, v in ipairs(LoadJson("songlist NS").songs) do
if MP[v.id] then
table.insert(MP[v.id].__plat, cfg.nsIcon)
if MP[v.id].set ~= v.set then
MP[v.id].__NS_pack_alt = v.set
end
else
v.__plat = {cfg.nsIcon}
MP[v.id] = v
end
end
for i, v in pairs(MP) do
table.insert(LST, i)
local page = W.title.new(v.__title or v.title_localized.en):getContent()
local title = (v.__title and v.__title .. '|' or '') .. v.title_localized.en
local dur = page:match("时长%s*=%s*0?(%d:%d%d)")
local pack, bpm, rate = packName[v.set], v.bpm, ''
if v.__NS_pack_alt then
pack = string.format('%s%s<br />%s%s', pack, mbMark, packName[v.__NS_pack_alt], nsMark)
end
if not tonumber(bpm) then
bpm = 'data-sort-value=' .. v.bpm_base .. '|' .. bpm
end
for j, d in ipairs(v.difficulties) do
rate = rate .. '||' .. d.rating
if d.ratingPlus then rate = rate .. '+' end
end
if v.difficulties[4] then
if not cfg.NS_byd_set[v.id] then rate = rate .. mbMark end
else
rate = rate .. '||/'
end
LS[i] = string.format(
'|%s\n|[[文件:Songs %s.jpg|75px]]\n|[[%s]]\n|<span lang="ja"><!---->-{<!---->%s<!---->}-<!----></span>\n|%s\n|%s\n|0%s\n%s\n|-\n',
table.concat(v.__plat), v.id, title, v.artist, pack, bpm, dur, rate:sub(2))
page = nil
end
table.sort(LST, function(a, b)
if packPrior[MP[a].set] ~= packPrior[MP[b].set] then
return packPrior[MP[a].set] < packPrior[MP[b].set]
else
return MP[a].date < MP[b].date
end
end)
return LS, LST
end)()
function p.main(frames)
local chart = ''
for i, v in ipairs(songList) do chart = chart .. songLines[v] end
return chart
end
return p