Module:Availability

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 = ' ' -- Availability with a specific villager -- if (frame.args['1'] == "Villager") then setDefault(game," NH Villager Icon.png") print = print .. ' '		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['2'] ..  else print = print ..  .. frame.args['2'] ..  end else print = print ..  .. frame.args['2'] ..  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 .. ''		   	end else 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 .. ' '			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 .. ' (' .. frame.args['note'] .. ') ' end print = print .. ' '	-- Line break function -- if not isEmpty(frame.args['nb']) then print = print .. ''	else print = print .. ' '	end return print end return p