-- access point for easily setting render settings such as default lighting properties, camera, etc


local References = require(game:GetService("ReplicatedStorage"):WaitForChild("Utilities"):WaitForChild("Services"):WaitForChild("References"))
local Utilities = References.Utilities
local Services = Utilities.Services

local Player = require(References.PlayerScripts.Main:WaitForChild("Player"))

local Gameplay = {}
	Gameplay.Camera = workspace.CurrentCamera
	
	Gameplay.HUDPositions = {}
	Gameplay.HUD_ENABLED = true
		
	function Gameplay:UpdateHUDPositions()
		local hud_elements = References.HUD:GetChildren()
		for i=1,#hud_elements do
			local hud_element = hud_elements[i]
			if hud_element:IsA("GuiObject") then
				Gameplay.HUDPositions[hud_element] = {}
				Gameplay.HUDPositions[hud_element].Show = hud_element.Position
				
				local axis = {X=0,Y=0}
				
				local hidden = {}
				for a in pairs(axis) do
					hidden[a] = {Offset = 0; Scale = 0;};
					if hud_element.Position[a].Scale <= .25 then
						hidden[a].Scale = 0;
						hidden[a].Offset = -(hud_element.AbsoluteSize.X*2)
						--hidden_x_scale = -.5
					elseif hud_element.Position[a].Scale > .25 and hud_element.Position[a].Scale < .75 then
						hidden[a].Scale = hud_element.Position[a].Scale
						hidden[a].Offset = hud_element.Position[a].Offset
					--	hidden_x_scale = hud_element.Position[a].Scale
					else
						hidden[a].Scale = 0;
						hidden[a].Offset = References.HUD.AbsoluteSize.X + (hud_element.AbsoluteSize.X*2)
						--hidden_x_scale = 1.5
					end
				end
				
				
				Gameplay.HUDPositions[hud_element].Hide = UDim2.new(hidden.X.Scale,hidden.X.Offset,hidden.Y.Scale,hidden.Y.Offset)
			end
		end
	end
	Gameplay:UpdateHUDPositions()
	
	References.HUD:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
		if Gameplay.HUD_ENABLED then
			Gameplay:UpdateHUDPositions()
		end
	end)
	
	
	function Gameplay:TweenHUD(on_off)
		local desc = References.HUD:GetChildren()
		for i=1,#desc do
			local d = desc[i]
			if d:IsA("GuiObject") then
				local positions = self.HUDPositions[d]
				if positions then
					d:TweenPosition(on_off and positions.Show or positions.Hide, "Out", "Quint", 1, true)
				end
			end
		end
	end
	
	function Gameplay:ToggleHUD(on_off)
		if on_off then
			self:SetDefaultCore()
		else
			Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
		end
		self:TweenHUD(on_off)
		self.HUD_ENABLED = on_off
	end
	
	-- sets all of our preferred core ui settings (topbar stuff, coreguitypes, etc)
	function Gameplay:SetDefaultCore()
		References.PlayerGui:SetTopbarTransparency(1)
		Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
		Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, true)
		Services.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
		--Services.StarterGui:SetCore("ResetButtonCallback",false)
		Player.Player.CameraMaxZoomDistance = 65;
	end
	
	Gameplay:SetDefaultCore()

return Gameplay