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

来自Arcaea中文维基
(版本)
(迭代1)
第1行: 第1行:
--- module: Another Data
local mad = require 'Module:沙盒/盐棋/Sandbox1'
local lang = mw.language.getContentLanguage()
local p = {}
local p = {}
local stream = require "Module:stream"
 
function opt(format, value, default)
local function opt(format, value, default)
default = default or ""
return value and format:format(tostring(value)) or default
return value and format:format(tostring(value)) or default
end
end
function p.entry(info)
 
if not string.find(info.duration, ":") then
local sectionCode = {unknown = 0, free = 1, archive = 2, mainstory = 3, sidestory = 4, collab = 5, single = 6}
info.duration = mw.language.getContentLanguage():formatDate("i:s", "@" .. math.floor(tonumber(info.duration)))
local langJa = '<span lang="ja">-{%s}-</span>'
-- 不对song的id、title_localized、artist、date、set、version、difficulties存在性做检验
local function main(plat, frame)
local lSong = mad.listOf('songs', plat)
-- pack index
-- duration
-- version
local mid = {}
for _, song in ipairs(lSong) do
local id = song.id
local function input(...) return frame.args[mw.text.listToText({id, ...}, '.', '.')] end
if id ~= 'lasteternity' then
local query = mad.songQueryWrap(song)
local packItem = mad.packQueryWrap(song.set, plat)
local row = {sort = {sectionCode[packItem['section']], packItem['numero'], song.date}}
table.insert(mid, row)
 
table.insert(row, id)
local title = input '标题'
if not title then
local baseTitle = {query.titleName}
table.insert(baseTitle, query.title)
local titles = {'[[' .. table.concat(baseTitle, '|') .. ']]'}
table.insert(titles, opt(langJa, song.title_localized.ja))
table.insert(titles, song.title_localized['zh-Hans'])
table.insert(titles, opt('%s <span style=color:#822328>[Beyond]</span>', query['.difficulties.4?title_localized?en']))
title = table.concat(titles, '<br />')
end
table.insert(row, title)
table.insert(row, input '音乐家' or mw.ustring.gsub(song.artist, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', function(v)
return langJa:format(v)
end))
table.insert(row, input '所属曲包' or packItem['name'])
local bpm = input 'BPM' or song.bpm_base
table.insert(row, (tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
table.insert(row, input '时长' or ' - ')
if plat ~= 'ns' then
table.insert(row, song.version .. '.')
end
for idx, key in ipairs {'PST', 'PRS', 'FTR', 'BYD'} do
local rating = input('等级', key)
if not rating then
local difficulty = song.difficulties[idx]
rating = difficulty and difficulty.rating .. (difficulty.ratingPlus and '+' or '') or '/'
end
table.insert(row, rating)
end
end
end
table.sort(mid, function(a, b)
for i = 1, 3 do
local d = a.sort[i] - b.sort[i]
if d ~= 0 then return d < 0 end
end
return false
end)
local res = {}
local template = '|-\n|[[文件:Songs %s.jpg|75px]]' .. ('||%s'):rep(plat == 'ns' and 9 or 10)
for idx, value in ipairs(mid) do
res[idx] = template:format(unpack(value))
end
end
for i = 1, 4 do info.ratings[i] = opt("%s", info.ratings[i], "/") end
return table.concat(res, '\n')
return ("|-\n|%s||[[文件:Songs %s.jpg|75px]]||%s||%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, info.version, table.concat(info.ratings, "||")
)
end
end


function p.main(frame)
function p.mobile(frame) return main('mobile', frame:getParent() or frame) end
local slstIdx = mw.loadData "Module:songlist index".slstIdx
function p.ns(frame) return main('ns', frame:getParent() or frame) end
local plst = mw.loadData "Module:packlist index"
 
local durs = mw.text.jsonDecode(mw.title.new "Template:duration.json":getContent())
local vers = mw.text.jsonDecode(mw.title.new "Template:version map.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=Arcaea ( 移动版)]]" }, id = song.id,
-- Arcaea (Nintendo Switch版)
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,
version = song.version .. "." .. (vers[song.id] or
vers[mw.language.getContentLanguage():formatDate("Y/n/j", "@" .. song.date)] or
-- mw.getCurrentFrame():expandTemplate { title = "Template:version", args = { "mobile" } }:match "[^.]+$"),
"[[Template:version map.json|E]]"),
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
return p

2024年2月17日 (六) 09:59的版本

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

--- module: Another Data
local mad = require 'Module:沙盒/盐棋/Sandbox1'
local lang = mw.language.getContentLanguage()
local p = {}

local function opt(format, value, default)
	return value and format:format(tostring(value)) or default
end

local sectionCode = {unknown = 0, free = 1, archive = 2, mainstory = 3, sidestory = 4, collab = 5, single = 6}
local langJa = '<span lang="ja">-{%s}-</span>'
-- 不对song的id、title_localized、artist、date、set、version、difficulties存在性做检验
local function main(plat, frame)
	local lSong = mad.listOf('songs', plat)
	-- pack index
	-- duration
	-- version
	local mid = {}
	for _, song in ipairs(lSong) do
		local id = song.id
		local function input(...) return frame.args[mw.text.listToText({id, ...}, '.', '.')] end
		if id ~= 'lasteternity' then
			local query = mad.songQueryWrap(song)
			local packItem = mad.packQueryWrap(song.set, plat)
			local row = {sort = {sectionCode[packItem['section']], packItem['numero'], song.date}}
			table.insert(mid, row)

			table.insert(row, id)
			local title = input '标题'
			if not title then
				local baseTitle = {query.titleName}
				table.insert(baseTitle, query.title)
				local titles = {'[[' .. table.concat(baseTitle, '|') .. ']]'}
				table.insert(titles, opt(langJa, song.title_localized.ja))
				table.insert(titles, song.title_localized['zh-Hans'])
				table.insert(titles, opt('%s <span style=color:#822328>[Beyond]</span>', query['.difficulties.4?title_localized?en']))
				title = table.concat(titles, '<br />')
			end
			table.insert(row, title)
			table.insert(row, input '音乐家' or mw.ustring.gsub(song.artist, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', function(v)
				return langJa:format(v)
			end))
			table.insert(row, input '所属曲包' or packItem['name'])
			local bpm = input 'BPM' or song.bpm_base
			table.insert(row, (tonumber(song.bpm) ~= bpm and ('data-sort-value=%s|'):format(bpm) or '') .. song.bpm)
			table.insert(row, input '时长' or ' - ')
			if plat ~= 'ns' then
				table.insert(row, song.version .. '.')
			end
			for idx, key in ipairs {'PST', 'PRS', 'FTR', 'BYD'} do
				local rating = input('等级', key)
				if not rating then
					local difficulty = song.difficulties[idx]
					rating = difficulty and difficulty.rating .. (difficulty.ratingPlus and '+' or '') or '/'
				end
				table.insert(row, rating)
			end
		end
	end
	table.sort(mid, function(a, b)
		for i = 1, 3 do
			local d = a.sort[i] - b.sort[i]
			if d ~= 0 then return d < 0 end
		end
		return false
	end)
	local res = {}
	local template = '|-\n|[[文件:Songs %s.jpg|75px]]' .. ('||%s'):rep(plat == 'ns' and 9 or 10)
	for idx, value in ipairs(mid) do
		res[idx] = template:format(unpack(value))
	end
	return table.concat(res, '\n')
end

function p.mobile(frame) return main('mobile', frame:getParent() or frame) end
function p.ns(frame) return main('ns', frame:getParent() or frame) end

return p