Module:Unlock:修订间差异
(Unlocks) |
小 (emm) |
||
第19行: | 第19行: | ||
}, { | }, { | ||
__call = function(self, args) | __call = function(self, args) | ||
return string.gsub(self[args.type] or "", "%$[a-z12_]+", function(k) | return (string.gsub(self[args.type] or "", "%$[a-z12_]+", function(k) | ||
k = k:sub(2) | k = k:sub(2) | ||
if self[k] then return self[k](args[k]) end | if self[k] then return self[k](args[k]) end | ||
if tonumber(k) then return self(args.conditions[tonumber(k)]) end | if tonumber(k) then return self(args.conditions[tonumber(k)]) end | ||
return args[k] | return args[k] | ||
end) | end)) | ||
end | end | ||
}) | }) | ||
第38行: | 第38行: | ||
i = i + 1 | i = i + 1 | ||
until ware[i].songId ~= key | until ware[i].songId ~= key | ||
if ware[i].songId == "lasteternity" then i = i + 4 end-- | if ware[i].songId == "lasteternity" then i = i + 4 end -- | ||
return key, arr | return key, arr | ||
end | end | ||
end | end | ||
function p.single(id) | function p.single(frame) | ||
local id = frame.args.id or slstIdx[mw.title.getCurrentTitle().text] | |||
local stringify = function(songv) | |||
local r = {} | |||
for _, v in ipairs(songv or {}) do table.insert(r, p.condition(v)) end | |||
return table.concat(r, "<br>") | |||
end | |||
--- unlocks song k/v : | --- unlocks song k/v : | ||
for songk, songv in unlocksIt(unlocks) do | for songk, songv in unlocksIt(unlocks) do | ||
if id == songk then return songv end | if id == songk then return mw.getCurrentFrame():expandTemplate { title = "解禁方法", args = { | ||
["PST解禁方法"] = stringify(songv[1]), | |||
["PRS解禁方法"] = stringify(songv[2]), | |||
["FTR解禁方法"] = stringify(songv[3]), | |||
} } | |||
end | |||
end | end | ||
end | end | ||
第68行: | 第79行: | ||
if key then | if key then | ||
row[key][rate] = row[key][rate] or {} | row[key][rate] = row[key][rate] or {} | ||
table.insert(row[key][rate], | table.insert(row[key][rate], p.condition(cond)) | ||
end | end | ||
end | end |
2022年9月18日 (日) 20:53的版本
可在Module:Unlock/doc创建此模块的帮助文档
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({
song_id = function(v) return "[[" .. slstIdx[v].title .. "]]" end,
song_difficulty = function(v) return "[" .. ({ [0] = "PST", "PRS", "FTR", "BYD" })[v] .. "]" end,
grade = function(v) return v == 0 and "" or ("以 「%s」 或以上成绩"):format(({ "C", "B", "A", "AA", "EX" })[v]) end,
rating = function(v) return ("%.2f"):format(v / 100) end,
id = function() return "[[拉格兰]]" end,
[0] = "$credit 残片",
"$grade通关 $song_id $song_difficulty",
"游玩 $song_id $song_difficulty",
"$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)
local i, key = 1, nil
return function()
if ware[i].songId == "" then return end
local arr = {}
key = ware[i].songId
repeat
table.insert(arr, ware[i].ratingClass + 1, ware[i].conditions)
i = i + 1
until ware[i].songId ~= key
if ware[i].songId == "lasteternity" then i = i + 4 end --
return key, arr
end
end
function p.single(frame)
local id = frame.args.id or slstIdx[mw.title.getCurrentTitle().text]
local stringify = function(songv)
local r = {}
for _, v in ipairs(songv or {}) do table.insert(r, p.condition(v)) end
return table.concat(r, "<br>")
end
--- unlocks song k/v :
for songk, songv in unlocksIt(unlocks) do
if id == songk then return mw.getCurrentFrame():expandTemplate { title = "解禁方法", args = {
["PST解禁方法"] = stringify(songv[1]),
["PRS解禁方法"] = stringify(songv[2]),
["FTR解禁方法"] = stringify(songv[3]),
} }
end
end
end
local detail = {}
function p.detail(frame)
if next(detail) then return detail[frame.args[1]] end
local inter = { fragment = {}, previous = {}, potential = {}, partner = {} }
function type2Key(t)
if t == 0 then return "fragment"
elseif t < 5 then return "previous"
elseif t == 5 then return "potential"
elseif t == 103 then return "partner"
end
end
for songk, songv in unlocksIt(unlocks) do
local row = { fragment = {}, previous = {}, potential = {}, partner = {} }
for rate = 1, 3 do
for _, cond in ipairs(songv[rate] or {}) do
local key = type2Key(cond.type)
if key then
row[key][rate] = row[key][rate] or {}
table.insert(row[key][rate], p.condition(cond))
end
end
end
for key, kind in pairs(row) do
if kind[3] then
table.insert(inter[key], {
table.concat(kind[1] or { " " }, "<br>"),
table.concat(kind[2] or { " " }, "<br>"),
table.concat(kind[3], "<br>"), id = songk
})
end
end
end
local slst = mw.loadData "Module:songlist index".slst
local plst = mw.loadData "Module:packlist index"
for key, songs in pairs(inter) do
table.sort(songs, function(a, b)
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 else return slst[slstIdx[a.id].idx].date < slst[slstIdx[b.id].idx].date end
end)
--- wikitable
local wtb, pid = {}, ""
for _, song in ipairs(songs) do
if pid ~= slst[slstIdx[song.id].idx].set then
pid = slst[slstIdx[song.id].idx].set
table.insert(wtb, '|-\n| colspan="4" |[[' .. plst[pid].name .. "]]")
end
table.insert(wtb, table.concat({ "|-\n|[[" .. slstIdx[song.id].title .. "]]", unpack(song) }, "||"))
end
detail[key] = table.concat({
'{| class="wikitable mw-collapsible mw-collapsed" style="text-align:center"',
"|-\n!曲目!!Past!!Present!!Future",
table.concat(wtb, "\n"),
"|}"
}, "\n")
end
return detail[frame.args[1]]
end
return p