Module:Unlock:修订间差异

来自Arcaea中文维基
(摩耶)
(新想法)
第1行: 第1行:
local mad = require 'Module:AnotherData'
local p = {}
local p = {}
local slstIdx = mw.loadData 'Module:songlist index'.slstIdx
local unlocks = mw.text.jsonDecode(mw.title.new 'Template:unlocks.json':getContent()).unlocks;
(function(u)u[14], u[15], u[16], u[17] = u[16], u[14], u[17], u[15]; table.insert(u, {songId = ''})end)(unlocks)


local eDifficulty = {[0] = 'PST', 'PRS', 'FTR', 'BYD'}
local linkPool = {}
local eGrade = {'C', 'B', 'A', 'AA', 'EX'}
local mLink = {}
local mPartner = {[45] = '拉格兰', [71] = '摩耶'}
local mSong = {}
p.condition = setmetatable({
for _, song in ipairs(mad.listOf 'songs') do
song_id = function(v) return '[[' .. slstIdx[v].title .. ']]' end,
local query = mad.songQueryWrap(song)
song_difficulty = function(v) return '[' .. eDifficulty[v] .. ']' end,
local link = query.linkTitle
grade = function(v) return v == 0 and '' or (' 以 「%s」 或以上成绩'):format(eGrade[v]) end,
linkPool[link] = true
rating = function(v) return v > 15 and ('%.2f'):format(v / 100) or v end,
mSong[song.id] = song
id = function(v) return '[[' .. mPartner[v] .. ']]' end,
mLink[song.id] = link
ratingPlus = function(v) return v and '+' or '' end,
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 残片',
[0] = '$credit 残片',
'$grade通关 $song_id $song_difficulty',
'$grade通关 $song_id $song_difficulty',
第21行: 第36行:
'个人游玩潜力值 $rating 或以上',
'个人游玩潜力值 $rating 或以上',
'通关$count首$rating$ratingPlus难度曲目',
'通关$count首$rating$ratingPlus难度曲目',
[103] = ' 获得搭档 $id 」'
}
}, {
local handlers = {}
__call = function(self, args)
local linkize = '[[%s]]'
return (string.gsub(self[args.type] or '', '%$[a-zA-Z12_]+', function(k)
function handlers.song_id(v) return linkize:format(mLink[v]) end
k = k:sub(2)
function handlers.song_difficulty(v) return ({[0] = '[PST]', '[PRS]', '[FTR]', '[BYD]'})[v] end
if self[k] then return self[k](args[k]) end
function handlers.grade(v) return v == 0 and '' or (' 以  %s 或以上成绩'):format(({'C', 'B', 'A', 'AA', 'EX'})[v]) end
if tonumber(k) then return self(args.conditions[tonumber(k)]) end
function handlers.rating(v) return v > 13 and ('%.2f'):format(v / 100) or v end
return args[k]
function handlers.ratingPlus(v) return v and '+' or '' end
end))
local function stringify(cond)
end
local res = 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)
return res
end


local function unlocksIt(ware)
local names = {'frag', 'prev', 'ptt'}
local i, key = 1, nil
local function judgeCond(type)
return function()
if type == 0 then
if ware[i].songId == '' then return end
return 'frag'
local arr = {}
elseif type == 5 then
key = ware[i].songId
return 'ptt'
repeat
elseif type <= 100 then
table.insert(arr, ware[i].ratingClass + 1, ware[i].conditions)
return 'prev'
i = i + 1
until ware[i].songId ~= key
if ware[i].songId == 'lasteternity' then i = i + 4 end --
return key, arr
end
end
end
local function createRow(res)
for _, k in ipairs(names) do res[k] = 0 end
return res
end
local function judgeRow(row)
local res = {'ulk'}
for _, k in ipairs(names) do if row[k] > 0 then table.insert(res, k) end end
return res
end
end


function p.single(frame)
function p.main()
local id = slstIdx[frame.args[1] or frame:getParent():getTitle()].id
local view = {}
local stringify = function(songv)
for _, chartUlk in ipairs(mad.listOf 'unlocks') do
local r = {}
local id, rc = chartUlk.songId, chartUlk.ratingClass + 1
for _, v in ipairs(songv or {}) do table.insert(r, p.condition(v)) end
for _, cond in ipairs(chartUlk.conditions) do
return table.concat(r, '<br>')
local className = judgeCond(cond.type)
end
if className then
--- unlocks song k/v :
local row = view[id]
for songk, songv in unlocksIt(unlocks) do
if not row then
if id == songk then
row = createRow {}
return frame:expandTemplate {title = '解禁方法', args = {
view[id] = row
['PST解禁方法'] = stringify(songv[1]),
end
['PRS解禁方法'] = stringify(songv[2]),
row[className] = row[className] + 1
['FTR解禁方法'] = stringify(songv[3]),
local cell = row[rc]
}}
if not cell then
cell = {}
row[rc] = cell
end
table.insert(cell, tostring(mw.html.create 'span':addClass 'ulk':addClass(className):wikitext(stringify(cond))))
end
end
end
end
end
end


function p.world(frame)
local texts = {}
local world = mw.title.new(' 世界模式地图详表 (移动版' .. frame.args[1] .. ')'):getContent()
local rowFormat = '|-%s\n|[[%s]]' .. ('||%s'):rep(3)
local res = {}
local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
for name, wtb in world:gmatch '== *([^B].-) *==[^={]+(%b{})' do
for id, row in pairs(view) do
local tot
local song = mSong[id]
for stair, reward in wtb:gmatch '| *(%d+)[0-9()%-| ]+(%b[])' do
local packItem = mad.packQueryWrap(song.set, 'mobile')
if slstIdx[reward:sub(3, -3)] then
local rowText = {}
tot = tot or wtb:match '| *(%d+)[^\n]+\n|%-\n| *总计'
for i = 1, 3 do
table.insert(res, ('|-\n|%s||%s||%d/%d'):format(reward, name, tonumber(stair) - 1, tonumber(tot) - 1))
local cell = row[i]
if not cell or #cell == 0 then
rowText[i] = ' '
else
rowText[i] = table.concat(cell, '<br>')
end
end
end
end
local classList = judgeRow(row)
if id == 'lasteternity' then classList = {'ulk'} end
table.insert(texts, {
data = rowFormat:format(('class="%s"'):format(table.concat(classList, ' ')), mLink[id], unpack(rowText)),
cls = classList,
pack = packItem['name'],
sort = {sectionCode[packItem['section']], packItem['numero'], song.date},
})
end
end
return table.concat(res, '\n')
end


local detail = {}
table.sort(texts, function(a, b)
function p.detail(frame)
a, b = a.sort, b.sort
if next(detail) then return detail[frame.args[1]] end
for i = 1, 3 do
local inter = {fragment = {}, previous = {}, potential = {}, partner = {}}
local d = a[i] - b[i]
function type2Key(t)
if d ~= 0 then return d < 0 end
if t == 0 then
return 'fragment'
elseif t < 5 then
return 'previous'
elseif t == 5 then
return 'potential'
elseif t == 103 then
return 'partner'
end
end
end
return false
end)


for songk, songv in unlocksIt(unlocks) do
local hybrid = {}
local row = {fragment = {}, previous = {}, potential = {}, partner = {}}
local pack
for rate = 1, 3 do
local idx
for _, cond in ipairs(songv[rate] or {}) do
local row = createRow {}
local key = type2Key(cond.type)
for _, value in ipairs(texts) do
if key then
if pack ~= value.pack then
row[key][rate] = row[key][rate] or {}
pack = value.pack
table.insert(row[key][rate], p.condition(cond))
table.insert(hybrid, '|-class="%s"\n| colspan="4" |' .. pack)
end
if idx then
hybrid[idx] = hybrid[idx]:format(table.concat(judgeRow(row), ' '))
end
end
idx = #hybrid
row = createRow {}
end
end
for key, kind in pairs(row) do
table.insert(hybrid, value.data)
if kind[3] then
for _, cls in ipairs(value.cls) do
table.insert(inter[key], {
for _, k in ipairs(names) do
table.concat(kind[1] or {' '}, '<br>'),
if k == cls then
table.concat(kind[2] or {' '}, '<br>'),
row[k] = row[k] + 1
table.concat(kind[3], '<br>'),
end
id = songk
})
end
end
end
end
end
end
local slst = mw.loadData 'Module:songlist index'.slst
if idx then
local plst = mw.loadData 'Module:packlist index'
hybrid[idx] = hybrid[idx]:format(table.concat(judgeRow(row), ' '))
for key, songs in pairs(inter) do
table.sort(songs, function(a, b)
local d = plst[slst[slstIdx[a.id].idx].set].idx - plst[slst[slstIdx[b.id].idx].set].idx
if d ~= 0 then return d < 0 else return slst[slstIdx[a.id].idx].date < slst[slstIdx[b.id].idx].date end
end)
--- wikitable
local wtb, pid = {}, ''
for _, song in ipairs(songs) do
if pid ~= slst[slstIdx[song.id].idx].set then
pid = slst[slstIdx[song.id].idx].set
table.insert(wtb, '|-\n| colspan="4" |[[' .. plst[pid].name .. ']]')
end
table.insert(wtb, table.concat({'|-\n|[[' .. slstIdx[song.id].title .. ']]', unpack(song)}, '||'))
end
detail[key] = table.concat(wtb, '\n')
end
end
return detail[frame.args[1]]
 
return table.concat(hybrid, '\n')
end
end


return p
return p

2024年2月25日 (日) 04:14的版本

可在Module:Unlock/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)
	local res = 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)
	return res
end

local names = {'frag', 'prev', 'ptt'}
local function judgeCond(type)
	if type == 0 then
		return 'frag'
	elseif type == 5 then
		return 'ptt'
	elseif type <= 100 then
		return 'prev'
	end
end
local function createRow(res)
	for _, k in ipairs(names) do res[k] = 0 end
	return res
end
local function judgeRow(row)
	local res = {'ulk'}
	for _, k in ipairs(names) do if row[k] > 0 then table.insert(res, k) end end
	return res
end

function p.main()
	local view = {}
	for _, chartUlk in ipairs(mad.listOf 'unlocks') do
		local id, rc = chartUlk.songId, chartUlk.ratingClass + 1
		for _, cond in ipairs(chartUlk.conditions) do
			local className = judgeCond(cond.type)
			if className then
				local row = view[id]
				if not row then
					row = createRow {}
					view[id] = row
				end
				row[className] = row[className] + 1
				local cell = row[rc]
				if not cell then
					cell = {}
					row[rc] = cell
				end
				table.insert(cell, tostring(mw.html.create 'span':addClass 'ulk':addClass(className):wikitext(stringify(cond))))
			end
		end
	end

	local texts = {}
	local rowFormat = '|-%s\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] = table.concat(cell, '<br>')
			end
		end
		local classList = judgeRow(row)
		if id == 'lasteternity' then classList = {'ulk'} end
		table.insert(texts, {
			data = rowFormat:format(('class="%s"'):format(table.concat(classList, ' ')), mLink[id], unpack(rowText)),
			cls = classList,
			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
	local idx
	local row = createRow {}
	for _, value in ipairs(texts) do
		if pack ~= value.pack then
			pack = value.pack
			table.insert(hybrid, '|-class="%s"\n| colspan="4" |' .. pack)
			if idx then
				hybrid[idx] = hybrid[idx]:format(table.concat(judgeRow(row), ' '))
			end
			idx = #hybrid
			row = createRow {}
		end
		table.insert(hybrid, value.data)
		for _, cls in ipairs(value.cls) do
			for _, k in ipairs(names) do
				if k == cls then
					row[k] = row[k] + 1
				end
			end
		end
	end
	if idx then
		hybrid[idx] = hybrid[idx]:format(table.concat(judgeRow(row), ' '))
	end

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

return p