local Z=import("\046\047\097\115\115\105\103\110")local D=import("\046\047\102\117\110\099\116\105\111\110\115\047\115\101\116\116\105\110\103\115\047\082\101\110\100\101\114\083\101\116\116\105\110\103\115")local Q={}setmetatable(Q,{__tostring=function()return"\083\101\116\116\105\110\103\115"end})local j={}function j.GetFFlag(D,Z)if D.settings.flags[Z]==nil then error(string.format("\070\097\115\116 \102\108\097\103 \037\115 \100\111\101\115 \110\111\116 \101\120\105\115\116",Z),2)end return D.settings.flags[Z]end local O={}O.type=Q function O.__index(D,Z)local Q=(getmetatable(D)).internal if Q[Z]~=nil then return Q[Z]end if j[Z]~=nil then return j[Z]end error(string.format("\037\115 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114 \111\102 \083\101\116\116\105\110\103\115",tostring(Z)),2)end function Q.new(Q)local j={settings=Q or{},Rendering=D.new()}j.settings.flags=j.settings.flags or{}local L=newproxy(true)Z(getmetatable(L),O);(getmetatable(L)).internal=j return L end return function(Z)local D=Q.new(Z)return function()return D end end
--[[
	This file creates the settings() method.
	Since settings implements the GetFFlag method, we need to pass fast flags
	from a Habitat instance.
]]
local assign = import("./assign")
local RenderSettings = import("./functions/settings/RenderSettings")

local Settings = {}

setmetatable(Settings, {
	__tostring = function()
		return "Settings"
	end,
})

local prototype = {}

--[[
	GetFFlag will throw on missing fast flags if ignoreMissingFFlags setting is false/nil
]]
function prototype:GetFFlag(name)
	if self.settings.flags[name] == nil then
		error(string.format("Fast flag %s does not exist", name), 2)
	end

	return self.settings.flags[name]
end

local metatable = {}
metatable.type = Settings

function metatable:__index(key)
	local internal = getmetatable(self).internal

	if internal[key] ~= nil then
		return internal[key]
	end

	if prototype[key] ~= nil then
		return prototype[key]
	end

	error(string.format("%s is not a valid member of Settings", tostring(key)), 2)
end

function Settings.new(settings)
	local internalInstance = {
		settings = settings or {},
		Rendering = RenderSettings.new()
	}

	internalInstance.settings.flags = internalInstance.settings.flags or {}

	local instance = newproxy(true)

	assign(getmetatable(instance), metatable)
	getmetatable(instance).internal = internalInstance

	return instance
end

return function(settings)
	local instance = Settings.new(settings)
	return function()
		return instance
	end
end
