Module:沙盒/盐棋/Sandbox:修订间差异

删除1,134字节 、​ 2022年10月10日 (星期一)
no
(frame)
(no)
第1行: 第1行:
local p = {}
local p = {}
local slstIdx = mw.loadData "Module:沙盒/盐棋/Sandbox1".slstIdx
--=p.entry{plat={},id="kokoro",title="Heart",title2=" ",artist='<span lang="ja">-{削除 (Violin : Katali)}-</span>',pack="pack",duration=148.014626,bpm="80-160",bpm_base=80,ratings={1,5,9}}
local unlocks = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate { title = "unlocks" }).unlocks
function map(iter, fn)
;(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)
-- local dict = setmetatable({}, { __index = fn })
 
local ret = {}
p.condition = setmetatable({
for k, v in pairs(iter) do ret[k] = fn(v, k, ret) end
song_id = function(v) return "[[" .. slstIdx[v].title .. "]]" end,
return ret
song_difficulty = function(v) return "[" .. ({ [0] = "PST", "PRS", "FTR", "BYD" })[v] .. "]" end,
end
grade = function(v) return v == 0 and "" or ("以 「%s」 或以上成绩"):format(({ "C", "B", "A", "AA", "EX" })[v]) end,
function opt(format, value, default)
rating = function(v) return ("%.2f"):format(v / 100) end,
default = default or ""
id = function() return "[[拉格兰]]" end,
return value and format:format(tostring(value)) or default
[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
end
 
function p.entry(info)
function p.single(id)
if info.args then info = info.args end
--- unlocks song k/v :
if not string.find(info.duration, ":") then
for songk, songv in unlocksIt(unlocks) do
-- mw.language.getContentLanguage():formatDate("i:s", "@" .. info.duration)
if id == songk then return songv end
local t = tonumber(info.duration)
info.duration = math.floor(t / 60) .. ":" .. math.floor(t % 60)
end
end
for i = 1, 4 do info.ratings[i] = opt("%s", info.ratings[i], "/") end
return ("|-\n|%s||[[文件:Songs %s.jpg|75px]]||%s||%s||%s||%s||%s||%s"):format(
table.concat(info.plat), info.id,
"[[" .. info.title .. "]]" .. opt('<br /><span lang="ja">-{%s}-</span>', info.title2),
info.artist, info.pack,
opt("data-sort-value=%s|", info.bpm_base) .. info.bpm,
info.duration, table.concat(info.ratings, "||")
)
end
end
 
function p.main(frame)
local detail = {}
local slstIdx = mw.loadData "Module:songlist index".slstIdx
function p.detail(frame)
local plst = mw.loadData "Module:packlist index"
if next(detail) then return detail[frame.args[1]] end
local durs = mw.text.jsonDecode(mw.title.new "Template:duration.json":getContent())
local inter = { fragment = {}, previous = {}, potential = {}, partner = {} }
local details = {}
function type2Key(t)
for _, song in ipairs(mw.loadData "Module:songlist index".slst) do
if t == 0 then return "fragment"
if song.id ~= "lasteternity" then
elseif t < 5 then return "previous"
table.insert(details, {
elseif t == 5 then return "potential"
plat = { "[[文件:Icon Smartphone.png|16px|link=曲目列表 (移动版)]]" }, id = song.id,
elseif t == 103 then return "partner"
title = slstIdx[song.id].name, title2 = song.title_localized.ja or song.title_localized["zh-Hans"],
artist = '<span lang="ja">-{' .. song.artist .. "}-</span>", pack = plst[song.id],
bpm = song.bpm, bpm_base = tonumber(song.bpm) ~= song.bpm_base and song.bpm_base or nil,
duration = durs[song.id],
ratings = map(song.difficulties, function(v) return v.rating .. opt("+", v.ratingPlus) end),
date = song.date
})
end
end
end
end
for songk, songv in unlocksIt(unlocks) do
table.sort(details, function(a, b)
local row = { fragment = {}, previous = {}, potential = {}, partner = {} }
local d = math.abs(a.pack.idx) - math.abs(a.pack.idx)
for rate = 1, 3 do
if d ~= 0 then return d < 0 else return a.date < b.date end
for _, cond in ipairs(songv[rate] or {}) do
end)
local key = type2Key(cond.type)
for _, song in ipairs(details) do
if key then
song.pack = "[[" .. song.pack.name .. "]]"
row[key][rate] = row[key][rate] or {}
local ride = frame.args[song.id]
table.insert(row[key][rate], (p.condition(cond)))
if ride then for k, v in pairs(mw.text.jsonDecode(ride)) do song[k] = v end end
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:沙盒/盐棋/Sandbox1".slst
local plst = mw.loadData "Module:沙盒/盐棋/Sandbox2"
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
end
return detail[frame.args[1]]
return table.concat(map(details, function(v) return select(2, xpcall(p.entry, function() return "" end)) end))
end
end
return p
return p
2,525

个编辑