Tangled Wiki
Advertisement

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

-- <nowiki>
local p = {}
 
-- Load the episodes
local episodes = mw.loadData('Module:TabSwitch/data')
 
-- Substitutes a number to the corresponding episode, or vice versa
function p._main(arg)
    local numarg = tonumber(arg)
    if numarg then
        if episodes[numarg] then
            return episodes[numarg]
        else
            return "N/A"
        end
    else
        for i, v in ipairs(episodes) do
            if v == arg then
                return i
            end
        end
        return "N/A"
    end
end
 
-- For use in templates
function p.main(frame)
    return p._main(frame.args[1])
end
 
-- Get the relative episode based on the episode given
-- Diff is the amount of episodes between the given episode
-- and the episode that should be returned
--
-- For most common uses, diff = 1 will return the next episode
-- and diff = -1 will return the previous episode
function p._relativeEpisode(episode, diff)
    local epNum = p._main(episode)
    -- check if it is a number
    if tonumber(epNum) then
        return p._main(epNum + diff)
    else
        return "N/A"
    end
end
 
-- For use in templates
function p.relativeEpisode(frame)
    return p._relativeEpisode(frame.args[1], frame.args[2])
end
 
return p
-- </nowiki>
Advertisement