Module:ONGEKI Difficulty: Difference between revisions

From SilentBlue.RemyWiki
Jump to navigation Jump to search
imported>Jack980517
(Created page with "-- オンゲキ difficulty rated from 1 to 14+. local p={} local function VerToNum(args) return tonumber(mw.text.trim(mw.getCurrentFrame():expandTemplate{title='VerToNum',arg...")
 
m (Protected "Module:ONGEKI Difficulty": structural page ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- オンゲキ difficulty rated from 1 to 14+.
local p={}
local p={}
local function VerToNum(args)
local function VerToNum(args)
Line 5: Line 4:
end
end


function p.chunithm_difficulty_multi(frame)
function p.ongeki_difficulty_multi(frame)
     args=frame:getParent().args
     args=frame:getParent().args
    local version_range_borders = {6,8}
     local result = "オンゲキ "
     local result = "オンゲキ "
     if VerToNum({"ongeki", args[1]}) <= 5 then
     if VerToNum({"ongeki", args[1]}) < version_range_borders[1] then
         result = result .. "to R.E.D. difficulty rated from 1 to 14+, "
         result = result .. "to R.E.D. difficulty rated from 1 to 14+, "
     else
     else
Line 14: Line 14:
     end
     end
     -- since #args can't be used, and there's no removals in R.E.D. and older anyway (except ikazuchi nazo which doesn't use this template), i'm removing the period, and moving the comma to the above branch
     -- since #args can't be used, and there's no removals in R.E.D. and older anyway (except ikazuchi nazo which doesn't use this template), i'm removing the period, and moving the comma to the above branch
    local version_range_borders = {6} -- first range already dealt with above
     -- although there's only two ranges, the loops below shall remain to be future-proof
     -- although there's only two ranges, the loops below shall remain to be future-proof
     local i = 0
     local i = 0
Line 22: Line 21:
     end
     end
     local ranges_text = {
     local ranges_text = {
         "1 to 15 from R.E.D. PLUS onwards"
         "1 to 15 from R.E.D. PLUS to bright",
        "1 to 15+ from bright MEMORY onwards"
     }
     }
     local j = 1
     local j = 1
Line 49: Line 49:
         end
         end
     end
     end
     if #included_ranges == 1 and VerToNum({"ongeki", args[1]}) <= 3 then -- first range special case
     if #included_ranges == 1 and VerToNum({"ongeki", args[1]}) < version_range_borders[1] then -- first range special case
         result = result .. "and " .. ranges_text[included_ranges[1]] .. "."
         result = result .. "and " .. ranges_text[included_ranges[1]] .. "."
         -- print(result)
         -- print(result)

Latest revision as of 00:07, 24 June 2023

Documentation for this module may be created at Module:ONGEKI Difficulty/doc

local p={}
local function VerToNum(args)
	return tonumber(mw.text.trim(mw.getCurrentFrame():expandTemplate{title='VerToNum',args=args}))
end

function p.ongeki_difficulty_multi(frame)
    args=frame:getParent().args
    local version_range_borders = {6,8}
    local result = "オンゲキ "
    if VerToNum({"ongeki", args[1]}) < version_range_borders[1] then
        result = result .. "to R.E.D. difficulty rated from 1 to 14+, "
    else
        result = result .. "difficulty rated "
    end
    -- since #args can't be used, and there's no removals in R.E.D. and older anyway (except ikazuchi nazo which doesn't use this template), i'm removing the period, and moving the comma to the above branch
    -- although there's only two ranges, the loops below shall remain to be future-proof
    local i = 0
    local in_range = {}
    for i = 1, #version_range_borders do
        in_range[i] = false
    end
    local ranges_text = {
        "1 to 15 from R.E.D. PLUS to bright",
        "1 to 15+ from bright MEMORY onwards"
    }
    local j = 1
    local endvernum = nil
    for i = 1, 99, 2 do -- again, ugly hack
        if args[i] == nil then break end
        local startvernum = VerToNum({"ongeki", args[i]})
        endvernum = VerToNum({"ongeki", args[i + 1]})
        if endvernum == nil then
            endvernum = 99
        end
        for j = 1, #version_range_borders do
            local cond = true
            if j + 1 <= #version_range_borders then
                cond = startvernum < version_range_borders[j + 1]
            end
            if endvernum >= version_range_borders[j] and cond then
                in_range[j] = true
            end
        end
    end
    local included_ranges = {}
    for j = 1, #in_range do
        if in_range[j] then
            table.insert(included_ranges, j)
        end
    end
    if #included_ranges == 1 and VerToNum({"ongeki", args[1]}) < version_range_borders[1] then -- first range special case
        result = result .. "and " .. ranges_text[included_ranges[1]] .. "."
        -- print(result)
    else
        for j = 1, #included_ranges do
            result = result .. ranges_text[included_ranges[j]]
            if j == #included_ranges then -- last range
                result = result .. "."
            elseif j == #included_ranges - 1 then -- second to last range
                result = result .. ", and "
            else
                result = result .. ", "
            end
        end
    end
    result = result .. "<br>[[Category:Songs]][[Category:ONGEKI Songs]]"
    if endvernum ~= 99 then
        result = result .. "[[Category:ONGEKI Removed Songs]]"
    end
    return result
end

return p