Module:Unlock:修订间差异

来自Arcaea中文维基
(修复anotherdata影响)
(暂定)
第6行: 第6行:
local mSong = {}
local mSong = {}
for _, song in ipairs(mad.listOf 'songs') do
for _, song in ipairs(mad.listOf 'songs') do
local link = mad.linkTitle(song)
  local link = mad.linkTitle(song)
linkPool[link] = true
  linkPool[link] = true
mSong[song.id] = song
  mSong[song.id] = song
mLink[song.id] = link
  mLink[song.id] = link
end
end


function p.world(frame)
function p.world(frame)
local world = mw.title.new('世界模式地图详表 (移动版' .. frame.args[1] .. ')'):getContent()
  local world = mw.title.new('世界模式地图详表 (移动版' .. frame.args[1] .. ')'):getContent()
local res = {}
  local res = {}
for name, wtb in world:gmatch '== *([^B].-) *==[^={]+(%b{})' do
  for name, wtb in world:gmatch '== *([^B].-) *==[^={]+(%b{})' do
local tot
   local tot
for stair, reward in wtb:gmatch '| *(%d+)[0-9()%-| ]+(%b[])' do
   for stair, reward in wtb:gmatch '| *(%d+)[0-9()%-| ]+(%b[])' do
if linkPool[reward:sub(3, -3)] then
    if linkPool[reward:sub(3, -3)] then
tot = tot or tonumber(wtb:match '| *(%d+)[^\n]+\n|%-\n| *总计') - 1
     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))
     table.insert(res, ('|-\n|%s||%s||%d/%d'):format(reward, name, tonumber(stair) - 1, tot))
end
    end
end
   end
end
  end
return table.concat(res, '\n')
  return table.concat(res, '\n')
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 残片',
'$grade通关 $song_id $song_difficulty',
  '$grade通关 $song_id $song_difficulty',
'游玩 $song_id $song_difficulty',
  '游玩 $song_id $song_difficulty',
'$grade通关 $song_id $song_difficulty$times回',
  '$grade通关 $song_id $song_difficulty$times回',
"$1 <br>'''或''' $2",
  "$1 <br>'''或''' $2",
'个人游玩潜力值 $rating 或以上',
  '个人游玩潜力值 $rating 或以上',
'通关$count首$rating$ratingPlus难度曲目',
  '通关$count首$rating$ratingPlus难度曲目',
}
}
local handlers = {}
local handlers = {}
第60行: 第43行:
function handlers.ratingPlus(v) return v and '+' or '' end
function handlers.ratingPlus(v) return v and '+' or '' end
local function stringify(cond)
local function stringify(cond)
local template = templates[cond.type] or ('不支持的解锁类型号:' .. cond.type)
  local template = templates[cond.type] or '???'--('不支持的解锁类型号:' .. cond.type)
local res = template:gsub('%$([a-zA-Z12_]+)', function(k)
  local res = template:gsub('%$([a-zA-Z12_]+)', function(k)
local nk = tonumber(k)
   local nk = tonumber(k)
if nk then return stringify(cond.conditions[nk]) end
   if nk then return stringify(cond.conditions[nk]) end
if handlers[k] then return handlers[k](cond[k]) end
   if handlers[k] then return handlers[k](cond[k]) end
return cond[k]
   return cond[k]
end)
  end)
return res
  return res
end
end
local function createView()
local function createView()
local res = {}
  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 = chartUlk.songId
for _, cond in ipairs(chartUlk.conditions) do
   local song = res[id]
local className = nameOf(cond.type)
   if not song then
if className then
    song = {group = mSong[id].set, link = mLink[id]}
local view = getOrSet(res, className)
    res[id] = song
local row = getOrSet(view, id)
   end
local cell = getOrSet(row, rc)
   local chart = {ratingClass = chartUlk.ratingClass}
table.insert(cell, stringify(cond))
   table.insert(song, chart)
end
   for _, cond in ipairs(chartUlk.conditions) do table.insert(chart, stringify(cond)) end
end
  end
end
  return res
return res
end
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 function createText(view)
local res = {}
  local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
for id, row in pairs(view) do
  local uis = {}
local song = mSong[id]
  for id, row in pairs(view) do
local packItem = mad.packQueryWrap(song.set)
   local packItem = mad.packQueryWrap(row.group)
local rowText = {}
   table.insert(uis, {id = id, name = packItem['name'], sectionCode[packItem['section']], packItem['numero'], mSong[id].date})
for i = 1, 3 do
  end
local cell = row[i]
  table.sort(uis, function(a, b)
rowText[i] = (cell and #cell > 0) and table.concat(cell, '<br>') or ' '
   for i = 1, 3 do
end
    local d = a[i] - b[i]
if id ~= 'lasteternity' then
    if d ~= 0 then return d < 0 end
table.insert(res, {
   end
data = rowFormat:format(mLink[id], unpack(rowText)),
   return false
pack = packItem['name'],
  end)
sort = {sectionCode[packItem['section']], packItem['numero'], song.date},
  local classes = {
})
   [0] = {'PAST', 'text-pst'},
end
   {'PRESENT', 'text-prs'},
end
   {'FUTURE',  'text-ftr'},
table.sort(res, function(a, b)
   {'BEYOND',  'text-byd'},
a, b = a.sort, b.sort
   {'ETERNAL', 'text-etr'},
for i = 1, 3 do
  }
local d = a[i] - b[i]
  local function chart(cursor, o)
if d ~= 0 then return d < 0 end
   local text, class = unpack(classes[o.ratingClass])
end
   cursor:tag 'dt':addClass(class):wikitext(text)
return false
   for _, i in ipairs(o) do cursor:tag 'dd':wikitext(i) end
end)
  end
return res
  local function song(cursor, o)
   local ch = cursor:tag 'tr'
     :tag 'td':css('text-align', 'center'):wikitext('[[', o.link, ']]'):done()
     :tag 'td':tag 'dl':css('column-count', #o)
   for _, i in ipairs(o) do chart(ch, i) end
  end
  local pack
  local res = mw.html.create 'table':addClass 'wikitable mw-collapsible mw-collapsed'
    :tag 'tr'
    :tag 'th':wikitext '曲目':done()
    :tag 'th':wikitext '解锁条件':done()
    :done()
  for _, value in ipairs(uis) do
   if pack ~= value.name then
    pack = value.name
    res:tag 'tr':tag 'th':attr('colspan', '2'):wikitext(pack)
   end
   song(res, view[value.id])
  end
  return res
end
end
local views
function p.detail()
function p.detail(frame)
  return tostring(createText(createView()))
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
end


return p
return p

2024年8月6日 (二) 10:33的版本

可在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 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 = chartUlk.songId
    local song = res[id]
    if not song then
      song = {group = mSong[id].set, link = mLink[id]}
      res[id] = song
    end
    local chart = {ratingClass = chartUlk.ratingClass}
    table.insert(song, chart)
    for _, cond in ipairs(chartUlk.conditions) do table.insert(chart, stringify(cond)) end
  end
  return res
end

local function createText(view)
  local sectionCode = {unknown = 0, single = 1, free = 2, mainstory = 3, sidestory = 4, collab = 5}
  local uis = {}
  for id, row in pairs(view) do
    local packItem = mad.packQueryWrap(row.group)
    table.insert(uis, {id = id, name = packItem['name'], sectionCode[packItem['section']], packItem['numero'], mSong[id].date})
  end
  table.sort(uis, function(a, b)
    for i = 1, 3 do
      local d = a[i] - b[i]
      if d ~= 0 then return d < 0 end
    end
    return false
  end)
  local classes = {
    [0] = {'PAST', 'text-pst'},
    {'PRESENT', 'text-prs'},
    {'FUTURE',  'text-ftr'},
    {'BEYOND',  'text-byd'},
    {'ETERNAL', 'text-etr'},
  }
  local function chart(cursor, o)
    local text, class = unpack(classes[o.ratingClass])
    cursor:tag 'dt':addClass(class):wikitext(text)
    for _, i in ipairs(o) do cursor:tag 'dd':wikitext(i) end
  end
  local function song(cursor, o)
    local ch = cursor:tag 'tr'
        :tag 'td':css('text-align', 'center'):wikitext('[[', o.link, ']]'):done()
        :tag 'td':tag 'dl':css('column-count', #o)
    for _, i in ipairs(o) do chart(ch, i) end
  end
  local pack
  local res = mw.html.create 'table':addClass 'wikitable mw-collapsible mw-collapsed'
      :tag 'tr'
      :tag 'th':wikitext '曲目':done()
      :tag 'th':wikitext '解锁条件':done()
      :done()
  for _, value in ipairs(uis) do
    if pack ~= value.name then
      pack = value.name
      res:tag 'tr':tag 'th':attr('colspan', '2'):wikitext(pack)
    end
    song(res, view[value.id])
  end
  return res
end
function p.detail()
  return tostring(createText(createView()))
end

return p