local P=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local Y=require(P.Packages.Knit)local z=require(P.Game.Modules.State)local V=.0013888888888889 local I=.5 local s=workspace.CurrentCamera local m=Y.CreateController({Name="\083\099\097\108\101\067\111\110\116\114\111\108\108\101\114"})function m.KnitStart(P) end function m.KnitInit(P)local Y=task.delay(I,function() end)local function m()local P=s.ViewportSize local m,W=P.X,P.Y local B=V*W if W>m then B=V*m end task.cancel(Y)Y=task.delay(I,function()z:dispatch({type="\083\101\116\083\099\097\108\101",scale=B})end)end task.spawn(m);(s:GetPropertyChangedSignal("\086\105\101\119\112\111\114\116\083\105\122\101")):Connect(m)end return m
-- ScaleController
-- 0_1195
-- May 08, 2022

--[[

https://devforum.roblox.com/t/scaler-using-uiscale-to-scale-your-ui/1105672

]]

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Knit = require(ReplicatedStorage.Packages.Knit)
local State = require(ReplicatedStorage.Game.Modules.State)

local MULTIPLIER = 1 / 720
local DISPATCH_DELAY = 0.5

local camera = workspace.CurrentCamera

local Controller = Knit.CreateController({
	Name = "ScaleController",
})

function Controller:KnitStart() end

function Controller:KnitInit()
	local updateThread = task.delay(DISPATCH_DELAY, function() end)

	local function viewportSizeChanged()
		local viewportSize = camera.ViewportSize

		local sizeX, sizeY = viewportSize.X, viewportSize.Y
		local scale = MULTIPLIER * sizeY

		if sizeY > sizeX then
			scale = MULTIPLIER * sizeX
		end

		task.cancel(updateThread)
		updateThread = task.delay(DISPATCH_DELAY, function()
			State:dispatch({
				type = "SetScale",
				scale = scale,
			})
		end)
	end

	task.spawn(viewportSizeChanged)

	camera:GetPropertyChangedSignal("ViewportSize"):Connect(viewportSizeChanged)
end

return Controller
