Skip to content

Commit

Permalink
Merge pull request #13 from MiaGobble/SEAM-34-Bug-Fixes
Browse files Browse the repository at this point in the history
Seam 34 bug fixes
  • Loading branch information
MiaGobble authored Oct 8, 2024
2 parents 32dc692 + cdb57ba commit f4eb452
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 39 deletions.
12 changes: 12 additions & 0 deletions src/Modules/InitPresetComponents.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Imports
local States = script.Parent.Parent.States
local DeclareComponent = require(States.DeclareComponent)

-- Variables
local PresetComponents = script.Parent.Parent.PresetComponents

return function()
for _, ComponentModule in ipairs(PresetComponents:GetChildren()) do
DeclareComponent(ComponentModule.Name, require(ComponentModule))
end
end
45 changes: 45 additions & 0 deletions src/PresetComponents/BasicButton.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- Imports
local States = script.Parent.Parent.States
local New = require(States.New)
local OnEvent = require(States.OnEvent)
local Computed = require(States.Computed)
local Tween = require(States.Animation.Tween)

return function(ButtonObject : GuiButton)
local State = "Idle"
local ColorPropertyName = ButtonObject:IsA("ImageButton") and "ImageColor3" or "TextColor3"

local H, S, V = Color3.toHSV(ButtonObject[ColorPropertyName] :: Color3)

return New(ButtonObject, {
AutoButtonColor = false,

[ColorPropertyName] = Tween(Computed(function()
if State == "Idle" then
return Color3.fromHSV(H, S, V)
elseif State == "Hover" then
return Color3.fromHSV(H, S, V * 0.9)
elseif State == "Press" then
return Color3.fromHSV(H, S, V * 0.75)
end

error("Invalid state: " .. State)
end), TweenInfo.new(0.1)),

[OnEvent "MouseButton1Down"] = function()
State = "Press"
end,

[OnEvent "MouseButton1Up"] = function()
State = "Idle"
end,

[OnEvent "MouseEnter"] = function()
State = "Hover"
end,

[OnEvent "MouseLeave"] = function()
State = "Idle"
end,
})
end
13 changes: 13 additions & 0 deletions src/PresetComponents/QuickSound.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Services
local SoundService = game:GetService("SoundService")

-- Imports
local States = script.Parent.Parent.States
local New = require(States.New)

return function(Sound : Sound)
New(Sound, {
Parent = SoundService,
PlayOnRemove = true,
}):Destroy()
end
39 changes: 39 additions & 0 deletions src/PresetComponents/ScaledUIStroke.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- 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")

-- 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()
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ type SpringConstructor = (Value : any, Speed : number, Dampening : number) -> Sp

-- Constants
local EULERS_NUMBER = 2.71828
local EPSILON = 0.001

-- Imports
local Modules = script.Parent.Parent.Parent.Modules
local Components = script.Parent.Parent
local States = script.Parent.Parent
local PackType = require(Modules.PackType)
local UnpackType = require(Modules.UnpackType)
local Computed = require(Components.Computed)
local Computed = require(States.Computed)
local Janitor = require(Modules.Janitor)
local Signal = require(Modules.Signal)

Expand Down Expand Up @@ -90,6 +91,12 @@ function Spring:__call(Value : any, Speed : number, Dampening : number) : Spring
for Index, Spring in ipairs(UnpackedSprings) do
local Position, _ = GetPositionDerivative(Speed, Dampening, Spring.Position0, Spring.Coordinate1, Spring.Coordinate2, Spring.Tick0)

if math.abs(Position) <= EPSILON then
Position = 0
elseif math.abs(Position - Spring.Position0) <= EPSILON then
Position = Spring.Position0
end

PackedValues[Index] = Position
end

Expand All @@ -108,25 +115,6 @@ function Spring:__call(Value : any, Speed : number, Dampening : number) : Spring
return PackType(PackedValues, ValueType)
elseif Index == "Changed" then
return ChangedSignal
elseif Index == "Impulse" then
return function(self, AmountValue : any)
local UnpackedAmount = UnpackType(AmountValue, ValueType)

for Index, Spring in ipairs(UnpackedSprings) do
local Amount = UnpackedAmount[Index]
local Position, Velocity = GetPositionDerivative(Speed, Dampening, Spring.Position0, Spring.Coordinate1, Spring.Coordinate2, Spring.Tick0)

Spring.Tick0, Spring.Coordinate1 = os.clock(), Position

if (Dampening >= 1) then
Spring.Coordinate2 = Spring.Coordinate1 + (Velocity + Amount) / Speed
else
local High = math.sqrt(1 - Dampening * Dampening)

Spring.Coordinate2 = Dampening / High * Spring.Coordinate1 + (Velocity + Amount) / (Speed * High)
end
end
end
end

return nil
Expand Down Expand Up @@ -156,8 +144,8 @@ function Spring:__call(Value : any, Speed : number, Dampening : number) : Spring
local UnpackedNewValue = UnpackType(NewValue, ValueType)

for Index, Spring in ipairs(UnpackedSprings) do
Spring.Position0 = UnpackedNewValue[Index]
Spring.Coordinate1, Spring.Coordinate2, Spring.Velocity = 0, 0, 0
--Spring.Position0 = UnpackedNewValue[Index]
Spring.Coordinate1, Spring.Coordinate2, Spring.Velocity = UnpackedNewValue[Index] - Spring.Position0, 0, 0
Spring.Tick0 = os.clock()
end
elseif Index == "Dampening" then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ type TweenInstance = {

type TweenConstructor = (Value : any, TweenInformation : TweenInfo) -> TweenInstance

-- Constants
local EPSILON = 0.001

-- Services
local TweenService = game:GetService("TweenService")

-- Imports
local Modules = script.Parent.Parent.Parent.Modules
local Components = script.Parent.Parent
local States = script.Parent.Parent
local PackType = require(Modules.PackType)
local UnpackType = require(Modules.UnpackType)
local Computed = require(Components.Computed)
local Computed = require(States.Computed)
local Janitor = require(Modules.Janitor)
local Signal = require(Modules.Signal)

Expand Down Expand Up @@ -71,6 +74,12 @@ function Tween:__call(Value : any, TweenInformation : TweenInfo) : TweenInstance
local UnitPosition = TweenService:GetValue(Alpha, TweenInformation.EasingStyle, TweenInformation.EasingDirection)
local Position = Tween.Position0 + (Tween.Position1 - Tween.Position0) * UnitPosition

if math.abs(Position) <= EPSILON then
Position = 0
elseif math.abs(Position - Tween.Position0) <= EPSILON then
Position = Tween.Position0
end

PackedValues[Index] = Position
end

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 22 additions & 14 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,95 +5,103 @@

local Seam = {}

-- Variables
local Components = script.Components
-- Imports
local States = script.States
local Modules = script.Modules
local InitPresetComponents = require(Modules.InitPresetComponents)

local function Init()
InitPresetComponents()
end

-- Note: I opt for WaitForChild to load stuff; this helps prevent edge case errors where children don't load in time.

--[=[
@prop New New
@within Seam
]=]

Seam.New = require(Components.New)
Seam.New = require(States:WaitForChild("New"))
Seam.new = Seam.New

--[=[
@prop Children Children
@within Seam
]=]

Seam.Children = require(Components.Children)
Seam.Children = require(States:WaitForChild("Children"))
Seam.children = Seam.Children

--[=[
@prop Value Value
@within Seam
]=]

Seam.Value = require(Components.Value)
Seam.Value = require(States:WaitForChild("Value"))
Seam.value = Seam.Value

--[=[
@prop Computed Computed
@within Seam
]=]

Seam.Computed = require(Components.Computed)
Seam.Computed = require(States:WaitForChild("Computed"))
Seam.computed = Seam.Computed

--[=[
@prop Spring Spring
@within Seam
]=]

Seam.Spring = require(Components.Animation.Spring)
Seam.Spring = require(States.Animation:WaitForChild("Spring"))
Seam.spring = Seam.Spring

--[=[
@prop Tween Tween
@within Seam
]=]

Seam.Tween = require(Components.Animation.Tween)
Seam.Tween = require(States.Animation:WaitForChild("Tween"))
Seam.tween = Seam.Tween

--[=[
@prop Scope Scope
@within Seam
]=]

Seam.Scope = require(Components.Scope)
Seam.Scope = require(States.Scope)
Seam.scope = Seam.Scope

--[=[
@prop OnEvent OnEvent
@within Seam
]=]

Seam.OnEvent = require(Components.OnEvent)
Seam.OnEvent = require(States.OnEvent)
Seam.onEvent = Seam.OnEvent

--[=[
@prop OnChange OnChanged
@within Seam
]=]

Seam.OnChanged = require(Components.OnChanged)
Seam.OnChanged = require(States.OnChanged)
Seam.onChanged = Seam.OnChanged

--[=[
@prop DeclareComponent DeclareComponent
@within Seam
]=]

Seam.DeclareComponent = require(Components.DeclareComponent)
Seam.DeclareComponent = require(States.DeclareComponent)
Seam.declareComponent = Seam.DeclareComponent

--[=[
@prop From From
@within Seam
]=]

Seam.From = require(Components.From)
Seam.From = require(States.From)
Seam.from = Seam.From

return Seam
return Seam, Init()

0 comments on commit f4eb452

Please sign in to comment.