Module:Unlock:修订间差异

来自Arcaea中文维基
(摩耶)
(TODO:Designant.;TableTools#invert)
 
(未显示同一用户的9个中间版本)
第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,
  if not song.deleted then
song_difficulty = function(v) return '[' .. eDifficulty[v] .. ']' end,
   local link = mad.linkTitle(song)
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
[0] = '$credit 残片',
end
'$grade通关 $song_id $song_difficulty',
'游玩 $song_id $song_difficulty',
'$grade通关 $song_id $song_difficulty$times回',
"$1 <br>'''或''' $2",
'个人游玩潜力值 $rating 或以上',
'通关$count首$rating$ratingPlus难度曲目',
[103] = '获得搭档「$id」'
}, {
__call = function(self, args)
return (string.gsub(self[args.type] or '', '%$[a-zA-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 templates = {
local id = slstIdx[frame.args[1] or frame:getParent():getTitle()].id
  [104] = '<small><i>Axiom</i></small>',
local stringify = function(songv)
  [105] = '<small><i>Eternity</i></small>',
local r = {}
  [106] = '<small><i>Moment</i></small>',
for _, v in ipairs(songv or {}) do table.insert(r, p.condition(v)) end
  [107] = '<small><i>Magnolia</i></small>',
return table.concat(r, '<br>')
  [108] = '连接她们的故事(15-6|16-6)',
end
  [110] = '<small><i>Course</i></small>',
--- unlocks song k/v :
  [111] = '阅读剧情【18-6】',
for songk, songv in unlocksIt(unlocks) do
  [112] = '得到你所渴求的',
if id == songk then
}
return frame:expandTemplate {title = ' 解禁方法', args = {
local handlers = {}
['PST解禁方法'] = stringify(songv[1]),
 
['PRS 禁方法'] = stringify(songv[2]),
function templates.t0(c) return ('%s 残片'):format(c.credit) end
['FTR解禁方法'] = stringify(songv[3]),
function templates.t1(c)
}}
  return c.grade <= 0
end
    and ('通关 %s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty))
end
    or ('以 「%s」 或以上成绩通关 %s [%s]'):format(handlers.grade(c.grade), handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty))
end
function templates.t2(c) return ('游玩 %s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty)) end
function templates.t3(c) return templates.t1(c) .. (' %s回'):format(c.times) end
function templates.t4(c) return ('%s<br><b>或</b> %s'):format(handlers.stringify(c.conditions[1]), handlers.stringify(c.conditions[2])) end
function templates.t5(c) return ('个人游玩潜力值 %s 或以上'):format(handlers.rating(c.rating)) end
function templates.t6(c)
  return c.grade <= 0
    and (' 通关%s首%s%s难度曲目'):format(c.count, c.rating, handlers.ratingPlus(c.ratingPlus))
    or (' 以「%s」或更高的成绩通关%s次难度%s%s的曲目'):format(handlers.grade(c.grade), c.count, c.rating, handlers.ratingPlus(c.ratingPlus))
end
function templates.t7(c) return ('解 锁%s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty)) end
function templates.t8(c) return ('FULL RECALL通关%s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty)) end
function templates.t9(c)
  return c.grade <= 0
    and ('通关%s次%s曲目'):format(c.count, handlers.difficulty(c.difficulty))
    or ('以「%s」或更高的成绩通关%s次%s曲目'):format(handlers.grade(c.grade), c.count, handlers.difficulty(c.difficulty))
end
end
function templates.t10(c) return ('阅读剧情【%s-%s】'):format(c.major, c.minor) end
function templates.t101(c) return ('<small><i>Gauge:%s%%-%s%%</i></small>'):format(c.min, c.max) end
function templates.t103(c) return ('选择搭档「[[%s]]」'):format(handlers.id(c.id)) end
function templates.t109(c) return ('于%s%s上刻下真名'):format(handlers.index(c.index), handlers.difficulty(c.difficulty)) end


function p.world(frame)
function handlers.song_id(v) return ('[[%s]]'):format(mLink[v]) end
local world = mw.title.new(' 世界模式地图详表 (移动版' .. frame.args[1] .. ')'):getContent()
function handlers.difficulty(v) return ({[0] = 'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[v] end
local res = {}
function handlers.grade(v) return ({'C', 'B', 'A', 'AA', 'EX', 'EX+'})[v] end
for name, wtb in world:gmatch '== *([^B].-) *==[^={]+(%b{})' do
function handlers.rating(v) return ('%.2f'):format(v / 100) end
local tot
function handlers.ratingPlus(v) return v and '+' or '' end
for stair, reward in wtb:gmatch '| *(%d+)[0-9()%-| ]+(%b[])' do
function handlers.id(v) return ({[45] = '拉格兰', [71] = '摩耶'})[v] end
if slstIdx[reward:sub(3, -3)] then
function handlers.index(v) return ({[0] = '[T]ec[h]nicolour', 'UNKNOW[N] LEVEL[S]', 'E[g]o E[i]m[i]'})[v] end
tot = tot or wtb:match '| *(%d+)[^\n]+\n|%-\n| *总计'
local function stringify(cond)
table.insert(res, ('|-\n|%s||%s||%d/%d'):format(reward, name, tonumber(stair) - 1, tonumber(tot) - 1))
  local template = templates['t' .. cond.type]
end
  if type(template) == 'function' then return template(cond) end
end
  template = templates[cond.type]
end
  if type(template) == 'string' then return template end
return table.concat(res, '\n')
  return (' 不支持的解锁类型号:' .. cond.type)
end
end
function handlers.stringify(v) return stringify(v) end


local detail = {}
local function createView()
function p.detail(frame)
  local res = {}
if next(detail) then return detail[frame.args[1]] end
  for _, chartUlk in ipairs(mad.listOf 'unlocks') do
local inter = {fragment = {}, previous = {}, potential = {}, partner = {}}
   local id = chartUlk.songId
function type2Key(t)
   local song = res[id]
if t == 0 then
   if not song then
return 'fragment'
    song = {group = mSong[id].set, link = mLink[id]}
elseif t < 5 then
    res[id] = song
return 'previous'
   end
elseif t == 5 then
   local chart = {ratingClass = chartUlk.ratingClass}
return 'potential'
   table.insert(song, chart)
elseif t == 103 then
   for _, cond in ipairs(chartUlk.conditions) do table.insert(chart, stringify(cond)) end
return 'partner'
  end
end
  return res
end
end


for songk, songv in unlocksIt(unlocks) do
local function createText(view)
local row = {fragment = {}, previous = {}, potential = {}, partner = {}}
  local sectionCode = {unknown = 0, single = 1, free = 2, mainstory2 = 4, mainstory = 3, sidestory = 5, collab = 6}
for rate = 1, 3 do
  local uis = {}
for _, cond in ipairs(songv[rate] or {}) do
  for id, row in pairs(view) do
local key = type2Key(cond.type)
   local packItem = mad.packQueryWrap(row.group)
if key then
   table.insert(uis, {id = id, name = packItem['name'], sectionCode[packItem['section']], packItem['numero'], mSong[id].date})
row[key][rate] = row[key][rate] or {}
  end
table.insert(row[key][rate], p.condition(cond))
  table.sort(uis, function(a, b)
end
   for i = 1, 3 do
end
    local d = a[i] - b[i]
end
    if d ~= 0 then return d < 0 end
for key, kind in pairs(row) do
   end
if kind[3] then
   return false
table.insert(inter[key], {
  end)
table.concat(kind[1] or {' '}, '<br>'),
  local classes = {
table.concat(kind[2] or {' '}, '<br>'),
   [0] = {'PAST', 'text-pst'},
table.concat(kind[3], '<br>'),
   {'PRESENT', 'text-prs'},
id = songk
   {'FUTURE',  'text-ftr'},
})
   {'BEYOND',  'text-byd'},
end
   {'ETERNAL', 'text-etr'},
end
  }
end
  local function chart(cursor, o)
local slst = mw.loadData 'Module:songlist index'.slst
   local text, class = unpack(classes[o.ratingClass])
local plst = mw.loadData 'Module:packlist index'
   cursor:tag 'dt':addClass(class):wikitext(text)
for key, songs in pairs(inter) do
   for _, i in ipairs(o) do cursor:tag 'dd':wikitext(i) end
table.sort(songs, function(a, b)
  end
local d = plst[slst[slstIdx[a.id].idx].set].idx - plst[slst[slstIdx[b.id].idx].set].idx
  local function song(cursor, o)
if d ~= 0 then return d < 0 else return slst[slstIdx[a.id].idx].date < slst[slstIdx[b.id].idx].date end
   local ch = cursor:tag 'tr'
end)
     :tag 'td':css('text-align', 'center'):wikitext('[[', o.link, ']]'):done()
--- wikitable
     :tag 'td':tag 'dl':css('column-count', #o)
local wtb, pid = {}, ''
   for _, i in ipairs(o) do chart(ch, i) end
for _, song in ipairs(songs) do
  end
if pid ~= slst[slstIdx[song.id].idx].set then
  local pack
pid = slst[slstIdx[song.id].idx].set
  local res = mw.html.create 'table':addClass 'wikitable mw-collapsible mw-collapsed'
table.insert(wtb, '|-\n| colspan="4" |[[' .. plst[pid].name .. ']]')
    :tag 'tr'
end
    :tag 'th':wikitext '曲目':done()
table.insert(wtb, table.concat({'|-\n|[[' .. slstIdx[song.id].title .. ']]', unpack(song)}, '||'))
    :tag 'th':wikitext ' 解锁条件':done()
end
    :done()
detail[key] = table.concat(wtb, '\n')
  for _, value in ipairs(uis) do
end
   if pack ~= value.name then
return detail[frame.args[1]]
    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
end


return p
return p

2024年12月24日 (二) 23:36的最新版本

可在Module:Unlock/doc创建此模块的帮助文档

local mad = require 'Module:AnotherData'
local p = {}

local linkPool = {}
local mLink = {}
local mSong = {}
for _, song in ipairs(mad.listOf 'songs') do
  if not song.deleted then
    local link = mad.linkTitle(song)
    linkPool[link] = true
    mSong[song.id] = song
    mLink[song.id] = link
  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 = {
  [104] = '<small><i>Axiom</i></small>',
  [105] = '<small><i>Eternity</i></small>',
  [106] = '<small><i>Moment</i></small>',
  [107] = '<small><i>Magnolia</i></small>',
  [108] = '连接她们的故事(15-6|16-6)',
  [110] = '<small><i>Course</i></small>',
  [111] = '阅读剧情【18-6】',
  [112] = '得到你所渴求的',
}
local handlers = {}

function templates.t0(c) return ('%s 残片'):format(c.credit) end
function templates.t1(c)
  return c.grade <= 0
      and ('通关 %s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty))
      or ('以 「%s」 或以上成绩通关 %s [%s]'):format(handlers.grade(c.grade), handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty))
end
function templates.t2(c) return ('游玩 %s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty)) end
function templates.t3(c) return templates.t1(c) .. (' %s回'):format(c.times) end
function templates.t4(c) return ('%s<br><b>或</b> %s'):format(handlers.stringify(c.conditions[1]), handlers.stringify(c.conditions[2])) end
function templates.t5(c) return ('个人游玩潜力值 %s 或以上'):format(handlers.rating(c.rating)) end
function templates.t6(c)
  return c.grade <= 0
      and ('通关%s首%s%s难度曲目'):format(c.count, c.rating, handlers.ratingPlus(c.ratingPlus))
      or ('以「%s」或更高的成绩通关%s次难度%s%s的曲目'):format(handlers.grade(c.grade), c.count, c.rating, handlers.ratingPlus(c.ratingPlus))
end
function templates.t7(c) return ('解锁%s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty)) end
function templates.t8(c) return ('FULL RECALL通关%s [%s]'):format(handlers.song_id(c.song_id), handlers.difficulty(c.song_difficulty)) end
function templates.t9(c)
  return c.grade <= 0
      and ('通关%s次%s曲目'):format(c.count, handlers.difficulty(c.difficulty))
      or ('以「%s」或更高的成绩通关%s次%s曲目'):format(handlers.grade(c.grade), c.count, handlers.difficulty(c.difficulty))
end
function templates.t10(c) return ('阅读剧情【%s-%s】'):format(c.major, c.minor) end
function templates.t101(c) return ('<small><i>Gauge:%s%%-%s%%</i></small>'):format(c.min, c.max) end
function templates.t103(c) return ('选择搭档「[[%s]]」'):format(handlers.id(c.id)) end
function templates.t109(c) return ('于%s%s上刻下真名'):format(handlers.index(c.index), handlers.difficulty(c.difficulty)) end

function handlers.song_id(v) return ('[[%s]]'):format(mLink[v]) end
function handlers.difficulty(v) return ({[0] = 'PST', 'PRS', 'FTR', 'BYD', 'ETR'})[v] end
function handlers.grade(v) return ({'C', 'B', 'A', 'AA', 'EX', 'EX+'})[v] end
function handlers.rating(v) return ('%.2f'):format(v / 100) end
function handlers.ratingPlus(v) return v and '+' or '' end
function handlers.id(v) return ({[45] = '拉格兰', [71] = '摩耶'})[v] end
function handlers.index(v) return ({[0] = '[T]ec[h]nicolour', 'UNKNOW[N] LEVEL[S]', 'E[g]o E[i]m[i]'})[v] end
local function stringify(cond)
  local template = templates['t' .. cond.type]
  if type(template) == 'function' then return template(cond) end
  template = templates[cond.type]
  if type(template) == 'string' then return template end
  return ('不支持的解锁类型号:' .. cond.type)
end
function handlers.stringify(v) return stringify(v) 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, mainstory2 = 4, mainstory = 3, sidestory = 5, collab = 6}
  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