Difference between revisions of "Module:Currency"
PanchamBro (talk | contribs) m (fixing absent note parameter) |
AlexBot2004 (talk | contribs) ("miles" is lowercased in-game when shortened) |
||
(14 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
− | + | local getArgs = require('Module:Arguments').getArgs | |
− | local | + | local sentenceCase = require('Module:SentenceCase').firstToUpper |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function p.main(frame) | function p.main(frame) | ||
Line 20: | Line 11: | ||
local currency = args[1] or args.currency or '' | local currency = args[1] or args.currency or '' | ||
local num = args[2] or args.num or '' | local num = args[2] or args.num or '' | ||
− | return p.outputCurrency(currency, num, nolink, note, short, size, frame) | + | local noimages = args.noimages or '' |
+ | return p.outputCurrency(currency, num, nolink, note, short, size, frame, noimages) | ||
end | end | ||
− | function p.outputCurrency(currency, num, nolink, note, short, size, frame) | + | function p.outputCurrency(currency, num, nolink, note, short, size, frame, noimages) |
local formatnum | local formatnum | ||
local function isEmpty(s) | local function isEmpty(s) | ||
Line 33: | Line 25: | ||
local data = { | local data = { | ||
["Bells"] = { "99k Bells NH Inv Icon cropped.png", "15px", "Bell", "Bell", "Bell" }, | ["Bells"] = { "99k Bells NH Inv Icon cropped.png", "15px", "Bell", "Bell", "Bell" }, | ||
+ | ["Caps"] = { "Cap PC Icon.png", "15px", "Cap", "Cap", "Cap" }, | ||
["Play Coins"] = { "Play Coins Icon.png", "15px", "Play Coins", "Play Coin", "Play Coin" }, | ["Play Coins"] = { "Play Coins Icon.png", "15px", "Play Coins", "Play Coin", "Play Coin" }, | ||
− | ["Medals"] = { "Medal NL Icon.png", "18px", " | + | ["Medals"] = { "Medal NL Icon.png", "18px", "Medal", "medal", "medal" }, |
["MEOW Coupons"] = { "MEOW Coupon Icon.png", "18px", "MEOW Coupons", "MEOW Coupon", "Coupon" }, | ["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" }, | ["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", " | + | ["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 | + | ["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" }, | ["Saharah Tickets"] = { "Saharah Ticket NH Inv Icon.png", "15px", "Item:Saharah Ticket (New Horizons)", "Saharah Ticket", "Saharah Ticket" }, | ||
− | ["Nook Points"] = { "Nook Points NH Icon | + | ["Nook Points"] = { "Nook Points NH Icon.svg", "18px", "NookLink#Nook Points", "Nook Point", "Point" }, |
["Points"] = { "", "", "Tom Nook Point System", "Point", "Point" }, | ["Points"] = { "", "", "Tom Nook Point System", "Point", "Point" }, | ||
["Happy Points"] = { "Happy Point aF Icon.png", "15px", "Happy Point", "Happy Point", "Happy Point" }, | ["Happy Points"] = { "Happy Point aF Icon.png", "15px", "Happy Point", "Happy Point", "Happy Point" }, | ||
− | ["Happy Tickets"] = { "", "", "Happy Ticket", "Happy Ticket", "Happy Ticket" }, | + | ["Happy Tickets"] = { "Happy Ticket aF Icon.png", "22px", "Happy Ticket", "Happy Ticket", "Happy Ticket" }, |
["Poki"] = { "Poki NH Inv Icon cropped.png", "15px", "Poki", "Poki", "Poki" }, | ["Poki"] = { "Poki NH Inv Icon cropped.png", "15px", "Poki", "Poki", "Poki" }, | ||
["Gold Points"] = { "My Nintendo Gold Point.png", "15px", "My Nintendo", "Gold Point", "Point" }, | ["Gold Points"] = { "My Nintendo Gold Point.png", "15px", "My Nintendo", "Gold Point", "Point" }, | ||
Line 51: | Line 44: | ||
local print = '' | local print = '' | ||
if not isEmpty(currency) then | if not isEmpty(currency) then | ||
− | if not isEmpty(data[currency][1]) then | + | if not isEmpty(data[currency][1]) and isEmpty(noimages) then |
print = print .. '[[File:'.. data[currency][1] .. '|' | print = print .. '[[File:'.. data[currency][1] .. '|' | ||
if not isEmpty(size) then | if not isEmpty(size) then | ||
Line 58: | Line 51: | ||
print = print .. data[currency][2] | print = print .. data[currency][2] | ||
end | end | ||
− | print = print .. '|link=|alt=]]' | + | print = print .. '|link=|alt=]] ' |
− | + | end | |
− | + | if not isEmpty(num) then | |
− | + | formatnum = require("Module:Formatnum") | |
− | + | print = print .. formatnum.formatNum(num,"en") | |
+ | print = print .. ' ' | ||
end | end | ||
− | |||
if not isEmpty(nolink) then | if not isEmpty(nolink) then | ||
if not isEmpty(short) then | if not isEmpty(short) then | ||
− | print = print .. data[currency][5] | + | if not isEmpty(num) then |
+ | print = print .. data[currency][5] | ||
+ | else | ||
+ | print = print .. sentenceCase(data[currency][5]) | ||
+ | end | ||
if (num == 1) or currency == "Poki" then | if (num == 1) or currency == "Poki" then | ||
print = print .. '' | print = print .. '' | ||
Line 74: | Line 71: | ||
end | end | ||
else | else | ||
− | print = print .. data[currency][4] | + | if not isEmpty(num) then |
+ | print = print .. data[currency][4] | ||
+ | else | ||
+ | print = print .. sentenceCase(data[currency][4]) | ||
+ | end | ||
if (num == 1) or currency == "Poki" then | if (num == 1) or currency == "Poki" then | ||
print = print .. '' | print = print .. '' | ||
Line 83: | Line 84: | ||
else | else | ||
if not isEmpty(short) then | if not isEmpty(short) then | ||
− | print = print .. '[[' .. data[currency][3] .. '|' .. data[currency][5] | + | print = print .. '[[' .. data[currency][3] .. '|' |
− | if (num == 1) | + | if not isEmpty(num) then |
+ | print = print .. data[currency][5] | ||
+ | else | ||
+ | print = print .. sentenceCase(data[currency][5]) | ||
+ | end | ||
+ | if (num == 1) or currency == "Poki" then | ||
print = print .. '' | print = print .. '' | ||
else | else | ||
print = print .. 's' | print = print .. 's' | ||
+ | end | ||
print = print .. ']]' | print = print .. ']]' | ||
+ | else | ||
+ | print = print .. '[[' .. data[currency][3] .. '|' | ||
+ | if not isEmpty(num) then | ||
+ | print = print .. data[currency][4] | ||
+ | else | ||
+ | print = print .. sentenceCase(data[currency][4]) | ||
end | end | ||
− | + | if (num == 1) or currency == "Poki" then | |
− | |||
− | if (num == 1) | ||
print = print .. '' | print = print .. '' | ||
else | else | ||
print = print .. 's' | print = print .. 's' | ||
+ | end | ||
print = print .. ']]' | print = print .. ']]' | ||
− | |||
end | end | ||
end | end |
Latest revision as of 16:38, May 10, 2024
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 ofname_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 thatcurrency_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 theshort
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 = {}
local getArgs = require('Module:Arguments').getArgs
local sentenceCase = require('Module:SentenceCase').firstToUpper
function p.main(frame)
local args = getArgs(frame)
local nolink = args.nolink or ''
local short = args.short or ''
local size = args.size or ''
local note = args.note or ''
local currency = args[1] or args.currency or ''
local num = args[2] or args.num or ''
local noimages = args.noimages or ''
return p.outputCurrency(currency, num, nolink, note, short, size, frame, noimages)
end
function p.outputCurrency(currency, num, nolink, note, short, size, frame, noimages)
local formatnum
local function isEmpty(s)
return s == nil or s == ''
end
local function tableEmpty(s)
return next(s) == nil
end
local data = {
["Bells"] = { "99k Bells NH Inv Icon cropped.png", "15px", "Bell", "Bell", "Bell" },
["Caps"] = { "Cap PC Icon.png", "15px", "Cap", "Cap", "Cap" },
["Play Coins"] = { "Play Coins Icon.png", "15px", "Play Coins", "Play Coin", "Play Coin" },
["Medals"] = { "Medal NL Icon.png", "18px", "Medal", "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.svg", "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 aF Icon.png", "22px", "Happy Ticket", "Happy Ticket", "Happy Ticket" },
["Poki"] = { "Poki NH Inv Icon cropped.png", "15px", "Poki", "Poki", "Poki" },
["Gold Points"] = { "My Nintendo Gold Point.png", "15px", "My Nintendo", "Gold Point", "Point" },
["Platinum Points"] = { "My Nintendo Platinum Point.png", "15px", "My Nintendo", "Platinum Point", "Point" },
["Platinum Points (PC)"] = { "My Nintendo Platinum Point PC.png", "15px", "My Nintendo", "Platinum Point", "Point" }
}
local print = ''
if not isEmpty(currency) then
if not isEmpty(data[currency][1]) and isEmpty(noimages) then
print = print .. '[[File:'.. data[currency][1] .. '|'
if not isEmpty(size) then
print = print .. size
else
print = print .. data[currency][2]
end
print = print .. '|link=|alt=]] '
end
if not isEmpty(num) then
formatnum = require("Module:Formatnum")
print = print .. formatnum.formatNum(num,"en")
print = print .. ' '
end
if not isEmpty(nolink) then
if not isEmpty(short) then
if not isEmpty(num) then
print = print .. data[currency][5]
else
print = print .. sentenceCase(data[currency][5])
end
if (num == 1) or currency == "Poki" then
print = print .. ''
else
print = print .. 's'
end
else
if not isEmpty(num) then
print = print .. data[currency][4]
else
print = print .. sentenceCase(data[currency][4])
end
if (num == 1) or currency == "Poki" then
print = print .. ''
else
print = print .. 's'
end
end
else
if not isEmpty(short) then
print = print .. '[[' .. data[currency][3] .. '|'
if not isEmpty(num) then
print = print .. data[currency][5]
else
print = print .. sentenceCase(data[currency][5])
end
if (num == 1) or currency == "Poki" then
print = print .. ''
else
print = print .. 's'
end
print = print .. ']]'
else
print = print .. '[[' .. data[currency][3] .. '|'
if not isEmpty(num) then
print = print .. data[currency][4]
else
print = print .. sentenceCase(data[currency][4])
end
if (num == 1) or currency == "Poki" then
print = print .. ''
else
print = print .. 's'
end
print = print .. ']]'
end
end
end
if not isEmpty(note) then
print = print .. frame:expandTemplate{ title = 'Note', args = { note }}
end
return print
end
return p