--!optimize 2 --!native --!strict local RelayAlgorithmModule = require(script.Parent:WaitForChild("RelayAlgorithm")) local DoorsModule = require(script.Parent:WaitForChild("Doors")) type Leveling = { Leveling: {number}, LevelingBetween: {number} } type ElevatorBox = BasePart type BoxAlignPosition = AlignPosition type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type Impl_Constructor = { __index: Impl_Constructor, constructor: Constructor_Fun, --Class functions BulkConnect: (self: ClassConstructor) -> (), BulkDisconnect: (self: ClassConstructor) -> (), __Ready: (self: ClassConstructor) -> (), __Open: (self: ClassConstructor) -> (), __Goal: (self: ClassConstructor) -> (), __GoalYLevel: (self: ClassConstructor) -> (), } type Constructor_Fun = (RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes, Leveling: Leveling, BoxAlignPosition: BoxAlignPosition, ElevatorBox: ElevatorBox) -> ClassConstructor type Constructor_Return_Props = { RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes, LevelingModule: Leveling, BoxAlignPosition: BoxAlignPosition, ElevatorBox: ElevatorBox, __Connections: { Ready: RBXScriptConnection?, Open: RBXScriptConnection?, GoalYLevel: RBXScriptConnection?, Goal: RBXScriptConnection? } } type ElevatorAttributes = { Relay: { Ready: BoolValue, GoalYLevel: NumberValue, Goal: IntValue }, Stopped: BoolValue } type DoorAttributes = DoorsModule.RelayAttributes export type RelayConstructor = ClassConstructor local Relay = {} :: Impl_Constructor Relay.__index = Relay function Relay.constructor(RelayAlgorthm, ElevatorAttributes, DoorAttributes, LevelingModule, BoxAlignPosition, ElevatorBox) return setmetatable({ RelayAlgorthm = RelayAlgorthm, ElevatorAttributes = ElevatorAttributes, DoorAttributes = DoorAttributes, LevelingModule = LevelingModule, BoxAlignPosition = BoxAlignPosition, ElevatorBox = ElevatorBox, __Connections = {} }, Relay) end function Relay:__Ready() if self.ElevatorAttributes.Relay.Ready.Value then self.BoxAlignPosition.Position = Vector3.new( self.ElevatorBox.Position.X, self.LevelingModule.Leveling[self.RelayAlgorthm.__FloorQueue[1]], self.ElevatorBox.Position.Z ) end end function Relay:__Open() self.ElevatorAttributes.Relay.Ready.Value = self.DoorAttributes.Relay.Open.Value end function Relay:__GoalYLevel() self.BoxAlignPosition.Position = Vector3.new( self.ElevatorBox.Position.X, self.ElevatorAttributes.Relay.GoalYLevel.Value, self.ElevatorBox.Position.Z ) end function Relay:__Goal() local Level: number? = self.LevelingModule.Leveling[self.ElevatorAttributes.Relay.Goal.Value] self.ElevatorAttributes.Relay.GoalYLevel.Value = Level or self.LevelingModule.Leveling[1] :: number end function Relay:BulkConnect() self.__Connections.Ready = self.ElevatorAttributes.Relay.Ready:GetPropertyChangedSignal("Value"):Connect(function() if not self.ElevatorAttributes.Stopped.Value then self:__Ready() end end) self.__Connections.Open = self.DoorAttributes.Relay.Open:GetPropertyChangedSignal("Value"):Connect(function() if not self.ElevatorAttributes.Stopped.Value then self:__Open() end end) self.__Connections.GoalYLevel = self.ElevatorAttributes.Relay.GoalYLevel:GetPropertyChangedSignal("Value"):Connect(function() if not self.ElevatorAttributes.Stopped.Value then self:__GoalYLevel() end end) self.__Connections.Goal = self.ElevatorAttributes.Relay.Goal:GetPropertyChangedSignal("Value"):Connect(function() if not self.ElevatorAttributes.Stopped.Value then self:__Goal() end end) end function Relay:BulkDisconnect() if self.__Connections.Ready and self.__Connections.Ready.Connected then self.__Connections.Ready:Disconnect() end if self.__Connections.Open and self.__Connections.Open.Connected then self.__Connections.Open:Disconnect() end if self.__Connections.GoalYLevel and self.__Connections.GoalYLevel.Connected then self.__Connections.GoalYLevel:Disconnect() end if self.__Connections.Goal and self.__Connections.Goal.Connected then self.__Connections.Goal:Disconnect() end end return Relay