Module:NLVillagerItemOutput

local p = {} local cargo = mw.ext.cargo

function tableEmpty(s) return next(s) == nil end

function isEmpty(s) return s == nil or s == '' end

function p.furnitureOutput( frame ) local print = ''

-- Cargo query for nl_house local tables = 'nl_house' local fields = "nl_house.villager=villager,nl_house._pageTitle=pageName" local args = { where = "nl_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'", orderBy = 'nl_house.name_sort', limit = 300, default = '' }   local results = cargo.query( tables, fields, args ) -- Cargo query for nlwa_rv local tables2 = 'nlwa_rv' local fields2 = "nlwa_rv.name=name,nlwa_rv.icon=icon,nlwa_rv._pageTitle=pageName" local args2 = { where = "nlwa_rv.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'", orderBy = 'nlwa_rv.name_sort', limit = 300, default = '' }   local results2 = cargo.query( tables2, fields2, args2 ) if not tableEmpty(results) then if not isEmpty(frame.args['disable-clothing']) then print = print .. "However, this item " else print = print .. "This item " end if not isEmpty(frame.args['clothing']) and isEmpty(frame.args['disable-clothing']) then print = print .. "also " else print = print .. " "   	end print = print .. "appears as a furniture item in the homes of " for r = 1, #results do	   	if r == #results and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. results[r].villager .. "" if r == #results then print = print .. '.'	       elseif r-1 == 0 and r+1 == #results then print = print .. ' '	       else print = print .. ', '	       end end if not isEmpty(frame.args['not-purchasable']) then print = print .. ''	   else print = print .. " As a result, this item has a chance to be purchasable by the player if they were invited by any of the preceding villagers." end end if not tableEmpty(results2) then if tableEmpty(results) then print = print .. "No villagers have this item in their home. However, this item" else print = print .. " This item also" end print = print .. " appears in the RVs of " for r = 1, #results2 do	   	if r == #results2 and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. results2[r].name .. "" if r == #results2 then print = print .. '.'	       elseif r-1 == 0 and r+1 == #results2 then print = print .. ' '	       else print = print .. ', '	       end end end if tableEmpty(results) and tableEmpty(results2) then print = print .. "No villagers have this item in their home, nor do any characters have this item in their RV." end if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] .. "."   end

return print end

function p.clothingOutput( frame ) local print = ''

-- Cargo query for nl_villager local tables = 'nl_villager' local fields = "nl_villager.icon=icon,nl_villager.name=villager,nl_villager._pageTitle=pageName" local args = { where = "nl_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "'",       orderBy = 'nl_villager.name_sort', limit = 300, default = '' }   local results = cargo.query( tables, fields, args ) if not tableEmpty(results) then print = print .. "This item is worn by " for r = 1, #results do	   	if r == #results and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. results[r].villager .. "" if r == #results then print = print .. ' '	       elseif r-1 == 0 and r+1 == #results then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default outfit." else print = print .. "No villagers wear this item as their default outfit." end if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] .. "."	end

return print end

function p.umbrellaOutput( frame ) local print = ''

-- Cargo query for nl_villager local tables = 'nl_villager' local fields = "nl_villager.icon=icon,nl_villager.name=villager,nl_villager._pageTitle=pageName" local args = { where = "nl_villager.umbrella = '" .. frame.args['1']:gsub("\'","\\'") .. "' AND species<>'Frog'", orderBy = 'nl_villager.name_sort', limit = 300, default = '' }   local results = cargo.query( tables, fields, args ) -- Cargo query for nl_villager (Frog villagers) local tables2 = 'nl_villager' local fields2 = "nl_villager.icon=icon,nl_villager.name=villager,nl_villager._pageTitle=pageName" local args2 = { where = "nl_villager.umbrella = '" .. frame.args['1']:gsub("\'","\\'") .. "' AND species='Frog'", orderBy = 'nl_villager.name_sort', limit = 300, default = '' }   local resultsFrog = cargo.query( tables2, fields2, args2 )

if not tableEmpty(results) then print = print .. "This item is used by " for r = 1, #results do	   	if r == #results and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. results[r].villager .. "" if r == #results then print = print .. ' '	       elseif r-1 == 0 and r+1 == #results then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default umbrella during periods of rain." if not tableEmpty(resultsFrog) then print = print .. " "		   for r = 1, #resultsFrog do		    	if r == #resultsFrog and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsFrog[r].villager .. "" if r == #resultsFrog then print = print .. ' '		       elseif r-1 == 0 and r+1 == #resultsFrog then print = print .. ' '		       else print = print .. ', '		       end end if #resultsFrog == 1 then print = print .. " has " else print = print .. " have " end print = print .. "this item as their default umbrella, but will refrain from using the umbrella due to their status as a frog villager." end elseif tableEmpty(results) and not tableEmpty(resultsFrog) then print = print .. "This item is featured by " for r = 1, #resultsFrog do	   	if r == #resultsFrog and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. resultsFrog[r].villager .. "" if r == #resultsFrog then print = print .. ' '	       elseif r-1 == 0 and r+1 == #resultsFrog then print = print .. ' '	       else print = print .. ', '	       end end print = print .. " as their default umbrella during periods of rain, but they will refrain from using the umbrella due to their status as a frog villager." else print = print .. "No villagers use this item as their default umbrella during periods of rain." end if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] .. "."	end

return print end

function p.interiorOutput( frame ) local print = ''

-- Cargo query for nl_house local tables local fields local args local results if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then tables = 'nl_house' fields = "nl_house.villager=villager,nl_house._pageTitle=pageName" args = { where = "nl_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'nl_house.name_sort', limit = 300, default = '' }	   results = cargo.query( tables, fields, args ) elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "carpet" then tables = 'nl_house' fields = "nl_house.villager=villager,nl_house._pageTitle=pageName" args = { where = "nl_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'nl_house.name_sort', limit = 300, default = '' }	   results = cargo.query( tables, fields, args ) else results = {} end if not tableEmpty(results) then print = print .. "This item appears in the homes of " for r = 1, #results do	   	if r == #results and r-1 ~= 0 then print = print .. 'and ' end print = print .. " " .. results[r].villager .. "" if r == #results or (r-1 == 0 and r+1 == #results) then print = print .. ' '	       else print = print .. ', '	       end end if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then print = print .. ' as the default wallpaper.' elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "carpet" then print = print .. ' as the default carpet.' end else print = print .. "No villagers have this item in their home." end if not isEmpty(frame.args['text']) then print = print .. " " .. frame.args['text'] .. "."	end

return print end

return p