From 1690fbee7489f591e5e5268efb83a0437bbf2f39 Mon Sep 17 00:00:00 2001 From: Reselim Date: Wed, 19 Aug 2020 13:23:16 -0400 Subject: [PATCH] Switch out implicit connection starting for full connection management This brings us back to feature parity with Otter. --- src/GroupMotor.lua | 14 +++++++++----- src/SingleMotor.lua | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/GroupMotor.lua b/src/GroupMotor.lua index d73638c..33234d4 100644 --- a/src/GroupMotor.lua +++ b/src/GroupMotor.lua @@ -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 @@ -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 @@ -77,7 +81,7 @@ function GroupMotor:setGoal(goals) motor:setGoal(goal) end - if self._shouldStartImplicitly then + if self._useImplicitConnections then self:start() end end diff --git a/src/SingleMotor.lua b/src/SingleMotor.lua index 6b67e05..f55689a 100644 --- a/src/SingleMotor.lua +++ b/src/SingleMotor.lua @@ -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 @@ -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 @@ -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