Module:WWVillagerItemOutput

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 ww_house local tables = 'ww_house' local fields = "ww_house.villager=villager,ww_house._pageTitle=pageName" local args = { where = "ww_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'", orderBy = 'ww_house.villager', limit = 300, default = '' }   local results = cargo.query( tables, fields, args ) 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 else print = print .. "No villagers have this item in their home." end return print end

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

-- Cargo query for ww_villager local tables = 'ww_villager' local fields = "ww_villager.pic=icon,ww_villager.name=villager,ww_villager._pageTitle=pageName" local args = { where = "ww_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "'",       orderBy = 'ww_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

return print end

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

-- Cargo query for ww_villager local tables = 'ww_villager' local fields = "ww_villager.pic=icon,ww_villager.name=villager,ww_villager._pageTitle=pageName" local args = { where = "ww_villager.umbrella = '" .. frame.args['1']:gsub("\'","\\'") .. "'",       orderBy = 'ww_villager.name_sort', limit = 300, default = '' }   local results = cargo.query( tables, fields, args )

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." 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 = ''

-- Cargo query for ww_house local tables local fields local args local results if not isEmpty(frame.args['type']) and frame.args['type']:lower == "wallpaper" then tables = 'ww_house' fields = "ww_house.villager=villager,ww_house._pageTitle=pageName" args = { where = "ww_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'ww_house.villager', limit = 300, default = '' }	   results = cargo.query( tables, fields, args ) elseif not isEmpty(frame.args['type']) and frame.args['type']:lower == "carpet" then tables = 'ww_house' fields = "ww_house.villager=villager,ww_house._pageTitle=pageName" args = { where = "ww_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",	       orderBy = 'ww_house.villager', 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

return print end

return p