Module:maimai Difficulty: Difference between revisions

From SilentBlue.RemyWiki
Jump to navigation Jump to search
imported>Jack980517
No edit summary
imported>Jack980517
No edit summary
Line 13: Line 13:
         result = result .. "difficulty rated "
         result = result .. "difficulty rated "
     end
     end
     if VerToNum({"maimai", args[#args]}) <= 2 then
     if VerToNum({"maimai", args[2]}) <= 2 then
        -- ugly hack; #args can't be used, and since there's (currently) no songs removed in _~_+ and revived later, the only use case is 舞萌 songs.
         result = result .. "."
         result = result .. "."
     elseif VerToNum({"maimai", args[1]}) <= 2 then
     elseif VerToNum({"maimai", args[1]}) <= 2 then

Revision as of 08:19, 9 April 2021

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

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

function p.maimai_difficulty_multi(frame)
    args=frame:getParent().args
    mw.logObject(args)
    local result = "maimai "
    if VerToNum({"maimai", args[1]}) <= 2 then
        result = result .. "to PLUS difficulty rated from 1 to 10"
    else
        result = result .. "difficulty rated "
    end
    if VerToNum({"maimai", args[2]}) <= 2 then
        -- ugly hack; #args can't be used, and since there's (currently) no songs removed in _~_+ and revived later, the only use case is 舞萌 songs.
        result = result .. "."
    elseif VerToNum({"maimai", args[1]}) <= 2 then
        result = result .. ", "
    end
    local version_range_borders = {3, 9, 13, 15} -- first range already dealt with above
    local i = 0
    local in_range = {}
    for i = 1, #version_range_borders do
        in_range[i] = false
    end
    local ranges_text = {
        "1 to 12 from GreeN to PiNK PLUS",
        "1 to 13 from MURASAKi to MiLK PLUS",
        "1 to 14 from FiNALE to でらっくす",
        "1 to 15 from でらっくす PLUS onwards"
    }
    local j = 1
    for i = 1, #args, 2 do
        local startver = args[i]
        local endver = ""
        if i ~= #args then
            endver = args[i + 1]
        end
        -- print('start = ' .. startver .. ' end = ' .. endver)
        local startvernum = VerToNum({"maimai", startver})
        local endvernum = 99
        if endver ~= "" then
            endvernum = VerToNum({"maimai", endver})
        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 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:maimai Songs]]"
    if #args % 2 == 0 then
        result = result .. "[[Category:maimai Removed Songs]]"
    end
    return result
end

return p