Module:沙盒/盐棋/Sandbox

来自Arcaea中文维基
< Module:沙盒
盐棋讨论 | 贡献2022年9月15日 (四) 23:48的版本 (slightly)

可在Module:沙盒/盐棋/Sandbox/doc创建此模块的帮助文档

local p = {}
local null = require('Module:Nullish')
local unlocks = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'unlocks' }).unlocks

p.condition = setmetatable({
    song_id = function(v) return "[[" .. mw.loadData('Module:沙盒/盐棋/Sandbox1')[v][2] .. "]]" 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 '''或''' $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
})

p.single = function(id)
    function UnlocksIt(ware)
        local i, key = 1, nil
        return function()
            if not ware[i] 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] / null).songId ~= key
            return key, arr
        end
    end
    -- unlocks k/v
    for ukey, uval in UnlocksIt(unlocks) do
        if id == ukey then return uval end
    end
end
return p