Difference between revisions of "Module:Availability"
From Nookipedia, the Animal Crossing wiki
PanchamBro (talk | contribs) m (minor fixes for June and Snooty availability; fixed Lulu and Carmen availability text when using villager availability) |
PanchamBro (talk | contribs) (converting to use arguments) |
||
Line 16: | Line 16: | ||
end | end | ||
− | function p.outputAvailability ( | + | local function getArgs(frame) |
+ | local args = {} | ||
+ | for key, value in pairs(frame:getParent().args) do | ||
+ | args[key] = value | ||
+ | end | ||
+ | for key, value in pairs(frame.args) do | ||
+ | args[key] = value | ||
+ | end | ||
+ | return args | ||
+ | end | ||
+ | |||
+ | function p.main(frame) | ||
+ | local args = getArgs(frame) | ||
+ | local args1 = args[1] or '' | ||
+ | local args2 = args[2] or '' | ||
+ | local args3 = args[3] or '' | ||
+ | local args4 = args[4] or '' | ||
+ | local text = args.text or '' | ||
+ | local size = args.size or '' | ||
+ | local nb = args.nb or '' | ||
+ | local note = args.note or '' | ||
+ | return p.outputAvailability (args1, args2, args3, args4, text, size, nb, note) | ||
+ | end | ||
+ | |||
+ | function p.outputAvailability (args1, args2, args3, args4, text, size, nb, note) | ||
local function isEmpty(s) | local function isEmpty(s) | ||
return s == nil or s == '' | return s == nil or s == '' | ||
Line 25: | Line 49: | ||
-- Availability with a specific villager -- | -- Availability with a specific villager -- | ||
− | if ( | + | if (args1 == "Villager") then |
setDefault(game," NH Villager Icon.png") | setDefault(game," NH Villager Icon.png") | ||
− | if ( | + | if (args2 == "Lulu (villager)" or args2 == "Lulu (islander)") then |
− | print = print .. '[[File:Lulu ' .. game[ | + | print = print .. '[[File:Lulu ' .. game[args3] |
− | elseif ( | + | elseif (args2 == "Carmen (mouse)") then |
− | print = print .. '[[File:Carmen ' .. game[ | + | print = print .. '[[File:Carmen ' .. game[args3] |
else | else | ||
− | print = print .. '[[File:' .. | + | print = print .. '[[File:' .. args2 .. game[args3] |
end | end | ||
− | if not isEmpty( | + | if not isEmpty(size) then |
− | print = print .. '|' .. | + | print = print .. '|' .. size |
else | else | ||
print = print .. '|22px' | print = print .. '|22px' | ||
end | end | ||
print = print .. '|link=|alt=]] ' | print = print .. '|link=|alt=]] ' | ||
− | if not isEmpty( | + | if not isEmpty(args4) then |
− | print = print .. '[[' .. | + | print = print .. '[[' .. args4 .. '|' .. args2 .. ']]' |
else | else | ||
− | if ( | + | if (args2 == "June" or args2 == "Snooty") then |
− | print = print .. '[[' .. | + | print = print .. '[[' .. args2 .. ' (villager)' |
else | else | ||
− | print = print .. '[[' .. | + | print = print .. '[[' .. args2 |
end | end | ||
− | if not isEmpty( | + | if not isEmpty(text) then |
− | print = print .. '|' .. | + | print = print .. '|' .. text .. ']]' |
− | elseif ( | + | elseif (args2 == "June" or args2 == "Snooty") then |
− | print = print .. '|' .. | + | print = print .. '|' .. args2 .. ']]' |
else | else | ||
print = print .. ']]' | print = print .. ']]' | ||
Line 58: | Line 82: | ||
else | else | ||
-- Availability in terms of RVs -- | -- Availability in terms of RVs -- | ||
− | if ( | + | if (args1 == "RV") then |
− | if not isEmpty(data.availabilityRV[ | + | if not isEmpty(data.availabilityRV[args2]) and not isEmpty(data.availabilityRV[args2][1]) then |
− | print = print .. '[[File:'.. data.availabilityRV[ | + | print = print .. '[[File:'.. data.availabilityRV[args2][1] |
else | else | ||
− | print = print .. '[[File:' .. | + | print = print .. '[[File:' .. args2 .. ' NL Villager Icon.png' |
end | end | ||
− | if not isEmpty( | + | if not isEmpty(size) then |
− | print = print .. '|' .. | + | print = print .. '|' .. size |
else | else | ||
− | if not isEmpty(data.availabilityRV[ | + | if not isEmpty(data.availabilityRV[args2]) and not isEmpty(data.availabilityRV[args2][2]) then |
− | print = print .. '|' .. data.availabilityRV[ | + | print = print .. '|' .. data.availabilityRV[args2][2] |
else | else | ||
print = print .. '|22px' | print = print .. '|22px' | ||
Line 74: | Line 98: | ||
end | end | ||
print = print .. '|link=|alt=]] ' | print = print .. '|link=|alt=]] ' | ||
− | if not isEmpty(data.availabilityRV[ | + | if not isEmpty(data.availabilityRV[args2]) and not isEmpty(data.availabilityRV[args2][3]) then |
− | print = print .. '[[' .. data.availabilityRV[ | + | print = print .. '[[' .. data.availabilityRV[args2][3] |
− | if not isEmpty( | + | if not isEmpty(text) then |
− | print = print .. '|' .. | + | print = print .. '|' .. text .. ']]' |
else | else | ||
− | print = print .. '|' .. data.availabilityRV[ | + | print = print .. '|' .. data.availabilityRV[args2][4] .. ']]' |
end | end | ||
else | else | ||
− | print = print .. '[[' .. | + | print = print .. '[[' .. args2 .. '#RV' |
− | if not isEmpty( | + | if not isEmpty(text) then |
− | print = print .. '|' .. | + | print = print .. '|' .. text .. ']]' |
else | else | ||
− | print = print .. '|' .. | + | print = print .. '|' .. args2 .. '\'s RV]]' |
end | end | ||
end | end | ||
else | else | ||
-- Main availability function -- | -- Main availability function -- | ||
− | if not isEmpty(data.availability[ | + | if not isEmpty(data.availability[args1]) and not isEmpty(data.availability[args1][1]) then |
− | print = print .. '[[File:'.. data.availability[ | + | print = print .. '[[File:'.. data.availability[args1][1] |
− | if not isEmpty( | + | if not isEmpty(size) then |
− | print = print .. '|' .. | + | print = print .. '|' .. size |
else | else | ||
− | print = print .. '|' .. data.availability[ | + | print = print .. '|' .. data.availability[args1][2] |
end | end | ||
print = print .. '|link=|alt=]] ' | print = print .. '|link=|alt=]] ' | ||
end | end | ||
− | if not isEmpty(data.availability[ | + | if not isEmpty(data.availability[args1]) and not isEmpty(data.availability[args1][3]) then |
− | print = print .. '[[' .. data.availability[ | + | print = print .. '[[' .. data.availability[args1][3] |
− | if (data.availability[ | + | if (data.availability[args1][3] == data.availability[args1][4]) then |
print = print .. ']]' | print = print .. ']]' | ||
else | else | ||
− | if not isEmpty( | + | if not isEmpty(text) then |
− | print = print .. '|' .. | + | print = print .. '|' .. text .. ']]' |
else | else | ||
− | print = print .. '|' .. data.availability[ | + | print = print .. '|' .. data.availability[args1][4] .. ']]' |
end | end | ||
end | end | ||
else | else | ||
− | if not isEmpty(data.availability[ | + | if not isEmpty(data.availability[args1]) and not isEmpty(data.availability[args1][5]) then |
− | if not isEmpty( | + | if not isEmpty(text) then |
− | print = print .. | + | print = print .. text |
else | else | ||
− | print = print .. data.availability[ | + | print = print .. data.availability[args1][5] |
end | end | ||
else | else | ||
− | if not isEmpty( | + | if not isEmpty(text) then |
− | print = print .. | + | print = print .. text |
else | else | ||
− | print = print .. | + | print = print .. args1 |
end | end | ||
end | end | ||
Line 129: | Line 153: | ||
end | end | ||
-- Note function -- | -- Note function -- | ||
− | if not isEmpty( | + | if not isEmpty(note) then |
− | print = print .. '<small> (' .. | + | print = print .. '<small> (' .. note .. ')</small>' |
end | end | ||
print = print .. '</span>' | print = print .. '</span>' | ||
-- Line break function -- | -- Line break function -- | ||
− | if not isEmpty( | + | if not isEmpty(nb) then |
print = print .. '' | print = print .. '' | ||
else | else |
Revision as of 17:38, May 4, 2022
Module documentation (view)
Usage
This Lua module outputs the availability of each source presented and is used for the {{Availability}} template to account for preprocessor node count limits. Data is stored in a table, and can determine how certain variables are used.
To add additional sources, see Module:Availability/Data.
See also
local p = {}
data = mw.loadData("Module:Availability/Data")
function setDefault (t, d)
local mt = {__index = function () return d end}
setmetatable(t, mt)
end
-- Imported function from https://www.lua.org/pil/13.4.3.html --
function copyTable(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
local function getArgs(frame)
local args = {}
for key, value in pairs(frame:getParent().args) do
args[key] = value
end
for key, value in pairs(frame.args) do
args[key] = value
end
return args
end
function p.main(frame)
local args = getArgs(frame)
local args1 = args[1] or ''
local args2 = args[2] or ''
local args3 = args[3] or ''
local args4 = args[4] or ''
local text = args.text or ''
local size = args.size or ''
local nb = args.nb or ''
local note = args.note or ''
return p.outputAvailability (args1, args2, args3, args4, text, size, nb, note)
end
function p.outputAvailability (args1, args2, args3, args4, text, size, nb, note)
local function isEmpty(s)
return s == nil or s == ''
end
game = copyTable(data.game)
local print = '<span style="font-size:.9em;">'
-- Availability with a specific villager --
if (args1 == "Villager") then
setDefault(game," NH Villager Icon.png")
if (args2 == "Lulu (villager)" or args2 == "Lulu (islander)") then
print = print .. '[[File:Lulu ' .. game[args3]
elseif (args2 == "Carmen (mouse)") then
print = print .. '[[File:Carmen ' .. game[args3]
else
print = print .. '[[File:' .. args2 .. game[args3]
end
if not isEmpty(size) then
print = print .. '|' .. size
else
print = print .. '|22px'
end
print = print .. '|link=|alt=]] '
if not isEmpty(args4) then
print = print .. '[[' .. args4 .. '|' .. args2 .. ']]'
else
if (args2 == "June" or args2 == "Snooty") then
print = print .. '[[' .. args2 .. ' (villager)'
else
print = print .. '[[' .. args2
end
if not isEmpty(text) then
print = print .. '|' .. text .. ']]'
elseif (args2 == "June" or args2 == "Snooty") then
print = print .. '|' .. args2 .. ']]'
else
print = print .. ']]'
end
end
else
-- Availability in terms of RVs --
if (args1 == "RV") then
if not isEmpty(data.availabilityRV[args2]) and not isEmpty(data.availabilityRV[args2][1]) then
print = print .. '[[File:'.. data.availabilityRV[args2][1]
else
print = print .. '[[File:' .. args2 .. ' NL Villager Icon.png'
end
if not isEmpty(size) then
print = print .. '|' .. size
else
if not isEmpty(data.availabilityRV[args2]) and not isEmpty(data.availabilityRV[args2][2]) then
print = print .. '|' .. data.availabilityRV[args2][2]
else
print = print .. '|22px'
end
end
print = print .. '|link=|alt=]] '
if not isEmpty(data.availabilityRV[args2]) and not isEmpty(data.availabilityRV[args2][3]) then
print = print .. '[[' .. data.availabilityRV[args2][3]
if not isEmpty(text) then
print = print .. '|' .. text .. ']]'
else
print = print .. '|' .. data.availabilityRV[args2][4] .. ']]'
end
else
print = print .. '[[' .. args2 .. '#RV'
if not isEmpty(text) then
print = print .. '|' .. text .. ']]'
else
print = print .. '|' .. args2 .. '\'s RV]]'
end
end
else
-- Main availability function --
if not isEmpty(data.availability[args1]) and not isEmpty(data.availability[args1][1]) then
print = print .. '[[File:'.. data.availability[args1][1]
if not isEmpty(size) then
print = print .. '|' .. size
else
print = print .. '|' .. data.availability[args1][2]
end
print = print .. '|link=|alt=]] '
end
if not isEmpty(data.availability[args1]) and not isEmpty(data.availability[args1][3]) then
print = print .. '[[' .. data.availability[args1][3]
if (data.availability[args1][3] == data.availability[args1][4]) then
print = print .. ']]'
else
if not isEmpty(text) then
print = print .. '|' .. text .. ']]'
else
print = print .. '|' .. data.availability[args1][4] .. ']]'
end
end
else
if not isEmpty(data.availability[args1]) and not isEmpty(data.availability[args1][5]) then
if not isEmpty(text) then
print = print .. text
else
print = print .. data.availability[args1][5]
end
else
if not isEmpty(text) then
print = print .. text
else
print = print .. args1
end
end
end
end
end
-- Note function --
if not isEmpty(note) then
print = print .. '<small> (' .. note .. ')</small>'
end
print = print .. '</span>'
-- Line break function --
if not isEmpty(nb) then
print = print .. ''
else
print = print .. '<br/>'
end
return print
end
return p