Skip to content

Commit

Permalink
Merge pull request #12 from MiaGobble/SPHI-13-Extended-Functionality
Browse files Browse the repository at this point in the history
Extended functionality
  • Loading branch information
MiaGobble authored Aug 1, 2024
2 parents b3bc3c0 + d0bf297 commit 32dc692
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/Components/Animation/Spring.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ 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 All @@ -133,6 +152,18 @@ function Spring:__call(Value : any, Speed : number, Dampening : number) : Spring
Spring.Coordinate2 = Dampening / High * Spring.Coordinate1 + Velocity / (Speed * High)
end
end
elseif Index == "Value" then
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.Tick0 = os.clock()
end
elseif Index == "Dampening" then
Dampening = NewValue
elseif Index == "Speed" then
Speed = NewValue
end
end,

Expand All @@ -159,6 +190,8 @@ end
function Spring:__index(Index : string)
if Index == "__SEAM_OBJECT" then
return "Spring"
elseif Index == "__SEAM_CAN_BE_SCOPED" then
return true
else
return nil
end
Expand Down
12 changes: 12 additions & 0 deletions src/Components/Animation/Tween.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ function Tween:__call(Value : any, TweenInformation : TweenInfo) : TweenInstance
Tween.Position1 = UnpackedTargetValue[Index]
Tween.Tick0 = os.clock()
end
elseif Index == "Value" then
local UnpackedValue = UnpackType(NewValue, ValueType)

for Index, Tween in ipairs(UnpackedTweens) do
Tween.Position0 = UnpackedValue[Index]
Tween.Position1 = UnpackedValue[Index]
Tween.Tick0 = os.clock()
end
elseif Index == "TweenInformation" then
TweenInformation = NewValue
end
end,

Expand All @@ -121,6 +131,8 @@ end
function Tween:__index(Index : string)
if Index == "__SEAM_OBJECT" then
return "Tween"
elseif Index == "__SEAM_CAN_BE_SCOPED" then
return true
else
return nil
end
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Children.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ end
function Children:__index(Index : string)
if Index == "__SEAM_INDEX" then
return "Children"
elseif Index == "__SEAM_CAN_BE_SCOPED" then
return false
else
return nil
end
Expand Down
16 changes: 15 additions & 1 deletion src/Components/Computed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Computed:__call(Callback : () -> any?)

__index = function(_, Index : string)
if Index == "__SEAM_OBJECT" then
return "Computed"
return "ComputedInstance"
elseif Index == "Value" then
return Callback()
end
Expand All @@ -56,6 +56,20 @@ function Computed:__call(Callback : () -> any?)
return ActiveComputation :: ComputedInstance
end

--[=[
@ignore
]=]

function Computed:__index(Key : string)
if Key == "__SEAM_INDEX" then
return "Computed"
elseif Key == "__SEAM_CAN_BE_SCOPED" then
return true
else
return nil
end
end

local Meta = setmetatable({}, Computed)

return Meta :: ComputedConstructor
8 changes: 8 additions & 0 deletions src/Components/DeclareComponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ function DeclareComponent:__call(ComponentName : string, Constructor : Component
ComponentsManager:PushComponent(ComponentName, Constructor)
end

function DeclareComponent:__index(Key : string)
if Key == "__SEAM_CAN_BE_SCOPED" then
return false
end

return nil
end

local Meta = setmetatable({}, DeclareComponent)

return Meta :: DeclareComponent
8 changes: 8 additions & 0 deletions src/Components/From.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ function From:__call(ComponentName : string, ... : any)
}
end

function From:__index(Key : string)
if Key == "__SEAM_CAN_BE_SCOPED" then
return false
end

return nil
end

return setmetatable({}, From)
2 changes: 2 additions & 0 deletions src/Components/New.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ end
function New:__index(Index : string)
if Index == "__SEAM_OBJECT" then
return "New"
elseif Index == "__SEAM_CAN_BE_SCOPED" then
return true
else
return nil
end
Expand Down
2 changes: 2 additions & 0 deletions src/Components/OnChanged.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ end
function OnChanged:__index(Index : string)
if Index == "__SEAM_INDEX" then
return "OnChanged"
elseif Index == "__SEAM_CAN_BE_SCOPED" then
return false
else
return nil
end
Expand Down
8 changes: 8 additions & 0 deletions src/Components/OnEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ function OnEvent:__call(EventName : string)
return EventBinding
end

function OnEvent:__index(Index : string)
if Index == "__SEAM_CAN_BE_SCOPED" then
return false
else
return nil
end
end

return setmetatable({}, OnEvent)
38 changes: 34 additions & 4 deletions src/Components/Scope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ local Janitor = require(Modules.Janitor)
@param Callback (self : Instance, PropertyName : string) -> any? -- The function to compute the value
]=]

local Meta = setmetatable({}, Scope)

function Scope:__call(ScopedObjects)
local selfClass = {}
local selfMeta = {}
Expand All @@ -35,8 +37,13 @@ function Scope:__call(ScopedObjects)
return self[Key]
end

if typeof(Object) ~= "table" then
error("Object is not a valid Seam object")
if typeof(Object) ~= "table" or not Object.__SEAM_CAN_BE_SCOPED then
if Object.__SEAM_OBJECT or Object.__SEAM_INDEX then
error((Object.__SEAM_OBJECT or Object.__SEAM_INDEX) .. " is not a valid scopable Seam object")
else
error("Object is not a valid scopable Seam object")
end

return
end

Expand All @@ -47,14 +54,29 @@ function Scope:__call(ScopedObjects)
return
end

for Index, Value in ipairs(Tuple) do
for _, Value in ipairs(Tuple) do
self.Janitor:Add(Value)
end

return unpack(Tuple)
end
end

function selfClass:InnerScope()
local NewScope = Meta(ScopedObjects)
self.Janitor:Add(NewScope)
return NewScope
end

function selfClass:AddObject(Object : any)
self.Janitor:Add(Object)
end

function selfClass:RemoveObject(Object : any)
Object:Destroy()
self.Janitor[Object] = nil
end

function selfClass:Destroy()
self.Janitor:Destroy()
self.Janitor = nil
Expand All @@ -68,6 +90,14 @@ function Scope:__call(ScopedObjects)
return Object
end

local Meta = setmetatable({}, Scope)
function Scope:__index(Key : string)
if Key == "__SEAM_OBJECT" then
return "Scope"
elseif Key == "__SEAM_CAN_BE_SCOPED" then
return true
else
return nil
end
end

return Meta :: ScopeConstructor
14 changes: 14 additions & 0 deletions src/Components/Value.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ function Value:__call(Value : any)
return ActiveValue :: ValueInstance
end

--[=[
@ignore
]=]

function Value:__index(Index : string)
if Index == "__SEAM_INDEX" then
return "Value"
elseif Index == "__SEAM_CAN_BE_SCOPED" then
return true
else
return nil
end
end

local Meta = setmetatable({}, Value)

return Meta :: ValueConstructor

0 comments on commit 32dc692

Please sign in to comment.