Module:PGVillagerItemOutput

From Nookipedia, the Animal Crossing wiki
Revision as of 17:24, May 30, 2022 by PanchamBro (talk | contribs) (rewording sentence w/ recommendation by SuperHamster)

Module documentation (view)


Usage

This Lua module outputs the villager data info for item pages from every first generation Animal Crossing game in regards to their furniture, clothing, umbrella, and interior items. These are put through {{PGFurnitureVillagers}}, {{PGInteriorVillagers}}, {{PGClothingVillagers}}, and {{PGUmbrellaVillagers}}. Please refer to the documentation of each of these templates for more information.


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 pg_house and pg_villager (Doubutsu no Mori)
    local tables1 = 'pg_house,pg_villager'
    local fields1 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args1 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DnM' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 300,
        default = ''
    }
    local resultsDnM = cargo.query( tables1, fields1, args1 )
    
    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori+)
    local tables2 = 'pg_house,pg_villager'
    local fields2 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args2 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DnM+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 300,
        default = ''
    }
    local resultsDnMplus = cargo.query( tables2, fields2, args2 )
    
	-- Cargo query for pg_house and pg_villager (Animal Crossing)
    local tables3 = 'pg_house,pg_villager'
    local fields3 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args3 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'PG' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 300,
        default = ''
    }
    local resultsPG = cargo.query( tables3, fields3, args3 )
    
    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori e+)
    local tables4 = 'pg_house,pg_villager'
    local fields4 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args4 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DmMe+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 300,
        default = ''
    }
    local resultsDnMeplus = cargo.query( tables4, fields4, args4 )
    
        if not tableEmpty(resultsDnM) then
    	print = print .. "In ''[[Doubutsu no Mori]]'', this item appears in the homes of "
	    for r = 1, #resultsDnM do
	    	if r == #resultsDnM and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnM[r].image .. "|x25px|link=|alt=|" .. resultsDnM[r].villager .. "]] [[" .. resultsDnM[r].pageName .. "|" .. resultsDnM[r].villager .. "]]"
	        if r == #resultsDnM then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsDnM then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not tableEmpty(resultsDnMplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMplus) then
    	print = print .. "In ''[[Animal Crossing|Doubutsu no Mori+]]'', this item appears in the homes of "
	    for r = 1, #resultsDnMplus do
	    	if r == #resultsDnMplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMplus[r].image .. "|x25px|link=|alt=|" .. resultsDnMplus[r].villager .. "]] [[" .. resultsDnMplus[r].pageName .. "|" .. resultsDnMplus[r].villager .. "]]"
	        if r == #resultsDnMplus then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsDnMplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not tableEmpty(resultsPG) then
	    	print = print .. "\n\n"
	    end
	end
    if not tableEmpty(resultsPG) then
    	print = print .. "In ''[[Animal Crossing]]'', this item appears in the homes of "
	    for r = 1, #resultsPG do
	    	if r == #resultsPG and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsPG[r].image .. "|x25px|link=|alt=|" .. resultsPG[r].villager .. "]] [[" .. resultsPG[r].pageName .. "|" .. resultsPG[r].villager .. "]]"
	        if r == #resultsPG then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsPG then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMeplus) then
    	print = print .. "In ''[[Doubutsu no Mori e+]]'', this item appears in the homes of "
	    for r = 1, #resultsDnMeplus do
	    	if r == #resultsDnMeplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMeplus[r].image .. "|x25px|link=|alt=|" .. resultsDnMeplus[r].villager .. "]] [[" .. resultsDnMeplus[r].pageName .. "|" .. resultsDnMeplus[r].villager .. "]]"
	        if r == #resultsDnMeplus then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsDnMeplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	end
	if not tableEmpty(resultsDnM) or not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
		print = print .. "\n\nFor villagers who have the " .. frame.args['1'] .. " placed on the floor in their house, there is a chance that the villager will gift it to the player."
	end
	if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then
		print = print .. "No villagers have this item in their home."
    end
    return print
end

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

	-- Cargo query for pg_villager (Doubutsu no Mori)
    local tables1 = 'pg_villager'
    local fields1 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args1 = {
        where = "pg_villager.clothing_dnm = '" .. frame.args['1']:gsub("\'","\\'").. "'",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsDnM = cargo.query( tables1, fields1, args1 )
    
	-- Cargo query for pg_villager (Doubutsu no Mori+)
    local tables2 = 'pg_villager'
    local fields2 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args2 = {
        where = "pg_villager.clothing_plus = '" .. frame.args['1']:gsub("\'","\\'").. "'",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsDnMplus = cargo.query( tables2, fields2, args2 )
    
	-- Cargo query for pg_villager (Animal Crossing)
    local tables3 = 'pg_villager'
    local fields3 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args3 = {
        where = "pg_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "' AND in_pg=1",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsPG = cargo.query( tables3, fields3, args3 )
    
    -- Cargo query for pg_villager (Doubutsu no Mori e+)
    local tables4 = 'pg_villager'
    local fields4 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args4 = {
        where = "pg_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "' AND in_pg=0",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsDnMeplus = cargo.query( tables4, fields4, args4 )
    
    if not tableEmpty(resultsDnM) then
    	print = print .. "In ''[[Doubutsu no Mori]]'', this item is worn by "
	    for r = 1, #resultsDnM do
	    	if r == #resultsDnM and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnM[r].icon .. "|25px|link=|alt=|" .. resultsDnM[r].villager .. "]] [[" .. resultsDnM[r].pageName .. "|" .. resultsDnM[r].villager .. "]]"
	        if r == #resultsDnM then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsDnM then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	    if not tableEmpty(resultsDnMplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMplus) then
    	print = print .. "In ''[[Animal Crossing|Doubutsu no Mori+]]'', this item is worn by "
	    for r = 1, #resultsDnMplus do
	    	if r == #resultsDnMplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMplus[r].icon .. "|25px|link=|alt=|" .. resultsDnMplus[r].villager .. "]] [[" .. resultsDnMplus[r].pageName .. "|" .. resultsDnMplus[r].villager .. "]]"
	        if r == #resultsDnMplus then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsDnMplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	    if not tableEmpty(resultsPG) then
	    	print = print .. "\n\n"
	    end
	end
    if not tableEmpty(resultsPG) then
    	print = print .. "In ''[[Animal Crossing]]'', this item is worn by "
	    for r = 1, #resultsPG do
	    	if r == #resultsPG and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsPG[r].icon .. "|25px|link=|alt=|" .. resultsPG[r].villager .. "]] [[" .. resultsPG[r].pageName .. "|" .. resultsPG[r].villager .. "]]"
	        if r == #resultsPG then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsPG then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	    if not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMeplus) then
    	print = print .. "In ''[[Doubutsu no Mori e+]]'', this item is worn by "
	    for r = 1, #resultsDnMeplus do
	    	if r == #resultsDnMeplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMeplus[r].icon .. "|25px|link=|alt=|" .. resultsDnMeplus[r].villager .. "]] [[" .. resultsDnMeplus[r].pageName .. "|" .. resultsDnMeplus[r].villager .. "]]"
	        if r == #resultsDnMeplus then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsDnMeplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	end
	if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then
		print = print .. "No villagers wear this item as their default outfit."
    end
    return print
end

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

	-- Cargo query for pg_villager
    local tables = 'pg_villager'
    local fields = "pg_villager.icon=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args = {
        where = "pg_villager.umbrella = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
        orderBy = 'pg_villager.romanized_name',
        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 .. "[[File:" .. results[r].icon .. "|25px|link=|alt=|" .. results[r].villager .. "]] [[" .. results[r].pageName .. "|" .. 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 [[weather|rain]]."
	else
		print = print .. "No villagers use this item as their default umbrella during periods of [[weather|rain]]."
    end
    return print
end

return p