Module:CustomizationGallery

From Nookipedia, the Animal Crossing wiki

Documentation for this module may be created at Module:CustomizationGallery/doc

local p = {}
local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').getArgs
local sentenceCase = require('Module:SentenceCase').firstToUpper

function p.main(frame)
    local args         = getArgs(frame)
    local where        = args['where'] or ''
    local game         = args['game'] or ''
    local limit        = args['limit'] or ''
	if game == "New Leaf" then
    	return p.outputNLGallery(where)
    elseif game == "New Horizons" then
    	return p.outputNHGallery(where)
    end
end

function p.outputNLGallery(where, limit)
	local function isEmpty(s)
		return s == nil or s == ''
	end
	local print = ''
	local tables = 'nl_furniture,nl_furniture_variation'
    local fields = "nl_furniture.en_name=name,nl_furniture_variation.variation=variation,nl_furniture_variation.pattern=pattern,nl_furniture_variation.ore=ore,nl_furniture_variation.image=image"
    local args = {
    	join = 'nl_furniture_variation.en_name = nl_furniture.en_name',
        where = where,
        orderBy = 'nl_furniture.catalog_num, nl_furniture.en_name, nl_furniture_variation.variation_number,nl_furniture_variation.ore_number,nl_furniture_variation.pattern_number',
        limit = limit,
        default = ''
    }
    local results = cargo.query( tables, fields, args )
    print = print .. '<gallery>\n'
    for r = 1, #results do
    	print = print .. results[r].image .. '|' .. sentenceCase(results[r].name)
    	if not isEmpty(results[r].pattern) then
    		if not isEmpty(results[r].variation) then
    			print = print .. " (" .. results[r].variation .. ' - ' .. results[r].pattern .. ")"
    		elseif not isEmpty(results[r].ore) then
    			print = print .. " (" .. sentenceCase(results[r].ore) .. ' - ' .. results[r].pattern .. ")"
    		end
    	end
    	print = print .. '\n'
    end
    print = print .. '</gallery>'
    return print
end

function p.outputNHGallery(where, limit)
	local function isEmpty(s)
		return s == nil or s == ''
	end
	local print = ''
	local tables = 'nh_furniture,nh_furniture_variation'
    local fields = "nh_furniture.en_name=name,nh_furniture_variation.variation=variation,nh_furniture_variation.pattern=pattern,nh_furniture_variation.image=image"
    local args = {
    	join = 'nh_furniture_variation.en_name = nh_furniture.en_name',
        where = where,
        orderBy = 'nh_furniture.catalog_num,nh_furniture_variation.variation_number,nh_furniture_variation.pattern_number',
        limit = limit,
        default = ''
    }
    local results = cargo.query( tables, fields, args )
    print = print .. '<gallery>\n'
    for r = 1, #results do
    	print = print .. results[r].image .. '|' .. sentenceCase(results[r].name)
    	if not isEmpty(results[r].pattern) then
    		print = print .. " (" .. results[r].variation .. ' - ' .. results[r].pattern .. ")"
    	end
    	print = print .. '\n'
    end
    print = print .. '</gallery>'
    return print
end

return p