Module:Unlock:修订间差异

来自Arcaea中文维基
(oops)
(修复anotherdata影响)
 
(未显示2个用户的13个中间版本)
第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.getCurrentFrame():expandTemplate { title = "unlocks" }).unlocks
;(function(u) local _ = u[14]; u[14] = u[16]; u[16] = u[17]; u[17] = u[15]; u[15] = _; table.insert(u, { songId = "" }) end)(unlocks)


p.condition = setmetatable({
local linkPool = {}
song_id = function(v) return "[[" .. slstIdx[v].title .. "]]" end,
local mLink = {}
song_difficulty = function(v) return "[" .. ({ [0] = "PST", "PRS", "FTR", "BYD" })[v] .. "]" end,
local mSong = {}
grade = function(v) return v == 0 and "" or ("以 「%s」 或以上成绩"):format(({ "C", "B", "A", "AA", "EX" })[v]) end,
for _, song in ipairs(mad.listOf 'songs') do
rating = function(v) return ("%.2f"):format(v / 100) end,
local link = mad.linkTitle(song)
id = function() return "[[拉格兰]]" end,
linkPool[link] = true
[0] = "$credit 残片",
mSong[song.id] = song
"$grade通关 $song_id $song_difficulty",
mLink[song.id] = link
"游玩 $song_id $song_difficulty",
end
"$grade通关 $song_id $song_difficulty$times回",
"$1 <br>'''或''' $2",
"个人游玩潜力值 $rating 或以上",
[103] = "获得搭档「$id」"
}, {
__call = function(self, args)
return (string.gsub(self[args.type] or "", "%$[a-z12_]+", function(k)
k = k:sub(2)
if self[k] then return self[k](args[k]) end
if tonumber(k) then return self(args.conditions[tonumber(k)]) end
return args[k]
end))
end
})


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


function p.single(frame)
local function nameOf(type)
local id = slstIdx[frame.args[1]]
if type == 0 then
local stringify = function(songv)
return 'fragment'
local r = {}
elseif type == 5 then
for _, v in ipairs(songv or {}) do table.insert(r, p.condition(v)) end
return 'potential'
return table.concat(r, "<br>")
elseif type <= 100 then
return 'previous'
end
end
--- unlocks song k/v :
end
for songk, songv in unlocksIt(unlocks) do
local function getOrSet(t, k)
if id == songk then return frame:expandTemplate { title = "解禁方法", args = {
local v = t[k]
["PST解禁方法"] = stringify(songv[1]),
if not v then
["PRS解禁方法"] = stringify(songv[2]),
v = {}
["FTR解禁方法"] = stringify(songv[3]),
t[k] = v
} }
end
end
end
return v
end
end
 
local templates = {
local detail = {}
[0] = '$credit 残片',
function p.detail(frame)
'$grade通关 $song_id $song_difficulty',
if next(detail) then return detail[frame.args[1]] end
'游玩 $song_id $song_difficulty',
local inter = { fragment = {}, previous = {}, potential = {}, partner = {} }
'$grade通关 $song_id $song_difficulty$times回',
function type2Key(t)
"$1 <br>'''或''' $2",
if t == 0 then return "fragment"
'个人游玩潜力值 $rating 或以上',
elseif t < 5 then return "previous"
'通关$count首$rating$ratingPlus难度曲目',
elseif t == 5 then return "potential"
}
elseif t == 103 then return "partner"
local handlers = {}
function handlers.song_id(v) return ('[[%s]]'):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 template = templates[cond.type] or ('不支持的解锁类型号:' .. cond.type)
local res = template: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 createView()
local res = {}
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 = nameOf(cond.type)
if className then
local view = getOrSet(res, className)
local row = getOrSet(view, id)
local cell = getOrSet(row, rc)
table.insert(cell, stringify(cond))
end
end
end
end
end
for songk, songv in unlocksIt(unlocks) do
return res
local row = { fragment = {}, previous = {}, potential = {}, partner = {} }
end
for rate = 1, 3 do
local rowFormat = '|-\n|[[%s]]' .. ('||%s'):rep(3)
for _, cond in ipairs(songv[rate] or {}) do
local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
local key = type2Key(cond.type)
local function createText(view)
if key then
local res = {}
row[key][rate] = row[key][rate] or {}
for id, row in pairs(view) do
table.insert(row[key][rate], p.condition(cond))
local song = mSong[id]
end
local packItem = mad.packQueryWrap(song.set)
end
local rowText = {}
for i = 1, 3 do
local cell = row[i]
rowText[i] = (cell and #cell > 0) and table.concat(cell, '<br>') or ' '
end
end
for key, kind in pairs(row) do
if id ~= 'lasteternity' then
if kind[3] then
table.insert(res, {
table.insert(inter[key], {
data = rowFormat:format(mLink[id], unpack(rowText)),
table.concat(kind[1] or { " " }, "<br>"),
pack = packItem['name'],
table.concat(kind[2] or { " " }, "<br>"),
sort = {sectionCode[packItem['section']], packItem['numero'], song.date},
table.concat(kind[3], "<br>"), id = songk
})
})
end
end
end
end
end
local slst = mw.loadData "Module:songlist index".slst
table.sort(res, function(a, b)
local plst = mw.loadData "Module:packlist index"
a, b = a.sort, b.sort
for key, songs in pairs(inter) do
for i = 1, 3 do
table.sort(songs, function(a, b)
local d = a[i] - b[i]
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 end
if d ~= 0 then return d < 0 else return slst[slstIdx[a.id].idx].date < slst[slstIdx[b.id].idx].date end
end
end)
return false
--- wikitable
end)
local wtb, pid = {}, ""
return res
for _, song in ipairs(songs) do
end
if pid ~= slst[slstIdx[song.id].idx].set then
local views
pid = slst[slstIdx[song.id].idx].set
function p.detail(frame)
table.insert(wtb, '|-\n| colspan="4" |[[' .. plst[pid].name .. "]]")
views = views or createView()
end
local view = views[frame.args[1]]
table.insert(wtb, table.concat({ "|-\n|[[" .. slstIdx[song.id].title .. "]]", unpack(song) }, "||"))
local texts = createText(view)
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
end
detail[key] = table.concat({
table.insert(hybrid, value.data)
'{| class="wikitable mw-collapsible mw-collapsed" style="text-align:center"',
"|-\n!曲目!!Past!!Present!!Future",
table.concat(wtb, "\n"),
"|}"
}, "\n")
end
end
return detail[frame.args[1]]
return table.concat(hybrid, '\n')
end
end
return p
return p

2024年3月18日 (一) 11:42的最新版本

可在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 link = mad.linkTitle(song)
	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 function nameOf(type)
	if type == 0 then
		return 'fragment'
	elseif type == 5 then
		return 'potential'
	elseif type <= 100 then
		return 'previous'
	end
end
local function getOrSet(t, k)
	local v = t[k]
	if not v then
		v = {}
		t[k] = v
	end
	return v
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 = {}
function handlers.song_id(v) return ('[[%s]]'):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 template = templates[cond.type] or ('不支持的解锁类型号:' .. cond.type)
	local res = template: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 createView()
	local res = {}
	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 = nameOf(cond.type)
			if className then
				local view = getOrSet(res, className)
				local row = getOrSet(view, id)
				local cell = getOrSet(row, rc)
				table.insert(cell, stringify(cond))
			end
		end
	end
	return res
end
local rowFormat = '|-\n|[[%s]]' .. ('||%s'):rep(3)
local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
local function createText(view)
	local res = {}
	for id, row in pairs(view) do
		local song = mSong[id]
		local packItem = mad.packQueryWrap(song.set)
		local rowText = {}
		for i = 1, 3 do
			local cell = row[i]
			rowText[i] = (cell and #cell > 0) and table.concat(cell, '<br>') or ' '
		end
		if id ~= 'lasteternity' then
			table.insert(res, {
				data = rowFormat:format(mLink[id], unpack(rowText)),
				pack = packItem['name'],
				sort = {sectionCode[packItem['section']], packItem['numero'], song.date},
			})
		end
	end
	table.sort(res, 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)
	return res
end
local views
function p.detail(frame)
	views = views or createView()
	local view = views[frame.args[1]]
	local texts = createText(view)
	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