local n=require(script.Parent.Config)local Z={User="\085\115\101\114";Dev="\068\101\118";Test="\084\101\115\116"}local w=n.isDevBuild and Z.Dev or Z.User local i={LogLevel={type="\073\110\116\086\097\108\117\101";values={[Z.User]=2;[Z.Dev]=4;[Z.Test]=4}},TypecheckingEnabled={type="\066\111\111\108\086\097\108\117\101",values={[Z.User]=false;[Z.Dev]=true;[Z.Test]=true}}}local X="\082\111\111\116\068\101\118\083\101\116\116\105\110\103\115"..n.codename local function G()return game:FindFirstChild(X)end local K=G()game.ChildAdded:Connect(function(n)local Z,w=pcall(function()return n.Name end)if Z and w==X then K=n end end)local function V(n)if K==nil then return nil end local Z=K:FindFirstChild(n)if Z==nil then return nil end return Z.Value end local function F(n,Z,w)local i=K:FindFirstChild(n)if i==nil then i=Instance.new(Z)i.Name=n i.Parent=K end i.Value=w end local function y(n)assert(Z[n]~=nil,"\073\110\118\097\108\105\100 \101\110\118\105\114\111\110\109\101\110\116")K=G()if K==nil then K=Instance.new("\070\111\108\100\101\114")K.Name=X K.Parent=game end for Z,w in pairs(i)do F(Z,w.type,w.values[n])end end local function J(n)assert(i[n]~=nil,"\073\110\118\097\108\105\100 \068\101\118\083\101\116\116\105\110\103\115 \110\097\109\101")local Z=V(n)if Z~=nil then return Z end return i[n].values[w]end local v={}function v.createDevSettings(n)y(Z.Dev)end function v.createTestSettings(n)y(Z.Test)end function v.hasChangedValues(n)return K~=nil end function v.resetValues(n)if K then K:Destroy()K=nil end end function v.isEnabled(n)return K~=nil end function v.getLogLevel(n)return J("\076\111\103\076\101\118\101\108")end function v.shouldTypecheck(n)return J("\084\121\112\101\099\104\101\099\107\105\110\103\069\110\097\098\108\101\100")end function _G.ROJO_DEV_CREATE()v:createDevSettings()end return v
local Config = require(script.Parent.Config)

local Environment = {
	User = 'User',
	Dev = 'Dev',
	Test = 'Test',
}

local DEFAULT_ENVIRONMENT = Config.isDevBuild and Environment.Dev or Environment.User

local VALUES = {
	LogLevel = {
		type = 'IntValue',
		values = {
			[Environment.User] = 2,
			[Environment.Dev] = 4,
			[Environment.Test] = 4,
		},
	},
	TypecheckingEnabled = {
		type = 'BoolValue',
		values = {
			[Environment.User] = false,
			[Environment.Dev] = true,
			[Environment.Test] = true,
		},
	},
}

local CONTAINER_NAME = 'RootDevSettings' .. Config.codename

local function getValueContainer()
	return game:FindFirstChild(CONTAINER_NAME)
end

local valueContainer = getValueContainer()

game.ChildAdded:Connect(function(child)
	local success, name = pcall(function()
		return child.Name
	end)

	if success and name == CONTAINER_NAME then
		valueContainer = child
	end
end)

local function getStoredValue(name)
	if valueContainer == nil then
		return nil
	end

	local valueObject = valueContainer:FindFirstChild(name)

	if valueObject == nil then
		return nil
	end

	return valueObject.Value
end

local function setStoredValue(name, kind, value)
	local object = valueContainer:FindFirstChild(name)

	if object == nil then
		object = Instance.new(kind)
		object.Name = name
		object.Parent = valueContainer
	end

	object.Value = value
end

local function createAllValues(environment)
	assert(Environment[environment] ~= nil, 'Invalid environment')

	valueContainer = getValueContainer()

	if valueContainer == nil then
		valueContainer = Instance.new('Folder')
		valueContainer.Name = CONTAINER_NAME
		valueContainer.Parent = game
	end

	for name, value in pairs(VALUES) do
		setStoredValue(name, value.type, value.values[environment])
	end
end

local function getValue(name)
	assert(VALUES[name] ~= nil, 'Invalid DevSettings name')

	local stored = getStoredValue(name)

	if stored ~= nil then
		return stored
	end

	return VALUES[name].values[DEFAULT_ENVIRONMENT]
end

local DevSettings = {}

function DevSettings:createDevSettings()
	createAllValues(Environment.Dev)
end

function DevSettings:createTestSettings()
	createAllValues(Environment.Test)
end

function DevSettings:hasChangedValues()
	return valueContainer ~= nil
end

function DevSettings:resetValues()
	if valueContainer then
		valueContainer:Destroy()
		valueContainer = nil
	end
end

function DevSettings:isEnabled()
	return valueContainer ~= nil
end

function DevSettings:getLogLevel()
	return getValue('LogLevel')
end

function DevSettings:shouldTypecheck()
	return getValue('TypecheckingEnabled')
end

function _G.ROJO_DEV_CREATE()
	DevSettings:createDevSettings()
end

return DevSettings