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

来自Arcaea中文维基
(bpm tonumber)
(ulk测试)
第1行: 第1行:
--- module: Another Data
local mad = require 'Module:AnotherData'
local mad = require 'Module: 沙盒/盐棋/Sandbox1'
local lang = mw.language.getContentLanguage()
local p = {}
local p = {}


local function opt(format, value, default)
local linkPool = {}
return value and format:format(tostring(value)) or default
local mLink = {}
local mSong = {}
for _, song in ipairs(mad.listOf 'songs') do
local query = mad.songQueryWrap(song)
local link = query.linkTitle
linkPool[link] = true
mSong[song.id] = song
mLink[song.id] = link
end
end


local versions = {date = {}, name = {}}
function p.world(frame)
local function verQuery(mDate)
local world = mw.title.new('世界模式地图详表 ( 移动版' .. frame.args[1] .. ')'):getContent()
local dDate = tonumber(lang:formatDate('ymd', '@' .. mDate)) - 1
local res = {}
local dates = versions.date
for name, wtb in world:gmatch '== *([^B].-) *==[^={]+(%b{})' do
if dDate > dates[#dates] then return '?' end
local tot
local l, r = 1, #dates
for stair, reward in wtb:gmatch '| *(%d+)[0-9()%-| ]+(%b[])' do
while l < r do
if linkPool[reward:sub(3, -3)] then
local m = math.floor((l + r) / 2)
tot = tot or tonumber(wtb:match '| *(%d+)[^\n]+\n|%-\n| *总计') - 1
if dates[m] < dDate then
table.insert(res, ('|-\n|%s||%s||%d/%d'):format(reward, name, tonumber(stair) - 1, tot))
l = m + 1
end
else
r = m
end
end
end
end
return versions.name[l]
return table.concat(res, '\n')
end
end


local sectionCode = {unknown = 0, free = 1, archive = 2, mainstory = 3, sidestory = 4, collab = 5, single = 6}
local templates = {
local langJa = '<span lang="ja">-{%s}-</span>'
[0] = '$credit 残片',
-- 不对song的id、title_localized、artist、date、set、version、difficulties存在性做检验
'$grade通关 $song_id $song_difficulty',
local function main(plat, frame)
'游玩 $song_id $song_difficulty',
local lSong = mad.listOf('songs', plat)
'$grade通关 $song_id $song_difficulty$times回',
local mid = {}
"$1 <br>'''或''' $2",
for _, song in ipairs(lSong) do
'个人游玩潜力值 $rating 或以上',
local id = song.id
' 通关$count首$rating$ratingPlus难度曲目',
local function input(...) return frame.args[table.concat({id, ...}, '.')] end
}
if id ~= 'lasteternity' then
local handlers = {}
local query = mad.songQueryWrap(song)
local linkize = '[[%s]]'
local packItem = mad.packQueryWrap(song.set, plat)
function handlers.song_id(v) return linkize:format(mLink[v]) end
local row = {sort = {sectionCode[packItem['section']], packItem['numero'], song.date}}
function handlers.song_difficulty(v) return ({[0] = '[PST]', '[PRS]', '[FTR]', '[BYD]'})[v] end
table.insert(mid, row)
function handlers.grade(v) return v == 0 and '' or ('以 「%s」 或以上成绩'):format(({'C', 'B', 'A', 'AA', 'EX'})[v]) end
function handlers.rating(v) return v > 13 and ('%.2f'):format(v / 100) or v end
function handlers.ratingPlus(v) return v and '+' or '' end
local function stringify(cond)
return templates[cond.type]:gsub('%$([a-zA-Z12_]+)', function(k)
local nk = tonumber(k)
if nk then return stringify(cond.conditions[nk]) end
if handlers[k] then return handlers[k](cond[k]) end
return cond[k]
end)
end


table.insert(row, id)
function p.main()
local title = input ' 标题'
local view = {}
if not title then
for _, chartUlk in ipairs(mad.listOf 'unlocks') do
local baseTitle = {query.titleName}
local id, rc = chartUlk.songId, chartUlk.ratingClass
table.insert(baseTitle, query.title)
local row = view[id]
local titles = {'[[' .. table.concat(baseTitle, '|') .. ']]'}
if not row then
table.insert(titles, opt(langJa, song.title_localized.ja))
row = {}
table.insert(titles, song.title_localized['zh-Hans'])
view[id] = row
table.insert(titles, opt('%s <span style=color:#822328>[Beyond]</span>', query['.difficulties.4?title_localized?en']))
end
title = table.concat(titles, '<br />')
local cell = {}
row[rc] = cell
for _, cond in ipairs(chartUlk.condition) do
local className
if cond.type == 0 then
className = 'ulk-frag'
elseif cond.type <= 100 and cond.type ~= 5 then
className = 'ulk-prev'
end
end
table.insert(row, title)
if className then
table.insert(row, input '音乐家' or mw.ustring.gsub(song.artist, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+', function(v) return langJa:format(v) end))
table.insert(cell, mw.html.create 'span':addClass(className):wikitext(stringify(cond)))
table.insert(row, input '所属曲包' or packItem['name'])
local bpm = tonumber(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
local version = input '收录版本' or verQuery(song.date)
table.insert(row, song.version .. '.' .. version)
end
end
for idx, key in ipairs {'PST', 'PRS', 'FTR', 'BYD'} do
end
local rating = input('等级', key)
end
if not rating then
 
local difficulty = song.difficulties[idx]
local texts = {}
rating = difficulty and difficulty.rating .. (difficulty.ratingPlus and '+' or '') or '/'
local rowFormat = '|-\n|[[%s]]' .. ('||%s'):rep(3)
end
local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
table.insert(row, rating)
for id, row in pairs(view) do
local song = mSong[id]
local packItem = mad.packQueryWrap(song.set, 'mobile')
local rowText = {}
for i = 1, 3 do
local cell = row[i]
if not cell or #cell == 0 then
rowText[i] = ' '
else
rowText[i] = mw.allToString(unpack(cell))
end
end
end
end
table.insert(texts, {
data = rowFormat:format(mLink[id], unpack(rowText)),
pack = packItem['name'],
sort = {sectionCode[packItem['section']], packItem['numero'], song.date},
})
end
end
table.sort(mid, function(a, b)
 
table.sort(texts, function(a, b)
a, b = a.sort, b.sort
for i = 1, 3 do
for i = 1, 3 do
local d = a.sort[i] - b.sort[i]
local d = a[i] - b[i]
if d ~= 0 then return d < 0 end
if d ~= 0 then return d < 0 end
end
end
return false
return false
end)
end)
local res = {}
 
local template = '|-\n|[[文件:Songs %s.jpg|75px]]' .. ('||%s'):rep(plat == 'ns' and 9 or 10)
local hybrid = {}
for idx, value in ipairs(mid) do
local pack
res[idx] = template:format(unpack(value))
for _, value in ipairs(texts) do
if pack ~= value.pack then
pack = value.pack
table.insert(hybrid, '|-\n| colspan="4" |' .. pack)
end
table.insert(hybrid, value.data)
end
end
return table.concat(res, '\n')
end


function p.mobile(frame)
return table.concat(hybrid, '\n')
for record in mw.text.gsplit(frame.args.versions, '%s') do
local date, name = record:match '(%d+):(.*)'
table.insert(versions.date, tonumber(date))
table.insert(versions.name, name)
end
return main('mobile', frame:getParent())
end
end
function p.ns(frame) return main('ns', frame:getParent()) end


return p
return p

2024年2月24日 (六) 19:26的版本

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

local mad = require 'Module:AnotherData'
local p = {}

local linkPool = {}
local mLink = {}
local mSong = {}
for _, song in ipairs(mad.listOf 'songs') do
	local query = mad.songQueryWrap(song)
	local link = query.linkTitle
	linkPool[link] = true
	mSong[song.id] = song
	mLink[song.id] = link
end

function p.world(frame)
	local world = mw.title.new('世界模式地图详表 (移动版' .. frame.args[1] .. ')'):getContent()
	local res = {}
	for name, wtb in world:gmatch '== *([^B].-) *==[^={]+(%b{})' do
		local tot
		for stair, reward in wtb:gmatch '| *(%d+)[0-9()%-| ]+(%b[])' do
			if linkPool[reward:sub(3, -3)] then
				tot = tot or tonumber(wtb:match '| *(%d+)[^\n]+\n|%-\n| *总计') - 1
				table.insert(res, ('|-\n|%s||%s||%d/%d'):format(reward, name, tonumber(stair) - 1, tot))
			end
		end
	end
	return table.concat(res, '\n')
end

local templates = {
	[0] = '$credit 残片',
	'$grade通关 $song_id $song_difficulty',
	'游玩 $song_id $song_difficulty',
	'$grade通关 $song_id $song_difficulty$times回',
	"$1 <br>'''或''' $2",
	'个人游玩潜力值 $rating 或以上',
	'通关$count首$rating$ratingPlus难度曲目',
}
local handlers = {}
local linkize = '[[%s]]'
function handlers.song_id(v) return linkize:format(mLink[v]) end
function handlers.song_difficulty(v) return ({[0] = '[PST]', '[PRS]', '[FTR]', '[BYD]'})[v] end
function handlers.grade(v) return v == 0 and '' or ('以 「%s」 或以上成绩'):format(({'C', 'B', 'A', 'AA', 'EX'})[v]) end
function handlers.rating(v) return v > 13 and ('%.2f'):format(v / 100) or v end
function handlers.ratingPlus(v) return v and '+' or '' end
local function stringify(cond)
	return templates[cond.type]:gsub('%$([a-zA-Z12_]+)', function(k)
		local nk = tonumber(k)
		if nk then return stringify(cond.conditions[nk]) end
		if handlers[k] then return handlers[k](cond[k]) end
		return cond[k]
	end)
end

function p.main()
	local view = {}
	for _, chartUlk in ipairs(mad.listOf 'unlocks') do
		local id, rc = chartUlk.songId, chartUlk.ratingClass
		local row = view[id]
		if not row then
			row = {}
			view[id] = row
		end
		local cell = {}
		row[rc] = cell
		for _, cond in ipairs(chartUlk.condition) do
			local className
			if cond.type == 0 then
				className = 'ulk-frag'
			elseif cond.type <= 100 and cond.type ~= 5 then
				className = 'ulk-prev'
			end
			if className then
				table.insert(cell, mw.html.create 'span':addClass(className):wikitext(stringify(cond)))
			end
		end
	end

	local texts = {}
	local rowFormat = '|-\n|[[%s]]' .. ('||%s'):rep(3)
	local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
	for id, row in pairs(view) do
		local song = mSong[id]
		local packItem = mad.packQueryWrap(song.set, 'mobile')
		local rowText = {}
		for i = 1, 3 do
			local cell = row[i]
			if not cell or #cell == 0 then
				rowText[i] = ' '
			else
				rowText[i] = mw.allToString(unpack(cell))
			end
		end
		table.insert(texts, {
			data = rowFormat:format(mLink[id], unpack(rowText)),
			pack = packItem['name'],
			sort = {sectionCode[packItem['section']], packItem['numero'], song.date},
		})
	end

	table.sort(texts, function(a, b)
		a, b = a.sort, b.sort
		for i = 1, 3 do
			local d = a[i] - b[i]
			if d ~= 0 then return d < 0 end
		end
		return false
	end)

	local hybrid = {}
	local pack
	for _, value in ipairs(texts) do
		if pack ~= value.pack then
			pack = value.pack
			table.insert(hybrid, '|-\n| colspan="4" |' .. pack)
		end
		table.insert(hybrid, value.data)
	end

	return table.concat(hybrid, '\n')
end

return p