Difference between revisions of "Module:Availability"

From Nookipedia, the Animal Crossing wiki
(moving data out; moving functions outside of main outputAvailability function)
Tag: Replaced
m (minor fixes for June and Snooty availability; fixed Lulu and Carmen availability text when using villager availability)
Line 27: Line 27:
 
if (frame.args['1'] == "Villager") then
 
if (frame.args['1'] == "Villager") then
 
setDefault(game," NH Villager Icon.png")
 
setDefault(game," NH Villager Icon.png")
print = print .. '[[File:' .. frame.args['2'] .. game[frame.args['3']]
+
if (frame.args['2']  == "Lulu (villager)" or frame.args['2'] == "Lulu (islander)") then
 +
print = print .. '[[File:Lulu ' .. game[frame.args['3']]
 +
elseif (frame.args['2'] == "Carmen (mouse)") then
 +
print = print .. '[[File:Carmen ' .. game[frame.args['3']]
 +
else
 +
print = print .. '[[File:' .. frame.args['2'] .. game[frame.args['3']]
 +
end
 
if not isEmpty(frame.args['size']) then
 
if not isEmpty(frame.args['size']) then
 
print = print .. '|' .. frame.args['size']
 
print = print .. '|' .. frame.args['size']
Line 35: Line 41:
 
print = print .. '|link=|alt=]] '
 
print = print .. '|link=|alt=]] '
 
if not isEmpty(frame.args['4']) then
 
if not isEmpty(frame.args['4']) then
if (frame.args['4'] == "June" or frame.args['4'] == "Snooty" or frame.args['4'] == "Lulu") then
+
print = print .. '[[' .. frame.args['4'] .. '|' .. frame.args['2'] .. ']]'
print = print .. '[[' .. frame.args['4'] .. ' (villager)|' .. frame.args['2'] .. ']]'
+
else
 +
if (frame.args['2'] == "June" or frame.args['2'] == "Snooty") then
 +
print = print .. '[[' .. frame.args['2'] .. ' (villager)'
 +
else
 +
print = print .. '[[' .. frame.args['2']
 +
end
 +
if not isEmpty(frame.args['text']) then
 +
    print = print .. '|' .. frame.args['text'] .. ']]'
 +
elseif (frame.args['2'] == "June" or frame.args['2'] == "Snooty") then
 +
print = print .. '|' .. frame.args['2'] .. ']]'
 
else
 
else
print = print .. '[[' .. frame.args['4'] .. '|' .. frame.args['2'] .. ']]'
+
print = print .. ']]'
 
end
 
end
else
 
print = print .. '[[' .. frame.args['2'] .. ']]'
 
 
end
 
end
 
else
 
else

Revision as of 23:30, March 22, 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

This page is fully-protected to prevent editing by non-administrator users

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

function p.outputAvailability (frame)
	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 (frame.args['1'] == "Villager") then
		setDefault(game," NH Villager Icon.png")
		if (frame.args['2']  == "Lulu (villager)" or frame.args['2'] == "Lulu (islander)") then
			print = print .. '[[File:Lulu ' .. game[frame.args['3']]
		elseif (frame.args['2'] == "Carmen (mouse)") then
			print = print .. '[[File:Carmen ' .. game[frame.args['3']]
		else
			print = print .. '[[File:' .. frame.args['2'] .. game[frame.args['3']]
		end
		if not isEmpty(frame.args['size']) then
			print = print .. '|' .. frame.args['size']
		else
			print = print .. '|22px'
		end
		print = print .. '|link=|alt=]]&nbsp;'
		if not isEmpty(frame.args['4']) then
			print = print .. '[[' .. frame.args['4'] .. '|' .. frame.args['2'] .. ']]'
		else
			if (frame.args['2'] == "June" or frame.args['2'] == "Snooty") then
				print = print .. '[[' .. frame.args['2'] .. ' (villager)'
			else
				print = print .. '[[' .. frame.args['2']
			end
			if not isEmpty(frame.args['text']) then
			    print = print .. '|' .. frame.args['text'] .. ']]'
			elseif (frame.args['2'] == "June" or frame.args['2'] == "Snooty") then
				print = print .. '|' .. frame.args['2'] .. ']]'
			else
				print = print .. ']]'
			end
		end
	else
		-- Availability in terms of RVs --
		if (frame.args['1'] == "RV") then
			if not isEmpty(data.availabilityRV[frame.args['2']]) and not isEmpty(data.availabilityRV[frame.args['2']][1]) then
				print = print .. '[[File:'.. data.availabilityRV[frame.args['2']][1]
			else
				print = print .. '[[File:' .. frame.args['2'] .. ' NL Villager Icon.png'
			end
			if not isEmpty(frame.args['size']) then
				print = print .. '|' .. frame.args['size']
			else
				if not isEmpty(data.availabilityRV[frame.args['2']]) and not isEmpty(data.availabilityRV[frame.args['2']][2]) then
					print = print .. '|' .. data.availabilityRV[frame.args['2']][2]
				else
					print = print .. '|22px'
				end
			end
			print = print .. '|link=|alt=]]&nbsp;'
			if not isEmpty(data.availabilityRV[frame.args['2']]) and not isEmpty(data.availabilityRV[frame.args['2']][3]) then
		    	print = print .. '[[' .. data.availabilityRV[frame.args['2']][3]
		    	if not isEmpty(frame.args['text']) then
		    		print = print .. '|' .. frame.args['text'] .. ']]'
		    	else
		    		print = print .. '|' .. data.availabilityRV[frame.args['2']][4] .. ']]'
		    	end
		    else
		    	print = print .. '[[' .. frame.args['2'] .. '#RV'
		    	if not isEmpty(frame.args['text']) then
		    		print = print .. '|' .. frame.args['text'] .. ']]'
		    	else
		    		print = print .. '|' .. frame.args['2'] .. '\'s RV]]'
		    	end
			end
		else
			-- Main availability function --
			if not isEmpty(data.availability[frame.args['1']]) and not isEmpty(data.availability[frame.args['1']][1]) then
		    	print = print .. '[[File:'.. data.availability[frame.args['1']][1]
				if not isEmpty(frame.args['size']) then
					print = print .. '|' .. frame.args['size']
				else
					print = print .. '|' .. data.availability[frame.args['1']][2]
				end
				print = print .. '|link=|alt=]]&nbsp;'
			end
			if not isEmpty(data.availability[frame.args['1']]) and not isEmpty(data.availability[frame.args['1']][3]) then
		    	print = print .. '[[' .. data.availability[frame.args['1']][3]
		    	if (data.availability[frame.args['1']][3] == data.availability[frame.args['1']][4]) then
		    		print = print .. ']]'
		    	else
		    		if not isEmpty(frame.args['text']) then
			    		print = print .. '|' .. frame.args['text'] .. ']]'
			    	else
			    		print = print .. '|' .. data.availability[frame.args['1']][4] .. ']]'
		    		end
		    	end
		    else
		    	if not isEmpty(data.availability[frame.args['1']]) and not isEmpty(data.availability[frame.args['1']][5]) then
		    		if not isEmpty(frame.args['text']) then
			    		print = print .. frame.args['text']
			    	else
		    			print = print .. data.availability[frame.args['1']][5]
		    		end
		    	else
		    		if not isEmpty(frame.args['text']) then
			    		print = print .. frame.args['text']
			    	else
		    			print = print .. frame.args['1']
		    		end
		    	end
			end
		end
	end
	-- Note function --
	if not isEmpty(frame.args['note']) then
		print = print .. '<small> (' .. frame.args['note'] .. ')</small>'
	end
	print = print .. '</span>'
	-- Line break function --
	if not isEmpty(frame.args['nb']) then
		print = print .. ''
	else
		print = print .. '<br/>'
	end
	return print
end
return p