-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEAM-30 ScaledUIStroke preset component
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- Constants | ||
local BASE_RATIO = Vector2.new(1920, 1080) | ||
local BASE_MAGNITUDE = (BASE_RATIO / BASE_RATIO).Magnitude | ||
local TICK_RATE = 1 / 1 | ||
|
||
-- Services | ||
local RunService = game:GetService("RunService") | ||
|
||
-- -- Imports | ||
-- local States = script.Parent.Parent.States | ||
-- local New = require(States.New) | ||
|
||
-- Variables | ||
local Camera = workspace.CurrentCamera | ||
local LastTick = os.clock() | ||
local Strokes = {} | ||
|
||
local function Init() | ||
RunService.RenderStepped:Connect(function() | ||
if os.clock() - LastTick < TICK_RATE then | ||
return | ||
else | ||
LastTick = os.clock() | ||
end | ||
|
||
for Object, Thickness in Strokes do | ||
if not Object:IsDescendantOf(game) then | ||
Strokes[Object] = nil | ||
continue | ||
end | ||
|
||
local Scale = (Camera.ViewportSize / BASE_RATIO).Magnitude / BASE_MAGNITUDE | ||
Object.Thickness = Thickness * Scale | ||
end | ||
end) | ||
end | ||
|
||
return function(StrokeObject : UIStroke) | ||
local OriginalThickness = StrokeObject.Thickness | ||
Strokes[StrokeObject] = OriginalThickness | ||
|
||
return StrokeObject | ||
end, Init() |