Module:沙盒/盐棋/Sandbox:修订间差异
小 (lab) |
小 (haskell) |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local stream = require "Module:stream" | |||
function opt(format, value, default) | function opt(format, value, default) | ||
default = default or "" | default = default or "" | ||
第13行: | 第6行: | ||
end | end | ||
function p.entry(info) | function p.entry(info) | ||
if not string.find(info.duration, ":") then | if not string.find(info.duration, ":") then | ||
info.duration = mw.language.getContentLanguage():formatDate("i:s", "@" .. math.floor(tonumber(info.duration))) | info.duration = mw.language.getContentLanguage():formatDate("i:s", "@" .. math.floor(tonumber(info.duration))) | ||
第27行: | 第18行: | ||
) | ) | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local slstIdx = mw.loadData "Module:songlist index".slstIdx | local slstIdx = mw.loadData "Module:songlist index".slstIdx | ||
local plst = mw.loadData "Module:packlist index" | local plst = mw.loadData "Module:packlist index" | ||
local durs = mw.text.jsonDecode(mw.title.new "Template:duration.json":getContent()) | local durs = mw.text.jsonDecode(mw.title.new "Template:duration.json":getContent()) | ||
return table.concat(stream.Array(mw.loadData "Module:songlist index".slst) | |||
:filter(function(v) return v.id ~= "lasteternity" end) | |||
:map(function(song) return { | |||
plat = { "[[文件:Icon Smartphone.png|16px|link=曲目列表 (移动版)]]" }, id = song.id, | plat = { "[[文件:Icon Smartphone.png|16px|link=曲目列表 (移动版)]]" }, id = song.id, | ||
title = slstIdx[song.id].title, title2 = song.title_localized.ja or song.title_localized["zh-Hans"], | title = slstIdx[song.id].title, title2 = song.title_localized.ja or song.title_localized["zh-Hans"], | ||
artist = '<span lang="ja">-{' .. song.artist .. "}-</span>", pack = plst[song.set], | artist = '<span lang="ja">-{' .. song.artist .. "}-</span>", pack = plst[song.set], | ||
bpm = song.bpm, bpm_base = tonumber(song.bpm) ~= song.bpm_base and song.bpm_base or nil, | bpm = song.bpm, bpm_base = tonumber(song.bpm) ~= song.bpm_base and song.bpm_base or nil, | ||
duration = durs[song.id], | duration = durs[song.id] or 0, | ||
ratings = | ratings = stream.Array(song.difficulties):map(function(v) return v.rating .. opt("+", v.ratingPlus) end):toArray(), | ||
date = song.date | date = song.date | ||
} | } | ||
end | end) | ||
:sorted(function(a, b) | |||
local d = math.abs(a.pack.idx) - math.abs(b.pack.idx) | |||
if d ~= 0 then return d < 0 else return a.date < b.date end | |||
end) | |||
:map(function(song) | |||
song.pack = "[[" .. song.pack.name .. "]]" | |||
local ride = frame.args[song.id] | |||
if ride then for k, v in pairs(mw.text.jsonDecode(ride)) do song[k] = v end end | |||
local succ, res = pcall(p.entry, song) | |||
if succ then return res else return "" end | |||
end):toArray(), "\n") | |||
end | end | ||
return p | return p |
2022年10月19日 (三) 02:54的版本
可在Module:沙盒/盐棋/Sandbox/doc创建此模块的帮助文档
local p = {}
local stream = require "Module:stream"
function opt(format, value, default)
default = default or ""
return value and format:format(tostring(value)) or default
end
function p.entry(info)
if not string.find(info.duration, ":") then
info.duration = mw.language.getContentLanguage():formatDate("i:s", "@" .. math.floor(tonumber(info.duration)))
end
for i = 1, 4 do info.ratings[i] = opt("%s", info.ratings[i], "/") end
return ("|-\n|%s||[[文件:Songs %s.jpg|75px]]||%s||%s||%s||%s||%s||%s"):format(
table.concat(info.plat), info.id,
"[[" .. info.title .. "]]" .. opt('<br /><span lang="ja">-{%s}-</span>', info.title2),
info.artist, info.pack,
opt("data-sort-value=%s|", info.bpm_base) .. info.bpm,
info.duration, table.concat(info.ratings, "||")
)
end
function p.main(frame)
local slstIdx = mw.loadData "Module:songlist index".slstIdx
local plst = mw.loadData "Module:packlist index"
local durs = mw.text.jsonDecode(mw.title.new "Template:duration.json":getContent())
return table.concat(stream.Array(mw.loadData "Module:songlist index".slst)
:filter(function(v) return v.id ~= "lasteternity" end)
:map(function(song) return {
plat = { "[[文件:Icon Smartphone.png|16px|link=曲目列表 (移动版)]]" }, id = song.id,
title = slstIdx[song.id].title, title2 = song.title_localized.ja or song.title_localized["zh-Hans"],
artist = '<span lang="ja">-{' .. song.artist .. "}-</span>", pack = plst[song.set],
bpm = song.bpm, bpm_base = tonumber(song.bpm) ~= song.bpm_base and song.bpm_base or nil,
duration = durs[song.id] or 0,
ratings = stream.Array(song.difficulties):map(function(v) return v.rating .. opt("+", v.ratingPlus) end):toArray(),
date = song.date
}
end)
:sorted(function(a, b)
local d = math.abs(a.pack.idx) - math.abs(b.pack.idx)
if d ~= 0 then return d < 0 else return a.date < b.date end
end)
:map(function(song)
song.pack = "[[" .. song.pack.name .. "]]"
local ride = frame.args[song.id]
if ride then for k, v in pairs(mw.text.jsonDecode(ride)) do song[k] = v end end
local succ, res = pcall(p.entry, song)
if succ then return res else return "" end
end):toArray(), "\n")
end
return p