Roblox Wiki
Roblox Wiki
mNo edit summary
mNo edit summary
Line 33: Line 33:
 
local a = "was"
 
local a = "was"
 
if st == "available" or st == "still available" then a = "is" end
 
if st == "available" or st == "still available" then a = "is" end
if l == "ingame" or l == "in-game" or l == "in game" or l == "game" then
+
if l == "ingame" or l == "in-game" or l == "in game" or l == "game" or l == "event" then
 
return '<span class="explain" title="This item '..a..' received in a Roblox game.">In-game</span>'..categorize("Items obtained in a game")
 
return '<span class="explain" title="This item '..a..' received in a Roblox game.">In-game</span>'..categorize("Items obtained in a game")
 
elseif l == "catalog" then
 
elseif l == "catalog" then

Revision as of 01:43, 1 June 2020

This module implements the {{Availability history}} template.

Messages used by the module, including categories, can be viewed and edited at Module:Availability history/i18n.


local categorization = require("Module:Categorization")
local utils = require("Module:Utils")

local categorize = categorization.categorize_in_namespaces(0, 'Catalog')

local p = {}

function p._format_status(args)
	local s = string.lower(args.status)
	if s == "available" or s == "still available" or s == "for sale" then
	    return "Available"
	elseif s == "limited" or s == "limitedu" or s == "limited item" then
	    return "Available (Limited)"
    elseif s == "off-sale" or s == "offsale" or s == "not available" or s == "unavailable" or s == "unobtainable" then
        return "Unavailable"
    elseif s == "redeemable" or s == "redeem" then
        return "Redeemable"
    elseif s == "unknown" then
        return "Unknown"
    else
        return error("Invalid status parameter.  Must be 'available', 'off-sale', 'redeemable', or 'unknown'.")
	end
end

p.format_status = utils.make_wrapper_function(p._format_status)

function p._format_location(args)
	local l = string.lower(args.location)
	if not args["until"] then
	    return error("until parameter is required")
	end
	local st = string.lower(args["until"])
	local a = "was"
	if st == "available" or st == "still available" then a = "is" end
	if l == "ingame" or l == "in-game" or l == "in game" or l == "game" or l == "event" then
	    return '<span class="explain" title="This item '..a..' received in a Roblox game.">In-game</span>'..categorize("Items obtained in a game")
	elseif l == "catalog" then
	    return '<span class="explain" title="This item '..a..' purchasable in the catalog.">Catalog</span>'..categorize("Items obtained in the avatar shop")
	elseif l == "limited" or l == "limitedu" or l == "limited item" then
	    return '<span class="explain" title="This item '..a..' purchasable in the catalog and can be resold by owners.">Catalog (Limited) </span>'..categorize("Items obtained in the avatar shop")
	elseif l == "promotional code" or l == "promotional-code" or l == "promotional" or l == "promotionalcode" then
	    return '<span class="explain" title="This item '..a..' received through a promotional code.">Promotional Code</span>'..categorize("Items obtained with a promotional code")
	elseif l == "ad" or l == "advertisement" or l == "advert" then
	    return '<span class="explain" title="This item '..a..' received through an online advertisement.">Advertisement</span>'..categorize("Items obtained from a Roblox advertisement")
    elseif l == "opened" or l == "gift" or l == "gifted" then
        return '<span class="explain" title="This item '..a..' received through a Roblox gift.">Opened</span>'..categorize('Items that came out of gifts')
    elseif l == "gamecard" or l == "game card" or l == "game-card" or l == "roblox card" then
        return '<span class="explain" title="This item '..a..' received through a Roblox game card.">Roblox Card</span>'..categorize('Gamecard items')
    elseif l == "select" or l == "select user" or l == "select users" then
        return '<span class="explain" title="This item '..a..' awarded to specific users.">Select Users</span>'..categorize('Items awarded to specific users')
    elseif l == "toy" or l == "roblox toy" or l == "toy code" then
        return '<span class="explain" title="This item '..a..' received through a Roblox toy code.">Toy Code</span>'..categorize('Toy items')
    elseif l == "bundle item" or l == "bundle" then
        return '<span class="explain" title="This item is part of a bundle.">Bundle item</span>'..categorize('Bundle items')
    else
        return args.location
	end
end

p.format_location = utils.make_wrapper_function(p._format_location)


-- TEST
p._generate_table = function(args)
    local str = [[{|border="1" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;"
!Location
!Available from
!Available until
|-]]
    local location = {}
    local from = {}
    local unt = {}
    for k,v in pairs(args) do
        local i = tonumber(k)
        if (i-1)%3 == 0 then
            table.insert(location,v)
        elseif (i-1)%3 == 1 then
            table.insert(from,v)
        elseif (i-1)%3 == 2 then
            table.insert(unt,v)
        end
    end
    
    for i,v in pairs(location) do
        if not unt[i] or not from[i] then
            return '<span style="color:red">Warning: Missing parameters. Please ensure that the amount of parameters in the template is a multiple of 3 (location, from, until, location, from, until, ...)</span>'
        end
        str = str .. '\n| style="text-align:center;"|'.. p._format_location({location=v,['until']=unt[i]}) .. '\n| style="text-align:center;"|' .. from[i] .. '\n| style="text-align:center;"|' .. unt[i] .. '\n|-'
    end
    return str .. "\n|}"
end

p.generate_table = utils.make_wrapper_function(p._generate_table)

return p