Difference between revisions of "Module:Currency"

From Nookipedia, the Animal Crossing wiki
m (fixing parameters)
(importing formatnum directly via Lua instead of being preprocessed)
Line 2: Line 2:
  
 
function p.outputCurrency (frame)
 
function p.outputCurrency (frame)
 +
local formatnum
 
local num = frame.args['2']
 
local num = frame.args['2']
 
local function isEmpty(s)
 
local function isEmpty(s)
Line 31: Line 32:
 
print = print .. '|link=|alt=]]'
 
print = print .. '|link=|alt=]]'
 
if not isEmpty(num) then
 
if not isEmpty(num) then
print = print .. ' ' .. frame:preprocess('{{#invoke:formatnum|main|lang=en|' .. num .. '}}')
+
formatnum = require("Module:Formatnum")
 +
print = print .. ' ' .. formatnum.formatNum(frame.args['2'],"en")
 
end
 
end
 
end
 
end

Revision as of 14:48, March 21, 2022

Module documentation (view)


Usage

This Lua module outputs the currency and its price for the {{Currency}} template to account for preprocessor node count limits. Data is stored in a table, and can determine how certain variables are used.

Portions of the module uses Module:Formatnum, see module for more information.

Inserting a new currency

["name_of_currency"] = { "currency_image", "currency_image_size", "link_to_currency", "name_of_currency", "short_name_of_currency" }

When adding a new currency to be used on pages, the following syntax must be inserted into the main data table.

  • name_of_currency describes the name of the currency that the editor will write in the Currency template. There is also a second instance of name_of_source, which can also feature a different text to its first instance.
  • currency_image requires an image (preferably an icon) to be added. It must include the filename extension.
  • currency_image_size describes the default size that currency_image will be presented in.
  • link_to_currency describes the link that the player will click on (provided that the link is present).
  • short_name_of_currency describes a shorter name of the currency when applying the short parameter on the main Currency template.

Example

["Bells"] = { "99k Bells NH Inv Icon cropped.png", "15px", "Bell", "Bell", "Bell" }

"Bells" is the name_of_currency, while "Bell" functions as the second instance of name_of_source, link_to_currency, and short_name_of_currency. Its currency_image is "99k Bells NH Inv Icon cropped.png", and the currency_image_size is set to "15px".

The output is: Bells

["Nook Miles"] = { "Nook Miles NH Icon Cropped.png", "18px", "Nook Miles", "Nook Mile", "Mile" }

"Nook Mile" is the name_of_currency and link_to_currency, while "Nook Mile" functions as the second instance of name_of_source. Its short_name_of_currency is "Mile". Its currency_image is "Nook Miles NH Icon Cropped.png", and the currency_image_size is set to "18px".

The output is: Nook Miles

When short is applied, the output is: Miles

See also


local p = {}

function p.outputCurrency (frame)
	local formatnum
	local num = frame.args['2']
	local function isEmpty(s)
		return s == nil or s == ''
	end
    local data = {
		["Bells"] = { "99k Bells NH Inv Icon cropped.png", "15px", "Bell", "Bell", "Bell" },
		["Play Coins"] = { "Play Coins Icon.png", "15px", "Play Coins", "Play Coin", "Play Coin" },
		["Medals"] = { "Medal NL Icon.png", "18px", "Medals", "Medal", "Medal" },
		["MEOW Coupons"] = { "MEOW Coupon Icon.png", "18px", "MEOW Coupons", "MEOW Coupon", "Coupon" },
		["Leaf Tickets"] = { "Leaf Ticket PC Icon.png", "15px", "Leaf Ticket", "Leaf Ticket", "Ticket" },
		["Nook Miles"] = { "Nook Miles NH Icon Cropped.png", "18px", "Nook Miles", "Nook Mile", "Mile" },
		["Heart Crystals"] = { "Heart Crystal NH Inv Icon.png", "15px", "Item:Heart Crystal (New Horizons)", "Heart Crystal", "Heart Crystal" },
		["Saharah Tickets"] = { "Saharah Ticket NH Inv Icon.png", "15px", "Item:Saharah Ticket (New Horizons)", "Saharah Ticket", "Saharah Ticket" },
		["Nook Points"] = { "Nook Points NH Icon Cropped.png", "18px", "NookLink#Nook Points", "Nook Point", "Point" },
		["Points"] = { "", "", "Tom Nook Point System", "Point", "Point" },
		["Happy Points"] = { "Happy Point aF Icon.png", "15px", "Happy Point", "Happy Point", "Happy Point" },
		["Happy Tickets"] = { "", "", "Happy Ticket", "Happy Ticket", "Happy Ticket" },
		["Poki"] = { "Poki NH Inv Icon cropped.png", "15px", "Poki", "Poki", "Poki" }
	}
	local print = ''
	if not isEmpty(data[frame.args['1']][1]) then
    	print = print .. '[[File:'.. data[frame.args['1']][1]  .. '|'
    	if (frame.args['size']) then
    		print = print .. frame.args['size']
    	else
    		print = print .. data[frame.args['1']][2]
    	end
		print = print .. '|link=|alt=]]'
		if not isEmpty(num) then
			formatnum = require("Module:Formatnum")
			print = print .. ' ' .. formatnum.formatNum(frame.args['2'],"en")
		end
	end
	print = print .. ' '
	if not isEmpty(frame.args['nolink']) then
		if not isEmpty(frame.args['short']) then
			print = print .. data[frame.args['1']][5]
			if (num == 1) then
				print = print .. ''
			else
				print = print .. 's'
			end
		else
			print = print .. data[frame.args['1']][4]
			if (num == 1) then
				print = print .. ''
			else
				print = print .. 's'
			end
		end
	else
		if not isEmpty(frame.args['short']) then
			print = print .. '[[' .. data[frame.args['1']][3] .. '|' .. data[frame.args['1']][5]
			if (num == 1) then
				print = print .. ''
			else
				print = print .. 's'
			print = print .. ']]'
			end
		else
			print = print .. '[[' .. data[frame.args['1']][3] .. '|' .. data[frame.args['1']][4]
			if (num == 1) then
				print = print .. ''
			else
				print = print .. 's'
			print = print .. ']]'
			end
		end
	end
	if not isEmpty(frame.args['note']) then
		print = print .. frame:preprocess('{{Note|' .. frame.args['note'] .. '}}')
	end
	return print
end

return p