Difference between revisions of "Module:Availability/Sandbox"

From Team Fortress Wiki
Jump to: navigation, search
Line 49: Line 49:
 
['halloween-purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. tooltip(common_string('purchase'), common_string('purchase-halloween')) .. ']]' end,
 
['halloween-purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. tooltip(common_string('purchase'), common_string('purchase-halloween')) .. ']]' end,
 
['hauntedgift'] = function() return '[[Haunted Halloween Gift' .. if_lang .. '|' .. item_name('haunted halloween gift') .. ']]' end,
 
['hauntedgift'] = function() return '[[Haunted Halloween Gift' .. if_lang .. '|' .. item_name('haunted halloween gift') .. ']]' end,
['keyless-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Cosmetic Crates|' .. item_name('unlocked cosmetic crate') .. ']]' end,
+
['keyless-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Cosmetic Crates|' .. item_name('unlocked cosmetic crate') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
 
['mannup'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' end,
 
['mannup'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' end,
 
['mvm-both-types'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']] ' .. common_string('and') .. ' [[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
 
['mvm-both-types'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']] ' .. common_string('and') .. ' [[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,

Revision as of 10:50, 16 October 2016

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

local p = {}

-- Imports the function status(number), which returns whether or not a crate is Active or Retired. This is in a separate file so that it can be updated *without* staff intervention.
require('Module:Availability/crate')

-- Defined here so that it can be referenced inside the next three functions
local frame = nil

-- Expands the template Tooltip for a given pair of values.
function tooltip(tool, tip)
	return frame:expandTemplate{title='Tooltip', args={tool, tip}}
end

-- Expands the template Item name for a given value.
function item_name(arg)
	return frame:expandTemplate{title='Item name', args={arg}}
end

-- Expands the template Common string for a given value. Note that some common string values include an additional parameter, here called opt_arg.
function common_string(arg, opt_arg)
	return frame:expandTemplate{title='Common string', args={arg, opt_arg}}
end

function paren(text)
	if if_lang == '/zh_hans' or if_lang == '/zh-hant' then
		return '(' .. text .. ')'
	else
		return ' (' .. text .. ') '
	end
end

-- Replaces the old Dictionary/templatecore strings
	lookup = {
		-- Singleton strings (without a number)
		['audition-reel'] = function() return '[[Mann Co. Supply Crate/Seriesless_crates' .. if_lang .. '#Audition Reel|' .. common_string('audition reel') .. ']]' end,
		['australium'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
		['botkiller'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']]') end,
		['bread-box'] = function() return '[[Bread Box' .. if_lang .. '|' .. item_name('bread box') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
		['chemistryset'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' end,
		['collectors'] = function() return '[[Chemistry Set' .. if_lang .. '|' .. item_name('chemistry set') .. ']]' .. paren('[[Collectors' .. if_lang .. '|' .. item_name('collector\'s') .. ']]') end,
		['contract'] = function() return '[[Gun Mettle Campaign' .. if_lang .. '#Contracts|' .. common_string('contract') .. ']]' .. paren('[[Decorated' .. if_lang .. '|' .. item_name('decorated') .. ']]') end,
		['craft'] = function() return '[[Crafting' .. if_lang .. '|' .. common_string('craft') .. ']]' end,
		['crate-scorched'] = function() return '[[Mann Co. Supply Crate/Retired series' .. if_lang .. '#46|' .. common_string('uncrate') .. ' #46]]' .. paren(common_string('scorched')) end,
		['creepy-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Creepy Crates|' .. item_name('unlocked creepy crate') .. ']]' end,
		['directors'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Director\'s Cut|' .. common_string('director\'s cut') .. ']]' end,
		['distributed'] = function() return common_string('distributed') end,
		['drop'] = function() return '[[Item drop system' .. if_lang .. '|' .. common_string('drop') .. ']]' end,
		['gift-cauldron'] = function() return '[[Halloween Gift Cauldron' .. if_lang .. '|' .. item_name('halloween gift cauldron') .. ']]' end,
		['halloween-purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. tooltip(common_string('purchase'), common_string('purchase-halloween')) .. ']]' end,
		['hauntedgift'] = function() return '[[Haunted Halloween Gift' .. if_lang .. '|' .. item_name('haunted halloween gift') .. ']]' end,
		['keyless-crate'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Unlocked Cosmetic Crates|' .. item_name('unlocked cosmetic crate') .. ']]' .. paren('[[Unique' .. if_lang .. '|' .. item_name('unique') .. ']] ' .. common_string('and') .. ' [[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
		['mannup'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' end,
		['mvm-both-types'] = function() return '[[Mann Up' .. if_lang .. '|' .. common_string('reward') .. ']]' .. paren('[[Botkiller weapons' .. if_lang .. '|' .. common_string('botkiller') .. ']] ' .. common_string('and') .. ' [[Australium weapons' .. if_lang .. '|' .. common_string('australium') .. ']]') end,
		['mvm'] = function() return '[[Mann vs. Machine' .. if_lang .. '|' .. common_string('mvm reward') .. ']]' end,
		['promotional'] = function() return '[[Promotional items' .. if_lang .. '|' .. common_string('promotional') .. ']]' end,
		['purchase'] = function() return '[[Mann Co. Store' .. if_lang .. '|' .. common_string('purchase') .. ']]' end,
		['retired'] = function() return common_string('retired') end,
		['stock'] = function() return '[[Stock weapons' .. if_lang .. '|' .. mw.getContentLanguage():ucfirst(item_name('stock')) .. ']]' end,
		['stockpile'] = function() return '[[Mann Co. Supply Crate/Seriesless crates' .. if_lang .. '#Stockpile|' .. common_string('stockpile crate') .. ']]' end,
		['strangifier'] = function() return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]'.. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
		['unavailable'] = function() return common_string('unavailable') end,
		['unlock'] = function() return '[[Achievement items' .. if_lang .. '|' .. common_string('unlock') .. ']]' end,
		['unusual'] = function() return '[[Mann Co. Supply Crate' .. if_lang .. '|' .. common_string('uncrate') .. ']]' .. paren('[[Unusual' .. if_lang .. '|' .. item_name('unusual') .. ']]') end,

		-- Multipart strings (with a number)
		['xmas'] = function(num) return '[[Smissmas ' .. num .. ' Festive Gift' .. if_lang .. '|' .. item_name('smissmas ' .. num .. ' festive gift') .. ']]' end,
		['crate'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' end,
		['crate-strange'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']] ' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
		['crate-festive'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']] ' .. paren('[[Festive weapons' .. if_lang .. '|' .. item_name('festive') .. ']]') end,
		['crate-haunted'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']] ' .. paren('[[Haunted' .. if_lang .. '|' .. item_name('haunted') .. ']]') end,
		['crate-nohaunt'] = function(num) return '[[' .. status(num) .. if_lang .. '#' .. num .. '|' .. common_string('uncrate') .. ' #' .. num .. ']]' end,
		['strangifier-crate-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('uncrateable from series number crate', num)) .. '</sup>' .. paren('[[Strange' .. if_lang .. '|' .. item_name('strange') .. ']]') end,
		['strangifier-series-'] = function(num) return '[[Strangifier' .. if_lang .. '|' .. item_name('strangifier') .. ']]<sup>' .. tooltip('?', common_string('series number chemistry sets', num)) .. '</sup>' end,

}

-- Some strings that were present in Dictionary/availcore and thus might be used somewhere.
local backwards_compat = {
	['store'] = 'purchase',
	['achievement'] = 'unlock',
	['strangifier-strange'] = 'strangifier',

	['crate-naughty'] = 'crate35-festive',
	['crate-naughty2012'] = 'crate52-festive',
	['crate-naughty2013'] = 'crate78-festive',
	['crate-naughty2014'] = 'crate88-festive',
	['crate-nice'] = 'crate36',
	['crate-nice2012'] = 'crate53',
	['crate-nice2013'] = 'crate79',
	['crate-nice2014'] = 'crate89',
	['crate-strongbox'] = 'crate81'

}

function p.dummyargs(f)
	return f:getParent().args
end
function p.dummyargs2(f)
	return f:getParent().args[0]
end
function p.dummyargs3(f)
	return (next(f:getParent().args, nil) == nil)
end
function p.dummyargs4(f)
	count = 0
	for _ in pairs(f:getParent().args) do count = count + 1 end
	return (count == 0)
end
function p.dummyargs5(f)
	return f.args
end
function p.dummyargs6(f)
	return f.args[0]
end
function p.dummyargs7(f)
	return (next(f.args, nil) == nil)
end
function p.dummyargs8(f)
	count = 0
	for _ in pairs(f.args) do count = count + 1 end
	return (count == 0)
end




function p.avail(f)
	-- Precompute the page's language.
	frame = f
	local args = f:getParent().args
	if_lang = frame:expandTemplate{title='If lang'}

	-- Avail is called with a long list of arguments. Each one needs to be translated and comma-separated.
	avail_string = ''
	for i, arg in ipairs(args) do
		arg = mw.ustring.lower(arg)
		-- Backwards compatibility
		if backwards_compat[arg] ~= nil then
			avail_string = avail_string .. '[[Category:Outdated Availability Parameters]]'
			arg = backwards_compat[arg]
		end

		-- Crate 46 is a Scorched Crate, which is a string that isn't used anywhere else.
		if arg == 'crate46' then arg = 'crate-scorched' end
		-- Enchantment: Eternawen was uncratable from #74, and cannot be Haunted.
		if arg == 'crate74' then arg = 'crate74-haunted' end

		-- Matches strings like 'craft' 'crate1' 'crate26-strange'
		-- Strings like 'crate26-strange' become 'crate-strange' and '26'.
		name1, num, name2 = string.match(arg, '(%D*)(%d*)(%D*)')
		name = name1 .. name2

		if (args[i+2] ~= nil)
		or (args[i+1] ~= nil and args['availability'] ~= nil)
			then -- There are at least two arguments left in the list
			if if_lang == '/zh-hans' then
				avail_string = avail_string .. lookup[name](num) .. '、'
			elseif if_lang == '/zh-hant' then
				avail_string = avail_string .. lookup[name](num) .. ','
			else
				avail_string = avail_string .. lookup[name](num) .. ', '
			end
		elseif (args[i+1] ~= nil and args['availability'] == nil)
				or (args[i+1] == nil and args['availability'] ~= nil)
			then -- There is exactly one more argument in the list
			avail_string = avail_string .. lookup[name](num) .. ' ' .. common_string('or') .. ' '
		else -- args[i+1] == nil and args['availability] == nil
			avail_string = avail_string .. lookup[name](num)
		end
	end -- End looping through arguments.
	if args['availability'] ~= nil then
		avail_string = avail_string .. args['availability']
	end

	return avail_string
end

return p