Skip to content

Commit

Permalink
Switch out implicit connection starting for full connection management
Browse files Browse the repository at this point in the history
This brings us back to feature parity with Otter.
  • Loading branch information
Reselim committed Aug 19, 2020
1 parent fe62664 commit 1690fbe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/GroupMotor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ local function toMotor(value)
error(("Unable to convert %q to motor; type %s is unsupported"):format(value, valueType), 2)
end

function GroupMotor.new(initialValues, shouldStartImplicitly)
function GroupMotor.new(initialValues, useImplicitConnections)
assert(initialValues, "Missing argument #1: initialValues")
assert(typeof(initialValues) == "table", "initialValues must be a table!")

local self = setmetatable(BaseMotor.new(), GroupMotor)

if shouldStartImplicitly ~= nil then
self._shouldStartImplicitly = shouldStartImplicitly
if useImplicitConnections ~= nil then
self._useImplicitConnections = useImplicitConnections
else
self._shouldStartImplicitly = true
self._useImplicitConnections = true
end

self._complete = true
Expand Down Expand Up @@ -62,6 +62,10 @@ function GroupMotor:step(deltaTime)
self._onStep:fire(self:getValue())

if allMotorsComplete then
if self._useImplicitConnections then
self:stop()
end

self._complete = true
self._onComplete:fire()
end
Expand All @@ -77,7 +81,7 @@ function GroupMotor:setGoal(goals)
motor:setGoal(goal)
end

if self._shouldStartImplicitly then
if self._useImplicitConnections then
self:start()
end
end
Expand Down
14 changes: 9 additions & 5 deletions src/SingleMotor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ local BaseMotor = require(script.Parent.BaseMotor)
local SingleMotor = setmetatable({}, BaseMotor)
SingleMotor.__index = SingleMotor

function SingleMotor.new(initialValue, shouldStartImplicitly)
function SingleMotor.new(initialValue, useImplicitConnections)
assert(initialValue, "Missing argument #1: initialValue")
assert(typeof(initialValue) == "number", "initialValue must be a number!")

local self = setmetatable(BaseMotor.new(), SingleMotor)

if shouldStartImplicitly ~= nil then
self._shouldStartImplicitly = shouldStartImplicitly
if useImplicitConnections ~= nil then
self._useImplicitConnections = useImplicitConnections
else
self._shouldStartImplicitly = true
self._useImplicitConnections = true
end

self._goal = nil
Expand All @@ -35,6 +35,10 @@ function SingleMotor:step(deltaTime)
self._onStep:fire(newState.value)

if newState.complete then
if self._useImplicitConnections then
self:stop()
end

self._onComplete:fire()
end

Expand All @@ -49,7 +53,7 @@ function SingleMotor:setGoal(goal)
self._state.complete = false
self._goal = goal

if self._shouldStartImplicitly then
if self._useImplicitConnections then
self:start()
end
end
Expand Down

0 comments on commit 1690fbe

Please sign in to comment.