Module:CFVillagerItemOutput
From Nookipedia, the Animal Crossing wiki
Module documentation (view)
Usage
This Lua module outputs the villager data info for item pages from Animal Crossing: City Folk in regards to their furniture, clothing, umbrella, and interior items. These are put through {{CFFurnitureVillagers}}, {{CFInteriorVillagers}}, {{CFClothingVillagers}}, and {{CFUmbrellaVillagers}}. Please refer to the documentation of each of these templates for more information.
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 = {}
-- Cargo query for cf_house
local tables = 'cf_house'
local fields = "cf_house.villager=villager,cf_house._pageTitle=pageName"
local args = {
where = "cf_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
orderBy = 'cf_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
data[r] = "[[" .. results[r].pageName .. "|" .. results[r].villager .. "]]"
end
print = print .. formatList(data) .. "."
else
print = print .. "No villagers have this item in their home."
end
return print
end
function p.clothingOutput( frame )
local print = ''
local data = {}
-- Cargo query for cf_villager
local tables = 'cf_villager'
local fields = "cf_villager.name=villager,cf_villager._pageTitle=pageName"
local args = {
where = "cf_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "'",
orderBy = 'cf_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].pageName .. "|" .. 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 = {}
-- Cargo query for cf_villager
local tables = 'cf_villager'
local fields = "cf_villager.name=villager,cf_villager._pageTitle=pageName"
local args = {
where = "cf_villager.umbrella = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
orderBy = 'cf_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
data[r] = "[[" .. results[r].pageName .. "|" .. results[r].villager .. "]]"
end
print = print .. formatList(data) .. " as their default umbrella during periods of [[weather|rain]]."
else
print = print .. "No villagers use this item as their default umbrella during periods of [[weather|rain]]."
end
return print
end
function p.interiorOutput( frame )
local print = ''
local data = {}
-- Cargo query for cf_house
local tables
local fields
local args
local results
if not isEmpty(frame.args['type']) and frame.args['type']:lower() == "wallpaper" then
tables = 'cf_house'
fields = "cf_house.villager=villager,cf_house._pageTitle=pageName"
args = {
where = "cf_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
orderBy = 'cf_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 = 'cf_house'
fields = "cf_house.villager=villager,cf_house._pageTitle=pageName"
args = {
where = "cf_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
orderBy = 'cf_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
data[r] = "[[" .. results[r].pageName .. "|" .. 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