跳到内容

Module:Unlock:修订间差异

删除747字节 、​ 2024年2月25日 (星期日)
放弃
(新想法)
(放弃)
第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 = {}
local linkize = '[[%s]]'
function handlers.song_id(v) return ('[[%s]]'):format(mLink[v]) end
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.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 names = {'frag', 'prev', 'ptt'}
local res = {}
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
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 = judgeCond(cond.type)
local className = nameOf(cond.type)
if className then
if className then
local row = view[id]
local view = getOrSet(res, className)
if not row then
local row = getOrSet(view, id)
row = createRow {}
local cell = getOrSet(row, rc)
view[id] = row
table.insert(cell, stringify(cond))
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
end
end
end
 
return res
local texts = {}
end
local rowFormat = '|-%s\n|[[%s]]' .. ('||%s'):rep(3)
local rowFormat = '|-\n|[[%s]]' .. ('||%s'):rep(3)
local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
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]
if not cell or #cell == 0 then
rowText[i] = (cell and #cell > 0) and table.concat(cell, '<br>') or ' '
rowText[i] = ' '
end
else
if id ~= 'lasteternity' then
rowText[i] = table.concat(cell, '<br>')
table.insert(res, {
end
data = rowFormat:format(mLink[id], unpack(rowText)),
pack = packItem['name'],
sort = {sectionCode[packItem['section']], packItem['numero'], song.date},
})
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
 
table.sort(res, function(a, b)
table.sort(texts, function(a, b)
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
local idx
local row = createRow {}
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, '|-class="%s"\n| colspan="4" |' .. pack)
table.insert(hybrid, '|-\n| colspan="4" |' .. pack)
if idx then
hybrid[idx] = hybrid[idx]:format(table.concat(judgeRow(row), ' '))
end
idx = #hybrid
row = createRow {}
end
end
table.insert(hybrid, value.data)
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
end
return table.concat(hybrid, '\n')
return table.concat(hybrid, '\n')
end
end


return p
return p
2,544

个编辑