Module:沙盒/盐棋/Sandbox:修订间差异

来自Arcaea中文维基
(?)
(\n)
第55行: 第55行:
end
end
return table.concat(map(details,
return table.concat(map(details,
function(v) return select(2, xpcall(function() return p.entry(v) end, function(e) mw.log(e); return "" end)) end))
function(v) return select(2, xpcall(function() return p.entry(v) end, function(e) return "" end)) end), "\n")
end
end
return p
return p

2022年10月10日 (一) 21:13的版本

可在Module:沙盒/盐棋/Sandbox/doc创建此模块的帮助文档

local p = {}
--=p.entry{plat={},id="kokoro",title="Heart",title2="心",artist='<span lang="ja">-{削除 (Violin : Katali)}-</span>',pack="pack",duration=148.014626,bpm="80-160",bpm_base=80,ratings={1,5,9}}
function map(iter, fn)
	-- local dict = setmetatable({}, { __index = fn })
	local ret = {}
	for k, v in pairs(iter) do ret[k] = fn(v, k, ret) end
	return ret
end
function opt(format, value, default)
	default = default or ""
	return value and format:format(tostring(value)) or default
end
function p.entry(info)
	if info.args then info = info.args end
	if not string.find(info.duration, ":") then
		-- mw.language.getContentLanguage():formatDate("i:s", "@" .. info.duration)
		local t = tonumber(info.duration)
		info.duration = math.floor(t / 60) .. ":" .. math.floor(t % 60)
	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())
	local details = {}
	for _, song in ipairs(mw.loadData "Module:songlist index".slst) do
		if song.id ~= "lasteternity" then
			table.insert(details, {
				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],
				ratings = map(song.difficulties, function(v) return v.rating .. opt("+", v.ratingPlus) end),
				date = song.date
			})
		end
	end
	table.sort(details, function(a, b)
		local d = math.abs(a.pack.idx) - math.abs(a.pack.idx)
		if d ~= 0 then return d < 0 else return a.date < b.date end
	end)
	for _, song in ipairs(details) do
		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
	end
	return table.concat(map(details,
		function(v) return select(2, xpcall(function() return p.entry(v) end, function(e) return "" end)) end), "\n")
end
return p