Module:Unlock:修订间差异
小 (新想法) |
小 (放弃) |
||
第28行: | 第28行: | ||
end | 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 = { | local templates = { | ||
[0] = '$credit 残片', | [0] = '$credit 残片', | ||
第38行: | 第55行: | ||
} | } | ||
local handlers = {} | 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.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.grade(v) return v == 0 and '' or ('以 「%s」 或以上成绩'):format(({'C', 'B', 'A', 'AA', 'EX'})[v]) end | ||
第53行: | 第69行: | ||
return res | return res | ||
end | end | ||
local function createView() | |||
local res = {} | |||
local function | |||
local res | |||
for _, chartUlk in ipairs(mad.listOf 'unlocks') do | for _, chartUlk in ipairs(mad.listOf 'unlocks') do | ||
local id, rc = chartUlk.songId, chartUlk.ratingClass + 1 | local id, rc = chartUlk.songId, chartUlk.ratingClass + 1 | ||
for _, cond in ipairs(chartUlk.conditions) do | for _, cond in ipairs(chartUlk.conditions) do | ||
local className = | local className = nameOf(cond.type) | ||
if className then | if className then | ||
local | local view = getOrSet(res, className) | ||
local row = getOrSet(view, id) | |||
local cell = getOrSet(row, rc) | |||
table.insert(cell, stringify(cond)) | |||
local cell = row | |||
table.insert(cell, | |||
end | end | ||
end | 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 | for id, row in pairs(view) do | ||
local song = mSong[id] | local song = mSong[id] | ||
第106行: | 第95行: | ||
for i = 1, 3 do | for i = 1, 3 do | ||
local cell = row[i] | 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 | ||
end | end | ||
table.sort(res, function(a, b) | |||
table.sort( | |||
a, b = a.sort, b.sort | a, b = a.sort, b.sort | ||
for i = 1, 3 do | for i = 1, 3 do | ||
第130行: | 第113行: | ||
return false | return false | ||
end) | 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 hybrid = {} | ||
local pack | local pack | ||
for _, value in ipairs(texts) do | for _, value in ipairs(texts) do | ||
if pack ~= value.pack then | if pack ~= value.pack then | ||
pack = value.pack | pack = value.pack | ||
table.insert(hybrid, '|- | table.insert(hybrid, '|-\n| colspan="4" |' .. pack) | ||
end | end | ||
table.insert(hybrid, value.data) | table.insert(hybrid, value.data) | ||
end | end | ||
return table.concat(hybrid, '\n') | return table.concat(hybrid, '\n') | ||
end | end | ||
return p | return p |
2024年2月25日 (日) 12:41的版本
可在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 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 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 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, 'mobile')
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