Module:Currency Image

From RuneRealm Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Currency Image/doc. [edit] [history] [purge]
Module:Currency Image is required by Module:Currencies.
Module:Currency Image is required by Module:DropsLine.
Module:Currency Image is required by Module:Sandbox/User:Kelsey/StoreLine.
Module:Currency Image is required by Module:Sandbox/User:PeaceBear0/Store locations list.

This module is a helper module to be used by other modules; it may not designed to be invoked directly. See RuneScape:Lua/Helper modules for a full list and more information. For a full list of modules using this helper click here

FunctionTypeUse
(name, quantity)StringIdentifies the proper filename to use for each respective currency type, including if different images apply for differing amounts.

name is the case insensitive currency name.

quantity is a number, or comma-separated string of numbers, the maximum of which will be used.

Supported currency names

abyssal pearls
agility arena ticket
anima-infused bark
archaic emblem
archery ticket
barronite shards
blood money
brimhaven voucher
castle wars ticket
coins
death runes
ecto-tokens
frog token
golden nugget
hallowed mark
league points
mark of grace
mermaid's tear
minnow
molch pearl
numulite
pieces of eight
platinum tokens
shark
speedrun points
stardust
survival tokens
termites
tokkul
trading sticks
twisted league points
unidentified minerals
warrior guild tokens

-- Static table to map currency names to filename and available quantities
local lookup = {
	['abyssal pearls'] = { filename = 'Abyssal_pearls_%d.png', bins = { 1, 2, 3, 4, 5 } },
	['barronite shards'] = { filename = 'Barronite_shards_%d.png', bins = { 1, 2, 3, 4, 5, 10, 25 } },
	['blood money'] = { filename = 'Blood_money_%d.png', bins = { 1, 2, 3, 4, 5, 25, 100, 250, 1000, 10000 } },
	['coins'] = { filename = 'Coins_%d.png', bins = { 1, 2, 3, 4, 5, 25, 100, 250, 1000, 10000 } },
	['ecto-tokens'] = { filename = 'Ecto-token_%d.png', bins = { 1, 2, 3 } },
	['hallowed mark'] = { filename = 'Hallowed_mark_%d.png', bins = { 1, 2, 3, 4, 5, 25 } },
	['mermaid\'s tear'] = { filename = 'Mermaid\'s_tear_%d.png', bins = { 1, 2, 3, 4, 5 } },
	['minnow'] = { filename = 'Minnow_%d.png', bins = { 1, 2, 3, 4, 5 } },
	['molch pearl'] = { filename = 'Molch_pearl_%d.png', bins = { 1, 2, 3, 4, 5 } },
	['numulite'] = { filename = 'numulite_%d.png', bins = { 1, 2, 3, 4, 5, 25 } },
	['pieces of eight'] = { filename = 'Pieces_of_eight_%d.png', bins = { 1, 2, 3 } },
	['platinum tokens'] = { filename = 'Platinum_token_%d.png', bins = { 1, 2, 3, 4, 5 } },
	['stardust'] = { filename = 'Stardust_%d.png', bins = { 1, 25, 75, 125, 175 } },
	['survival tokens'] = { filename = 'Survival_token_%d.png', bins = { 1, 2, 3, 4, 5 } },
	['trading sticks'] = { filename = 'Trading_sticks_%d.png', bins = { 1, 10, 100, 1000, 10000 } },
	['tokkul'] = { filename = 'Tokkul_%d.png', bins = { 1, 2, 3, 4, 5, 25 } },
	['warrior guild tokens'] = { filename = 'Warrior_guild_token_%d.png', bins = { 1, 2, 3, 4, 5 } },
	['runerealm credits'] = { filename = '%d_RuneRealm_Credits.png', bins = { 10, 100, 300, 500, 700, 1000, 2500, 5000, 7500, 10000, 20000 } },
	['afk-tokens'] = { filename = 'Afk-token_%d.png', bins = { 1, 2, 3 } },
}

local lookup_fixed = {
	['agility arena ticket'] = {filename = 'Agility arena ticket.png'},
	['anima-infused bark'] = {filename = 'Anima-infused_bark.png'},
	['archaic emblem'] = {filename = 'Archaic_emblem_(tier_1).png'},
	['archery ticket'] = {filename = 'Archery_ticket.png'},
	['brimhaven voucher'] = {filename = 'Brimhaven_voucher.png'},
	['castle wars ticket'] = {filename = 'Castle_wars_ticket.png'},
	['deadman points'] = { filename = 'Skull (Deadman Mode) icon.png' },
	['death runes'] = {filename = 'Death_rune.png'},
	['frog token'] = {filename = 'Frog token.png'},
	['golden nugget'] = {filename = 'Golden_nugget.png'},
	['league points'] = {filename = 'League Points.png'},
	['mark of grace'] = {filename = 'Mark_of_grace.png'},
	['shark'] = {filename = 'Shark.png'},
	['speedrun points'] = {filename = 'Giant stopwatch.png'},
	['twisted league points'] = {filename = 'Twisted League icon.png'},
	['unidentified minerals'] = {filename = 'Unidentified_minerals.png'},
	['termites'] = {filename = 'Termites.png'},
	['runerealm credits'] = { filename = '10_RuneRealm_Credits.png' },
}

--
-- Like Module:Coins image, but for multiple currency types
--
return function(name, quantity)
	quantity = mw.text.split(tostring(quantity or ''),'[,%-–]')
	local q = 1
	for _, v in ipairs(quantity) do
		if (tonumber(v) or 0) > q then
			q = tonumber(v)
		end
	end
	
	name = string.lower(name or '')
	
	local info = lookup[name]
	if info == nil then
		info = lookup_fixed[name]
		if info == nil then
			-- Unrecognized currency type
			return
		end
		return info.filename
	end
	local max_q = q
	for _, j in ipairs( info.bins ) do
		if q >= j then
			max_q = j
		else
			break
		end
	end
	return string.format(info.filename, max_q)
end

--[[ DEBUG USAGE
=p('agility arena ticket', 5)
=p('coins', 500)
]]

-- If this module ever gets refactored to be able to be called directly by
-- templates, this can be exposed to self-document what is supported.
--[[ 
local GetSupportedCurrencyNames = function()
	
	local supportedCurrencyNames = {}
	
	for k, _ in pairs( lookup ) do
		table.insert(supportedCurrencyNames, k)
	end
	
	for k, _ in pairs( lookup_fixed ) do
		table.insert(supportedCurrencyNames, k)
	end
	
	table.sort(supportedCurrencyNames)
	
	local supportedCurrencyNamesFormatted = table.concat(supportedCurrencyNames,"\r\n")
	return supportedCurrencyNamesFormatted
end
--]]