Module:NLVillagerItemOutput

local p = {} local cargo = mw.ext.cargo local formatList = require('Module:List').listFormat

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

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

function p.furnitureOutput( frame ) local print = '' local data = {} local dataRV = {}

-- 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 data[r] = " " .. results[r].villager .. "" end print = print .. formatList(data) .. "."	   if not isEmpty(frame.args['not-purchasable']) then print = print .. ''	   else print = print .. " As a result, this item can be purchased by the player if they were invited by any of the preceding villagers." end if not isEmpty(frame.args['not-re-tail']) then print = print .. ''	   else print = print .. " Villagers may also put this item up for sale at the Re-Tail flea market for 50% to 90% of the item's buy price, in increments of 10%." 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 RV" if #results2 ~= 1 then print = print .. "s" end print = print .. " of " for r = 1, #results2 do dataRV[r] = " " .. results2[r].name .. "" end print = print .. formatList(dataRV) .. "."	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 return print end

function p.clothingOutput( frame ) local print = '' local data = {}

-- 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 data[r] = " " .. results[r].villager .. "" end print = print .. formatList(data) .. " as their default outfit." else print = print .. "No villagers wear this item as their default outfit." end return print end

function p.umbrellaOutput( frame ) local print = '' local data = {} local data2 = {} -- 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 data[r] = " " .. results[r].villager .. "" end print = print .. formatList(data) .. " as their default umbrella during periods of rain." if not tableEmpty(resultsFrog) then print = print .. " "		   for r = 1, #resultsFrog do data2[r] = " " .. resultsFrog[r].villager .. "" end print = print .. formatList(data2) 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 data2[r] = " " .. resultsFrog[r].villager .. "" end print = print .. formatList(data2) .. " 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 return print end

function p.interiorOutput( frame ) local print = '' local data = {}

-- 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 data[r] = " " .. results[r].villager .. "" end print = print .. formatList(data) 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 return print end

return p