diff --git a/src/server/main/Elevators/InitElevator/init.luau b/src/server/main/Elevators/InitElevator/init.luau index e5bf3f1..7219b0d 100644 --- a/src/server/main/Elevators/InitElevator/init.luau +++ b/src/server/main/Elevators/InitElevator/init.luau @@ -123,12 +123,12 @@ local function Mover(ElevatorBoxModel: UnionOperation, Responsiveness: number, M end function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions) - print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`) - local _BoxAttachment, BoxAlignPosition, _BoxAlignOrientation = Mover(ElevatorBoxModel, ElevatorConfigurationTable.Responsiveness, ElevatorConfigurationTable.MaxVelocity) + local RelayAlgorithmConstructor = RelayAlgorithm.constructor(BoxAlignPosition) + local Events = { CabProgression = Instance.new("BindableEvent") :: BindableEvent, CabTraveling = Instance.new("BindableEvent") :: BindableEvent, @@ -150,10 +150,11 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo Attributes.GoingUp.Value = false Attributes.Goal.Value = 1 - return setmetatable({ - RelayAlgorithm = RelayAlgorithm.constructor(BoxAlignPosition), - FloorLevelingPositions = FloorLevelingPositions, + print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`) + return setmetatable({ + RelayAlgorithm = RelayAlgorithmConstructor, + FloorLevelingPositions = FloorLevelingPositions, Elevator = { BoxModel = ElevatorBoxModel, AlignPosition = BoxAlignPosition, diff --git a/src/server/main/Elevators/Mover.luau b/src/server/main/Elevators/Mover.luau deleted file mode 100644 index 8586f45..0000000 --- a/src/server/main/Elevators/Mover.luau +++ /dev/null @@ -1,29 +0,0 @@ ---!optimize 2 ---!native ---!strict - -return function(ElevatorBox: BasePart, StartPosition: Vector3, Responsiveness: number, MaxVelocity: number): (Attachment, AlignPosition, AlignOrientation) - local BoxAttachment = Instance.new("Attachment") - BoxAttachment.Parent = ElevatorBox - - local BoxAlignPosition = Instance.new("AlignPosition") - BoxAlignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment - BoxAlignPosition.Attachment0 = BoxAttachment - BoxAlignPosition.MaxForce = math.huge - BoxAlignPosition.Position = StartPosition - -- BoxAlignPosition.RigidityEnabled = true - -- Lines below are disabled with RigidityEnabled true - BoxAlignPosition.Responsiveness = Responsiveness - BoxAlignPosition.MaxVelocity = MaxVelocity - -- - BoxAlignPosition.Parent = ElevatorBox - - local BoxAlignOrientation = Instance.new("AlignOrientation") - BoxAlignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment - BoxAlignOrientation.Attachment0 = BoxAttachment - BoxAlignOrientation.RigidityEnabled = true - BoxAlignOrientation.CFrame = CFrame.new(0,0,0)*CFrame.fromOrientation(0,0,0) - BoxAlignOrientation.Parent = ElevatorBox - - return BoxAttachment, BoxAlignPosition, BoxAlignOrientation -end \ No newline at end of file diff --git a/src/server/main/Elevators/Otis1960/Config.luau b/src/server/main/Elevators/Otis1960/Config.luau new file mode 100644 index 0000000..c627c6d --- /dev/null +++ b/src/server/main/Elevators/Otis1960/Config.luau @@ -0,0 +1,33 @@ +--!optimize 2 +--!native +--!strict + +local MainDir = script.Parent.Parent.Parent +local StorageService = game:GetService("ReplicatedStorage") + +local Enums = require(StorageService:WaitForChild("Enums")) +local SoundEnums = require(MainDir:WaitForChild("Enums"):WaitForChild("Sounds")) + +local ElevatorConfiguration = {} +ElevatorConfiguration.Name = Enums.Elevator.Otis1960 +ElevatorConfiguration.FloorLevelingDistance = 4 +ElevatorConfiguration.FloorLeveling3PhaseDistance = 1.5 +ElevatorConfiguration.ParkedDistance = 0.2 +ElevatorConfiguration.Responsiveness = 20 +ElevatorConfiguration.MaxVelocity = 7 +ElevatorConfiguration.LevelingVelocity = 2 +ElevatorConfiguration.Phase3LevelingVelocity = .5 + +ElevatorConfiguration.Sounds = { + LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection, + LanternChimeLanding = SoundEnums.Otis1960.LanternChimeLanding +} + +ElevatorConfiguration.Colors = { + ButtonActivated = Color3.fromRGB(180,0,0), + ButtonDeactivated = Color3.fromRGB(139,139,139), + LanternDisplayOn = Color3.fromRGB(255,114,71), + LanternDisplayOff = Color3.fromRGB(55,55,55), +} + +return ElevatorConfiguration diff --git a/src/server/main/Elevators/Otis1960/Leveling.luau b/src/server/main/Elevators/Otis1960/Leveling.luau index be65a14..742c0a1 100644 --- a/src/server/main/Elevators/Otis1960/Leveling.luau +++ b/src/server/main/Elevators/Otis1960/Leveling.luau @@ -15,6 +15,4 @@ local Leveling: {number} = { [10] = 239.245, } -return { - Leveling = Leveling -} +return Leveling diff --git a/src/server/main/Elevators/Otis1960/Moving.luau b/src/server/main/Elevators/Otis1960/Moving.luau deleted file mode 100644 index 8c07b63..0000000 --- a/src/server/main/Elevators/Otis1960/Moving.luau +++ /dev/null @@ -1,233 +0,0 @@ ---!optimize 2 ---!native ---!strict - -local Dir = script.Parent -local ElevatorsDir = Dir.Parent - -local Lanterns = require(ElevatorsDir:WaitForChild("Lanterns")) -local TractionRopes = require(ElevatorsDir:WaitForChild("TractionRopes")) -local MovingObjects = require(Dir:WaitForChild("MovingObjects")) -local LevelingModule = require(Dir:WaitForChild("Leveling")) -local PhysicalRelays = require(Dir:WaitForChild("PhysicalRelay")) -local RelayAlgorithm = require(Dir:WaitForChild("RelayAlgorithm")) -local ElevatorDoors = require(Dir:WaitForChild("Doors")) - -type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) -type Impl_Constructor = { - __index: Impl_Constructor, - constructor: Constructor_Fun, - --Class functions - Start: (self: ClassConstructor, GoingUp: boolean, RequestedLevel: number, ElevatorBox_1960: BasePart, BoxAlignPosition: AlignPosition) -> (), -} - -type Constructor_Fun = ( - ElevatorAttributes: ElevatorAttributes, - LanternsConstructor: Lanterns.LanternsConstructor, - TractionRopesConstructor: TractionRopes.TractionRopesConstructor, - MovingObjectsConstructor: MovingObjects.MovingObjectsConstructor, - PhysicalRelaysConstructor: PhysicalRelays.PhysicalRelayConstructor, - RelayAlgorithmConstructor: RelayAlgorithm.RelayAlgorithmConstructor, - ElevatorDoorsConstructor: ElevatorDoors.DoorConstructor -) -> ClassConstructor - -type Constructor_Return_Props = { - LanternsConstructor: Lanterns.LanternsConstructor, - ElevatorAttributes: ElevatorAttributes, - TractionRopesConstructor: TractionRopes.TractionRopesConstructor, - MovingObjectsConstructor: MovingObjects.MovingObjectsConstructor, - PhysicalRelaysConstructor: PhysicalRelays.PhysicalRelayConstructor, - RelayAlgorithmConstructor: RelayAlgorithm.RelayAlgorithmConstructor, - - __Connections: { - Moving: RBXScriptConnection? - } -} - -type ElevatorAttributes = { - CurrentFloor: IntValue, - Moving: BoolValue, - GoingUp: BoolValue, - FloorLevelingDistance: number, - LeveledDistance: number, - DoorOpeningDistance: number, - FloorLeveling3PhaseDistance: number, - QueueWaitTime: number, - - Relay: { - Goal: IntValue, - ReadyForMoving: BoolValue - } -} - -export type MovingConstructor = ClassConstructor - -local Moving = {} :: Impl_Constructor -Moving.__index = Moving - -local RS = game:GetService("RunService") - -local DoorsOpeningDebounce = false - -function Moving.constructor( - ElevatorAttributes, - LanternsConstructor, - TractionRopesConstructor, - MovingObjectsConstructor, - PhysicalRelaysConstructor, - RelayAlgorithmConstructor, - ElevatorDoorsConstructor -) - return setmetatable({ - ElevatorAttributes = ElevatorAttributes, - LanternsConstructor = LanternsConstructor, - TractionRopesConstructor = TractionRopesConstructor, - MovingObjectsConstructor = MovingObjectsConstructor, - PhysicalRelaysConstructor = PhysicalRelaysConstructor, - RelayAlgorithmConstructor = RelayAlgorithmConstructor, - ElevatorDoorsConstructor = ElevatorDoorsConstructor, - - __Connections = {} - }, Moving) -end - -local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean - return CurrentFloor=NextLevelBetweenFloors then - self.ElevatorAttributes.CurrentFloor.Value+=1 - - self.LanternsConstructor:Toggle(true, self.ElevatorAttributes.CurrentFloor.Value) - self.LanternsConstructor:Toggle(false, self.ElevatorAttributes.CurrentFloor.Value-1) - end -end - -local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) - local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[self.ElevatorAttributes.CurrentFloor.Value-1] - - if NextLevelBetweenFloors and ElevatorPositionY<=NextLevelBetweenFloors then - self.ElevatorAttributes.CurrentFloor.Value-=1 - - self.LanternsConstructor:Toggle(true, self.ElevatorAttributes.CurrentFloor.Value) - self.LanternsConstructor:Toggle(false, self.ElevatorAttributes.CurrentFloor.Value+1) - end -end - -local function UpDirection(self: ClassConstructor, ElevatorPositionY: number, BoxAlignY: number, RequestedLevel: number) - FloorPassingUp(self, ElevatorPositionY, self.ElevatorAttributes.Relay.Goal.Value) - - if ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.FloorLevelingDistance then - Leveling(self, self.ElevatorAttributes.Relay.Goal.Value) - - if ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.FloorLeveling3PhaseDistance then - Leveling3Phase(self, RequestedLevel) - - if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.DoorOpeningDistance then - DoorsOpeningDebounce = true - self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, self.ElevatorAttributes.Relay.Goal.Value) - end - end - end - - if ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.LeveledDistance then - Leveled(self, self.ElevatorAttributes.Relay.Goal.Value) - end -end - -local function DownDirection(self: ClassConstructor, ElevatorPositionY: number, BoxAlignY: number, RequestedLevel: number) - FloorPassingDown(self, ElevatorPositionY, self.ElevatorAttributes.Relay.Goal.Value) - - if ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.FloorLevelingDistance then - Leveling(self, self.ElevatorAttributes.Relay.Goal.Value) - - if ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.FloorLeveling3PhaseDistance then - Leveling3Phase(self, RequestedLevel) - - if not DoorsOpeningDebounce and ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.DoorOpeningDistance then - DoorsOpeningDebounce = true - self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, self.ElevatorAttributes.Relay.Goal.Value) - end - end - end - - if ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.LeveledDistance then - Leveled(self, self.ElevatorAttributes.Relay.Goal.Value) - end -end - -function Moving:Start(GoingUp, RequestedLevel, ElevatorBox_1960, BoxAlignPosition) - local MovingDelta = 0 - - self.ElevatorAttributes.GoingUp.Value = GoingUp - self.ElevatorAttributes.Relay.Goal.Value = RequestedLevel - self.ElevatorAttributes.Moving.Value = true - - self.PhysicalRelaysConstructor:SetState(GoingUp and "UP" or "DOWN", true, false) - self.PhysicalRelaysConstructor:SetState("240 V", true, false) - self.PhysicalRelaysConstructor:SetState("440 V", true, false) - - self.MovingObjectsConstructor:UpdateCFrame() - - if self.__Connections.Moving and self.__Connections.Moving.Connected then - self.__Connections.Moving:Disconnect() - end - self.__Connections.Moving = RS.Heartbeat:Connect(function(_) - MovingDelta+=1 - - local ElevatorPosition = ElevatorBox_1960.Position - local ElevatorPositionY = ElevatorPosition.Y - local ElevatorVelocityY = ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y - local BoxAlignY = BoxAlignPosition.Position.Y - - self.TractionRopesConstructor:Move(27, ElevatorPosition) - self.MovingObjectsConstructor:FramePullies(MovingDelta, ElevatorVelocityY) - - if self.ElevatorAttributes.GoingUp.Value then - UpDirection(self, ElevatorPositionY, BoxAlignY, RequestedLevel) - else - DownDirection(self, ElevatorPositionY, BoxAlignY, RequestedLevel) - end - end) -end - -return Moving \ No newline at end of file diff --git a/src/server/main/Elevators/Otis1960/Relay.luau b/src/server/main/Elevators/Otis1960/Relay.luau deleted file mode 100644 index 7d4badb..0000000 --- a/src/server/main/Elevators/Otis1960/Relay.luau +++ /dev/null @@ -1,115 +0,0 @@ ---!optimize 2 ---!native ---!strict - -local ElevatorDir = script.Parent - -local RelayAlgorithmModule = require(ElevatorDir:WaitForChild("RelayAlgorithm")) -local DoorsModule = require(ElevatorDir:WaitForChild("Doors")) -local PhysicalRelay = require(ElevatorDir:WaitForChild("PhysicalRelay")) - -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) -> (), - __Open: (self: ClassConstructor) -> (), - __Goal: (self: ClassConstructor) -> (), -} - -type Constructor_Fun = ( - PhysicalRelay: PhysicalRelay.PhysicalRelayConstructor, - RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor, - ElevatorAttributes: ElevatorAttributes, - DoorAttributes: DoorAttributes, - Leveling: Leveling, - BoxAlignPosition: BoxAlignPosition, - ElevatorBox: ElevatorBox -) -> ClassConstructor - -type Constructor_Return_Props = { - PhysicalRelay: PhysicalRelay.PhysicalRelayConstructor, - RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor, - ElevatorAttributes: ElevatorAttributes, - DoorAttributes: DoorAttributes, - LevelingModule: Leveling, - BoxAlignPosition: BoxAlignPosition, - ElevatorBox: ElevatorBox, - - __Connections: { - ReadyForMoving: RBXScriptConnection?, - Open: RBXScriptConnection?, - Goal: RBXScriptConnection? - } -} - -type ElevatorAttributes = { - Relay: { - ReadyForMoving: BoolValue, - Goal: IntValue - }, - - Stopped: BoolValue -} - -type DoorAttributes = DoorsModule.RelayAttributes - -export type RelayConstructor = ClassConstructor - -local Relay = {} :: Impl_Constructor -Relay.__index = Relay - -function Relay.constructor(PhysicalRelay, RelayAlgorthm, ElevatorAttributes, DoorAttributes, LevelingModule, BoxAlignPosition, ElevatorBox) - return setmetatable({ - PhysicalRelay = PhysicalRelay, - RelayAlgorthm = RelayAlgorthm, - ElevatorAttributes = ElevatorAttributes, - DoorAttributes = DoorAttributes, - LevelingModule = LevelingModule, - BoxAlignPosition = BoxAlignPosition, - ElevatorBox = ElevatorBox, - - __Connections = {} - }, Relay) -end - -function Relay:__Open() - self.ElevatorAttributes.Relay.ReadyForMoving.Value = not self.DoorAttributes.Relay.Open.Value -end - -function Relay:BulkConnect() - local ReadyForMovingRelay = self.ElevatorAttributes.Relay.ReadyForMoving - local OpenRelay = self.DoorAttributes.Relay.Open - - self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function() - self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value, false) - end) - - self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function() - self.PhysicalRelay:SetState("DO", OpenRelay.Value, true) - - if not self.ElevatorAttributes.Stopped.Value then - self:__Open() - end - end) -end - -function Relay:BulkDisconnect() - if self.__Connections.ReadyForMoving and self.__Connections.ReadyForMoving.Connected then - self.__Connections.ReadyForMoving:Disconnect() - end - if self.__Connections.Open and self.__Connections.Open.Connected then - self.__Connections.Open:Disconnect() - end -end - -return Relay \ No newline at end of file diff --git a/src/server/main/Elevators/Otis1960/init.luau b/src/server/main/Elevators/Otis1960/init.luau index 53c9f06..a6180dc 100644 --- a/src/server/main/Elevators/Otis1960/init.luau +++ b/src/server/main/Elevators/Otis1960/init.luau @@ -2,246 +2,19 @@ --!native --!strict ---Set relay tags through studio command line ---[[ -local s = game.Selection:Get()[1] - -for i,v in s:GetChildren() do - if v:IsA("Model") then - local main = v:FindFirstChild("main") - if main then - local label = v:FindFirstChildWhichIsA("TextLabel", true) - if label then - main:AddTag(`Otis1960_RelayButton_{label.Text}`) - end - end - end -end -]] - -local Elevators = script.Parent -local MainDir = Elevators.Parent -local EnumsDir = MainDir:WaitForChild("Enums") -local LoadDir = MainDir:WaitForChild("Load") - +local ParentDir = script.Parent +local MainDir = ParentDir.Parent local StorageService = game:GetService("ReplicatedStorage") -local RunService = game:GetService("RunService") +local InitElevator = require(ParentDir:WaitForChild("InitElevator")) + +local TagsModule = require(MainDir:WaitForChild("Load"):WaitForChild("Tags")) +local SoundEnums = require(MainDir:WaitForChild("Enums"):WaitForChild("Sounds")) local Enums = require(StorageService:WaitForChild("Enums")) -local SoundEnums = require(EnumsDir:WaitForChild("Sounds")) -local LevelingModule = require(script:WaitForChild("Leveling")) +local ElevatorConfigurationTable = require(script:WaitForChild("Config")) +local FloorLevelingPositions = require(script:WaitForChild("Leveling")) -local Tags = require(LoadDir:WaitForChild("Tags")) - -type Tags = Tags.ExportedTags -type TagsConstructor = Tags.TagsConstructor - -type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) -type Impl_Constructor = { - __index: Impl_Constructor, - constructor: Constructor_Fun, - --Class functions - RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean, - __TravelToFloor: (self: ClassConstructor, LevelInt: number, LevelVec3: number, ElevatorGoingUp: boolean) -> (), -} & Impl_Static_Props - -type ElevatorConfigurationTable = { - Name: Enums.ElevatorValues, - Responsiveness: number, - MaxVelocity: number, - FloorLevelingDistance: number, - FloorLeveling3PhaseDistance: number, - ParkedDistance: number, - LevelingVelocity: number, - Phase3LevelingVelocity: number, - Sounds: { - LanternChimeDirection: SoundEnums.ElevatorSoundValues, - LanternChimeLanding: SoundEnums.ElevatorSoundValues, - }, - Colors: { - ButtonActivated: Color3, - ButtonDeactivated: Color3, - LanternDisplayOn: Color3, - LanternDisplayOff: Color3, - }, -} - -type Impl_Static_Props = {} - -type Constructor_Fun = (ElevatorConfigurationTable: ElevatorConfigurationTable) -> ClassConstructor - -type Constructor_Return_Props = { - ElevatorConfiguration: ElevatorConfigurationTable, - - Attributes: { - PreviousFloor: IntValue, - CurrentFloor: IntValue, - NextFloor: IntValue, - Moving: BoolValue, - GoingUp: BoolValue, - Stopped: BoolValue, - Goal: IntValue - }, - Events: { - CabProgression: BindableEvent, - CabTraveling: BindableEvent, - Parked: BindableEvent, - Leveling: BindableEvent, - Leveling3Phase: BindableEvent, - }, - - __Connections: { - Moving: RBXScriptConnection?, - } -} - -local Elevator = {} :: Impl_Constructor -Elevator.__index = Elevator - -local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean - -- -(CurrentFloor-RequestedFloor)>0 - -- -CurrentFloor+RequestedFloor>0 - return CurrentFloor