diff --git a/sourcemap.json b/sourcemap.json index 48cc2f8..d97f048 100644 --- a/sourcemap.json +++ b/sourcemap.json @@ -1 +1 @@ -{"name":"ElevatorGame","className":"DataModel","filePaths":["default.project.json"],"children":[{"name":"ReplicatedFirst","className":"ReplicatedFirst","children":[{"name":"intro","className":"LocalScript","filePaths":["src/load/intro/init.client.luau"],"children":[{"name":"IntroGui","className":"ModuleScript","filePaths":["src/load/intro/IntroGui.luau"]}]}]},{"name":"ReplicatedStorage","className":"ReplicatedStorage","children":[{"name":"Algebra","className":"ModuleScript","filePaths":["src/shared/Algebra.luau"]},{"name":"Client","className":"Folder","children":[{"name":"Camera","className":"ModuleScript","filePaths":["src/shared/Client/Camera.luau"]},{"name":"KeyBinds","className":"ModuleScript","filePaths":["src/shared/Client/KeyBinds.luau"]}]},{"name":"Delta","className":"ModuleScript","filePaths":["src/shared/Delta.luau"]},{"name":"Enums","className":"ModuleScript","filePaths":["src/shared/Enums.luau"]},{"name":"Property","className":"ModuleScript","filePaths":["src/shared/Property.luau"]},{"name":"Server","className":"Folder","children":[{"name":"holder","className":"ModuleScript","filePaths":["src/shared/Server/holder.luau"]}]},{"name":"Tween","className":"ModuleScript","filePaths":["src/shared/Tween.luau"]}]},{"name":"ServerScriptService","className":"ServerScriptService","children":[{"name":"rapid/server","className":"Actor","children":[{"name":"main","className":"Script","filePaths":["src/server/main/init.server.luau"],"children":[{"name":"Elevators","className":"Folder","children":[{"name":"ButtonsManager","className":"ModuleScript","filePaths":["src/server/main/Elevators/ButtonsManager.luau"]},{"name":"HallDisplays","className":"ModuleScript","filePaths":["src/server/main/Elevators/HallDisplays.luau"]},{"name":"InitElevator","className":"ModuleScript","filePaths":["src/server/main/Elevators/InitElevator/init.luau"],"children":[{"name":"RelayAlgorithm","className":"ModuleScript","filePaths":["src/server/main/Elevators/InitElevator/RelayAlgorithm.luau"]}]},{"name":"Lanterns","className":"ModuleScript","filePaths":["src/server/main/Elevators/Lanterns.luau"]},{"name":"Otis1960","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/init.luau"],"children":[{"name":"Config","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/Config.luau"]},{"name":"Doors","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/Doors.luau"]},{"name":"Leveling","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/Leveling.luau"]},{"name":"MovingObjects","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/MovingObjects.luau"]},{"name":"PhysicalRelay","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/PhysicalRelay.luau"]}]},{"name":"TractionRopes","className":"ModuleScript","filePaths":["src/server/main/Elevators/TractionRopes.luau"]}]},{"name":"Enums","className":"Folder","children":[{"name":"Sounds","className":"ModuleScript","filePaths":["src/server/main/Enums/Sounds.luau"]}]},{"name":"Lighting","className":"ModuleScript","filePaths":["src/server/main/Lighting/init.luau"]},{"name":"Load","className":"Folder","children":[{"name":"EditorEntities","className":"ModuleScript","filePaths":["src/server/main/Load/EditorEntities.luau"]},{"name":"StarterPlayer","className":"ModuleScript","filePaths":["src/server/main/Load/StarterPlayer.luau"]},{"name":"Tags","className":"ModuleScript","filePaths":["src/server/main/Load/Tags/init.luau"],"children":[{"name":"Buttons","className":"ModuleScript","filePaths":["src/server/main/Load/Tags/Buttons.luau"]},{"name":"Lights","className":"ModuleScript","filePaths":["src/server/main/Load/Tags/Lights.luau"]}]},{"name":"Workspace","className":"ModuleScript","filePaths":["src/server/main/Load/Workspace.luau"]}]},{"name":"Map","className":"Folder","children":[{"name":"Interactions","className":"Folder","children":[{"name":"LightSwitches","className":"ModuleScript","filePaths":["src/server/main/Map/Interactions/LightSwitches.luau"]}]},{"name":"Prompts","className":"ModuleScript","filePaths":["src/server/main/Map/Prompts.luau"]}]},{"name":"PlayerAdded","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/init.luau"],"children":[{"name":"Character","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/init.luau"],"children":[{"name":"Actions","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/Actions.luau"]},{"name":"Flashlight","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/Flashlight.luau"]},{"name":"Shadows","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/Shadows.luau"]},{"name":"SpineKinematics","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/SpineKinematics.luau"]}]},{"name":"Users","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Users.luau"]}]},{"name":"Types","className":"Folder","children":[{"name":"Elevator","className":"ModuleScript","filePaths":["src/server/main/Types/Elevator.luau"]}]}]}]}]},{"name":"StarterPlayer","className":"StarterPlayer","children":[{"name":"StarterPlayerScripts","className":"StarterPlayerScripts","children":[{"name":"rapid/client","className":"Folder","children":[{"name":"Player","className":"LocalScript","filePaths":["src/client/init.client.luau"],"children":[{"name":"Character","className":"ModuleScript","filePaths":["src/client/Character/init.luau"],"children":[{"name":"Actions","className":"ModuleScript","filePaths":["src/client/Character/Actions.luau"]},{"name":"Camera","className":"ModuleScript","filePaths":["src/client/Character/Camera/init.luau"],"children":[{"name":"Bobbing","className":"ModuleScript","filePaths":["src/client/Character/Camera/Bobbing.luau"]}]},{"name":"Humanoid","className":"ModuleScript","filePaths":["src/client/Character/Humanoid.luau"]},{"name":"HumanoidRootPart","className":"ModuleScript","filePaths":["src/client/Character/HumanoidRootPart.luau"]},{"name":"Sound","className":"Folder","children":[{"name":"Relays","className":"ModuleScript","filePaths":["src/client/Character/Sound/Relays.luau"]}]},{"name":"SpineKinematics","className":"ModuleScript","filePaths":["src/client/Character/SpineKinematics.luau"]}]},{"name":"CoreGuis","className":"ModuleScript","filePaths":["src/client/CoreGuis.luau"]},{"name":"GuiService","className":"ModuleScript","filePaths":["src/client/GuiService.luau"]},{"name":"Mouse","className":"ModuleScript","filePaths":["src/client/Mouse.luau"]},{"name":"UI","className":"Folder","children":[{"name":"Crosshair","className":"ModuleScript","filePaths":["src/client/UI/Crosshair.luau"]},{"name":"Health","className":"ModuleScript","filePaths":["src/client/UI/Health.luau"]},{"name":"Vignette","className":"ModuleScript","filePaths":["src/client/UI/Vignette.luau"]}]}]}]}]}]}]} \ No newline at end of file +{"name":"ElevatorGame","className":"DataModel","filePaths":["default.project.json"],"children":[{"name":"ReplicatedFirst","className":"ReplicatedFirst","children":[{"name":"intro","className":"LocalScript","filePaths":["src/load/intro/init.client.luau"],"children":[{"name":"IntroGui","className":"ModuleScript","filePaths":["src/load/intro/IntroGui.luau"]}]}]},{"name":"ReplicatedStorage","className":"ReplicatedStorage","children":[{"name":"Algebra","className":"ModuleScript","filePaths":["src/shared/Algebra.luau"]},{"name":"Client","className":"Folder","children":[{"name":"Camera","className":"ModuleScript","filePaths":["src/shared/Client/Camera.luau"]},{"name":"KeyBinds","className":"ModuleScript","filePaths":["src/shared/Client/KeyBinds.luau"]}]},{"name":"Delta","className":"ModuleScript","filePaths":["src/shared/Delta.luau"]},{"name":"Enums","className":"ModuleScript","filePaths":["src/shared/Enums.luau"]},{"name":"Output","className":"ModuleScript","filePaths":["src/shared/Output.luau"]},{"name":"Property","className":"ModuleScript","filePaths":["src/shared/Property.luau"]},{"name":"Server","className":"Folder","children":[{"name":"holder","className":"ModuleScript","filePaths":["src/shared/Server/holder.luau"]}]},{"name":"Tween","className":"ModuleScript","filePaths":["src/shared/Tween.luau"]}]},{"name":"ServerScriptService","className":"ServerScriptService","children":[{"name":"rapid/server","className":"Actor","children":[{"name":"main","className":"Script","filePaths":["src/server/main/init.server.luau"],"children":[{"name":"Elevators","className":"Folder","children":[{"name":"ButtonsManager","className":"ModuleScript","filePaths":["src/server/main/Elevators/ButtonsManager.luau"]},{"name":"HallDisplays","className":"ModuleScript","filePaths":["src/server/main/Elevators/HallDisplays.luau"]},{"name":"InitElevator","className":"ModuleScript","filePaths":["src/server/main/Elevators/InitElevator/init.luau"],"children":[{"name":"RelayAlgorithm","className":"ModuleScript","filePaths":["src/server/main/Elevators/InitElevator/RelayAlgorithm.luau"]}]},{"name":"Lanterns","className":"ModuleScript","filePaths":["src/server/main/Elevators/Lanterns.luau"]},{"name":"Otis1960","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/init.luau"],"children":[{"name":"Config","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/Config.luau"]},{"name":"Doors","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/Doors.luau"]},{"name":"Leveling","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/Leveling.luau"]},{"name":"MovingObjects","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/MovingObjects.luau"]},{"name":"PhysicalRelay","className":"ModuleScript","filePaths":["src/server/main/Elevators/Otis1960/PhysicalRelay.luau"]}]},{"name":"TractionRopes","className":"ModuleScript","filePaths":["src/server/main/Elevators/TractionRopes.luau"]}]},{"name":"Enums","className":"Folder","children":[{"name":"Sounds","className":"ModuleScript","filePaths":["src/server/main/Enums/Sounds.luau"]}]},{"name":"Lighting","className":"ModuleScript","filePaths":["src/server/main/Lighting/init.luau"]},{"name":"Load","className":"Folder","children":[{"name":"EditorEntities","className":"ModuleScript","filePaths":["src/server/main/Load/EditorEntities.luau"]},{"name":"StarterPlayer","className":"ModuleScript","filePaths":["src/server/main/Load/StarterPlayer.luau"]},{"name":"Tags","className":"ModuleScript","filePaths":["src/server/main/Load/Tags/init.luau"],"children":[{"name":"Buttons","className":"ModuleScript","filePaths":["src/server/main/Load/Tags/Buttons.luau"]},{"name":"Lights","className":"ModuleScript","filePaths":["src/server/main/Load/Tags/Lights.luau"]}]},{"name":"Workspace","className":"ModuleScript","filePaths":["src/server/main/Load/Workspace.luau"]}]},{"name":"Map","className":"Folder","children":[{"name":"Interactions","className":"Folder","children":[{"name":"LightSwitches","className":"ModuleScript","filePaths":["src/server/main/Map/Interactions/LightSwitches.luau"]}]},{"name":"Prompts","className":"ModuleScript","filePaths":["src/server/main/Map/Prompts.luau"]}]},{"name":"PlayerAdded","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/init.luau"],"children":[{"name":"Character","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/init.luau"],"children":[{"name":"Actions","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/Actions.luau"]},{"name":"Flashlight","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/Flashlight.luau"]},{"name":"Shadows","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/Shadows.luau"]},{"name":"SpineKinematics","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Character/SpineKinematics.luau"]}]},{"name":"Users","className":"ModuleScript","filePaths":["src/server/main/PlayerAdded/Users.luau"]}]},{"name":"Types","className":"Folder","children":[{"name":"Elevator","className":"ModuleScript","filePaths":["src/server/main/Types/Elevator.luau"]}]}]}]}]},{"name":"StarterPlayer","className":"StarterPlayer","children":[{"name":"StarterPlayerScripts","className":"StarterPlayerScripts","children":[{"name":"rapid/client","className":"Folder","children":[{"name":"Player","className":"LocalScript","filePaths":["src/client/init.client.luau"],"children":[{"name":"Character","className":"ModuleScript","filePaths":["src/client/Character/init.luau"],"children":[{"name":"Actions","className":"ModuleScript","filePaths":["src/client/Character/Actions.luau"]},{"name":"Camera","className":"ModuleScript","filePaths":["src/client/Character/Camera/init.luau"],"children":[{"name":"Bobbing","className":"ModuleScript","filePaths":["src/client/Character/Camera/Bobbing.luau"]}]},{"name":"Humanoid","className":"ModuleScript","filePaths":["src/client/Character/Humanoid.luau"]},{"name":"HumanoidRootPart","className":"ModuleScript","filePaths":["src/client/Character/HumanoidRootPart.luau"]},{"name":"Sound","className":"Folder","children":[{"name":"Relays","className":"ModuleScript","filePaths":["src/client/Character/Sound/Relays.luau"]}]},{"name":"SpineKinematics","className":"ModuleScript","filePaths":["src/client/Character/SpineKinematics.luau"]}]},{"name":"CoreGuis","className":"ModuleScript","filePaths":["src/client/CoreGuis.luau"]},{"name":"GuiService","className":"ModuleScript","filePaths":["src/client/GuiService.luau"]},{"name":"Mouse","className":"ModuleScript","filePaths":["src/client/Mouse.luau"]},{"name":"UI","className":"Folder","children":[{"name":"Crosshair","className":"ModuleScript","filePaths":["src/client/UI/Crosshair.luau"]},{"name":"Health","className":"ModuleScript","filePaths":["src/client/UI/Health.luau"]},{"name":"Vignette","className":"ModuleScript","filePaths":["src/client/UI/Vignette.luau"]}]}]}]}]}]}]} \ No newline at end of file diff --git a/src/server/main/Elevators/InitElevator/RelayAlgorithm.luau b/src/server/main/Elevators/InitElevator/RelayAlgorithm.luau index fa57244..a18e5e9 100644 --- a/src/server/main/Elevators/InitElevator/RelayAlgorithm.luau +++ b/src/server/main/Elevators/InitElevator/RelayAlgorithm.luau @@ -2,28 +2,35 @@ --!native --!strict +--Slap this here +--The Otis relay based call logic +--https://youtu.be/BCN9mQOT3RQ + +local StorageService = game:GetService("ReplicatedStorage") +local Enums = require(StorageService:WaitForChild("Enums")) + type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type Impl_Constructor = { __index: Impl_Constructor, constructor: Constructor_Fun, --Class functions - Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (), - AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, GoingUpAttribute: BoolValue, RequestedLevel: number) -> (), + Sort: (self: ClassConstructor, Direction: Enums.ElevatorCallDirectionValues) -> (), + AddFloor: (self: ClassConstructor, Direction: Enums.ElevatorCallDirectionValues, RequestedLevel: number) -> (), } +export type RelayAlgorithmEvents = { + Sorted: RBXScriptSignal, + Added: RBXScriptSignal, + __eventInstances__: { + Sorted: BindableEvent, + Added: BindableEvent + } +} type Constructor_Fun = (ElevatorBoxModel: AlignPosition) -> ClassConstructor type Constructor_Return_Props = { ElevatorBoxModel: AlignPosition, - __FloorQueue: FloorQueue, - - Events: { - Sorted: RBXScriptSignal, - Added: RBXScriptSignal, - __eventInstances__: { - Sorted: BindableEvent, - Added: BindableEvent - } - }, + FloorQueue: FloorQueue, + Events: RelayAlgorithmEvents, } type DoorAttributes = { @@ -32,7 +39,11 @@ type DoorAttributes = { } } -export type FloorQueue = {number?} +export type FloorDirectionQueue = {number?} +export type FloorQueue = { + Up: FloorDirectionQueue, + Down: FloorDirectionQueue +} export type RelayAlgorithmConstructor = ClassConstructor @@ -45,7 +56,10 @@ function RelayAlgorithm.constructor(ElevatorBoxModel) return setmetatable({ ElevatorBoxModel = ElevatorBoxModel, - __FloorQueue = {}, + FloorQueue = { + Up = {}, + Down = {}, + }, Events = { Sorted = Sorted.Event, Added = Added.Event, @@ -57,23 +71,26 @@ function RelayAlgorithm.constructor(ElevatorBoxModel) }, RelayAlgorithm) end ---The Otis relay based call logic ---https://youtu.be/BCN9mQOT3RQ - -function RelayAlgorithm:Sort(ElevatorGoingUp) - table.sort(self.__FloorQueue, function(a, b): boolean - if ElevatorGoingUp then - return ab - end) - self.Events.__eventInstances__.Sorted:Fire() +function RelayAlgorithm:Sort(Direction) + if Direction == Enums.ElevatorCallDirection.Up then + table.sort(self.FloorQueue.Up, function(FirstFloorIndex, LastFloorIndex): boolean + return FirstFloorIndexLastFloorIndex + end) + self.Events.__eventInstances__.Sorted:Fire(Enums.ElevatorCallDirection.Down, self.FloorQueue.Down) + else + warn(`[{script.Name}.lua]: :Sort method failed. Called an unknown enum direction, direction={Direction}`, debug.traceback()) + end end -function RelayAlgorithm:AddFloor(ElevatorGoingUp, GoingUpAttribute, RequestedLevel) - table.insert(self.__FloorQueue, ElevatorGoingUp == GoingUpAttribute.Value and 1 or #self.__FloorQueue+1, RequestedLevel) - self.Events.__eventInstances__.Added:Fire(RequestedLevel) - self:Sort(ElevatorGoingUp) +function RelayAlgorithm:AddFloor(Direction, RequestedLevel) + table.insert(Direction == Enums.ElevatorCallDirection.Up and self.FloorQueue.Up or self.FloorQueue.Down, RequestedLevel) + self.Events.__eventInstances__.Added:Fire(Direction, RequestedLevel) + self:Sort(Direction :: Enums.ElevatorCallDirectionValues) end return RelayAlgorithm diff --git a/src/server/main/Elevators/InitElevator/init.luau b/src/server/main/Elevators/InitElevator/init.luau index 1faf0f3..b1142b2 100644 --- a/src/server/main/Elevators/InitElevator/init.luau +++ b/src/server/main/Elevators/InitElevator/init.luau @@ -6,8 +6,11 @@ local Elevators = script.Parent local MainDir = Elevators.Parent local LoadDir = MainDir:WaitForChild("Load") -local RunService = game:GetService("RunService") +local RunService = game:GetService("RunService") +local StorageService = game:GetService("ReplicatedStorage") +local Enums = require(StorageService:WaitForChild("Enums")) +local Out = require(StorageService:WaitForChild("Output")) local ElevatorTypes = require(MainDir:WaitForChild("Types"):WaitForChild("Elevator")) local Tags = require(LoadDir:WaitForChild("Tags")) local RelayAlgorithm = require(script:WaitForChild("RelayAlgorithm")) @@ -20,8 +23,9 @@ 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) -> (), + GetLevel: (self: ClassConstructor, Level: number, Direction: Enums.ElevatorCallDirectionValues) -> Vector3?, + RequestLevel: (self: ClassConstructor, RequestedLevel: number, Direction: Enums.ElevatorCallDirectionValues) -> boolean, + __TravelToFloor: (self: ClassConstructor, LevelInt: number, VEC3_Y_WRAP: Vector3, Direction: Enums.ElevatorCallDirectionValues) -> (), } type FloorLevelingPositions = {number} @@ -32,17 +36,18 @@ type Constructor_Return_Props = { FloorLevelingPositions: FloorLevelingPositions, Elevator: { - BoxModel: UnionOperation, - AlignPosition: AlignPosition, - Configuration: ElevatorTypes.ElevatorConfigurationTable + TravelingDirection: Enums.ElevatorCallDirectionValues, + BoxModel: UnionOperation, + AlignPosition: AlignPosition, + Configuration: ElevatorTypes.ElevatorConfigurationTable }, Attributes: { - PreviousFloor: IntValue, - CurrentFloor: IntValue, - NextFloor: IntValue, - Goal: IntValue, - GoingUp: BoolValue, - Stopped: BoolValue + PreviousFloor: IntValue, + CurrentFloor: IntValue, + NextFloor: IntValue, + Goal: IntValue, + TravelingUpwards: BoolValue, + Stopped: BoolValue }, Events: { CabProgression: RBXScriptSignal, @@ -100,7 +105,7 @@ local function Mover(ElevatorBoxModel: UnionOperation, Responsiveness: number, M end function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions) - assert(#FloorLevelingPositions>1, `[{ElevatorConfigurationTable.Name}] requires more floors to operate. Floors={FloorLevelingPositions}, #Floors={#FloorLevelingPositions}.`) + assert(#FloorLevelingPositions>1, `"{ElevatorConfigurationTable.Name}" requires more floors to operate. Floors={FloorLevelingPositions}, #Floors={#FloorLevelingPositions}.`) local _BoxAttachment, BoxAlignPosition, @@ -115,28 +120,27 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo local Leveling3Phase = Instance.new("BindableEvent") :: BindableEvent local Attributes = { - PreviousFloor = Instance.new("IntValue") :: IntValue, - CurrentFloor = Instance.new("IntValue") :: IntValue, - NextFloor = Instance.new("IntValue") :: IntValue, - Goal = Instance.new("IntValue") :: IntValue, - GoingUp = Instance.new("BoolValue") :: BoolValue, - Stopped = Instance.new("BoolValue") :: BoolValue + PreviousFloor = Instance.new("IntValue") :: IntValue, + CurrentFloor = Instance.new("IntValue") :: IntValue, + NextFloor = Instance.new("IntValue") :: IntValue, + Goal = Instance.new("IntValue") :: IntValue, + TravelingUpwards = Instance.new("BoolValue") :: BoolValue, + Stopped = Instance.new("BoolValue") :: BoolValue } - Attributes.CurrentFloor.Value = 1 - Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value - Attributes.NextFloor.Value = Attributes.CurrentFloor.Value+1 - Attributes.GoingUp.Value = false - Attributes.Goal.Value = 1 + Attributes.CurrentFloor.Value = 1 + Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value + Attributes.NextFloor.Value = Attributes.CurrentFloor.Value+1 + Attributes.TravelingUpwards.Value = true + Attributes.Goal.Value = 1 - print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`) - - return setmetatable({ + local ElevatorClass = setmetatable({ RelayAlgorithm = RelayAlgorithmConstructor, FloorLevelingPositions = FloorLevelingPositions, Elevator = { - BoxModel = ElevatorBoxModel, - AlignPosition = BoxAlignPosition, - Configuration = ElevatorConfigurationTable, + TravelingDirection = Enums.ElevatorCallDirection.Up, + BoxModel = ElevatorBoxModel, + AlignPosition = BoxAlignPosition, + Configuration = ElevatorConfigurationTable, }, Events = { CabProgression = CabProgression.Event, @@ -155,29 +159,54 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo Attributes = Attributes, __Connections = {} }, Elevator) + + RelayAlgorithmConstructor.Events.Sorted:Connect(function(AddedFloorDirection: Enums.ElevatorCallDirectionValues, FloorDirectionQueue: RelayAlgorithm.FloorDirectionQueue) + if AddedFloorDirection == ElevatorClass.Elevator.TravelingDirection then + local NextFloorAsTraveling = FloorDirectionQueue[1] + if NextFloorAsTraveling then + local Level = FloorLevelingPositions[NextFloorAsTraveling] + ElevatorClass:__TravelToFloor(Level, Vector3.new(0, Level, 0), AddedFloorDirection) + end + Out.printStudio(`[{ElevatorConfigurationTable.Name}]: Floors sorted in proceeding direction. direction={AddedFloorDirection}, FloorDirectionQueue={FloorDirectionQueue}`) + end + end) + + print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`) + return ElevatorClass end -local function CheckFloorQueue(self: ClassConstructor) - if self.RelayAlgorithm.__FloorQueue[1] ~= self.Attributes.CurrentFloor.Value then - warn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", self.Attributes.CurrentFloor.Value, "FloorQueue[1]=", self.RelayAlgorithm.__FloorQueue[1]) - end - table.remove(self.RelayAlgorithm.__FloorQueue, 1) +local function CheckFloorQueue(self: ClassConstructor, Direction: Enums.ElevatorCallDirectionValues) + local DirectionFloorQueue = Direction == Enums.ElevatorCallDirection.Up and self.RelayAlgorithm.FloorQueue.Up or self.RelayAlgorithm.FloorQueue.Down - local NextFloorInQueue = self.RelayAlgorithm.__FloorQueue[1] - print(NextFloorInQueue) + if DirectionFloorQueue[1] ~= self.Attributes.CurrentFloor.Value then + warn(`[{self.Elevator.Configuration.Name}]: The floor queue first index did not match the elevator's current floor, CurrentFloor=`, self.Attributes.CurrentFloor.Value, "FloorQueue[1]=", DirectionFloorQueue[1]) + end + table.remove(DirectionFloorQueue, 1) + Out.printStudio(`[{self.Elevator.Configuration.Name}]: Checking more floors in direction queue. DirectionFloorQueue=`, DirectionFloorQueue) + + local NextFloorInQueue = DirectionFloorQueue[1] if NextFloorInQueue then - local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, NextFloorInQueue) - local LevelVec3 = self.FloorLevelingPositions[NextFloorInQueue] - self:__TravelToFloor(NextFloorInQueue, LevelVec3, ElevatorGoingUp) + else + --No more floors in this direction? + --Check the opposite + if Direction == Enums.ElevatorCallDirection.Up then + if #self.RelayAlgorithm.FloorQueue.Down ~= 0 then + + end + else + if #self.RelayAlgorithm.FloorQueue.Up ~= 0 then + + end + end end end -local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3: number, ElevatorGoingUp: boolean) +local function CabTraveling(self: ClassConstructor, deltaTime: number, VEC3_Y_WRAP: Vector3, Direction: Enums.ElevatorCallDirectionValues) local ElevatorPosition = self.Elevator.BoxModel.Position - local AtFloorY = self.FloorLevelingPositions[ElevatorGoingUp and self.Attributes.CurrentFloor.Value+1 or self.Attributes.CurrentFloor.Value-1] + local AtFloorY = self.FloorLevelingPositions[Direction == Enums.ElevatorCallDirection.Up and self.Attributes.CurrentFloor.Value+1 or self.Attributes.CurrentFloor.Value-1] - if ElevatorGoingUp then + if Direction == Enums.ElevatorCallDirection.Up then --Detecting between the floors if ElevatorPosition.Y>=AtFloorY-self.Elevator.Configuration.FloorLevelingDistance then self.Attributes.PreviousFloor.Value = self.Attributes.CurrentFloor.Value @@ -188,17 +217,17 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3 end --Elevator is riding upwards towards the destination - if ElevatorPosition.Y>=LevelVec3-self.Elevator.Configuration.FloorLevelingDistance then + if ElevatorPosition.Y>=VEC3_Y_WRAP.Y-self.Elevator.Configuration.FloorLevelingDistance then self.Events.__eventInstances__.Leveling:Fire() self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity - if ElevatorPosition.Y>=LevelVec3-self.Elevator.Configuration.FloorLeveling3PhaseDistance then + if ElevatorPosition.Y>=VEC3_Y_WRAP.Y-self.Elevator.Configuration.FloorLeveling3PhaseDistance then self.Events.__eventInstances__.Leveling3Phase:Fire() self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity - if ElevatorPosition.Y>=LevelVec3-self.Elevator.Configuration.ParkedDistance then + if ElevatorPosition.Y>=VEC3_Y_WRAP.Y-self.Elevator.Configuration.ParkedDistance then self.Events.__eventInstances__.Parked:Fire() - CheckFloorQueue(self); + CheckFloorQueue(self, Direction); (self.__Connections.Moving :: RBXScriptConnection):Disconnect() end @@ -214,17 +243,17 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3 end --Elevator is riding upwards towards the destination - if ElevatorPosition.Y<=LevelVec3+self.Elevator.Configuration.FloorLevelingDistance then + if ElevatorPosition.Y<=VEC3_Y_WRAP.Y+self.Elevator.Configuration.FloorLevelingDistance then self.Events.__eventInstances__.Leveling:Fire() self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity - if ElevatorPosition.Y<=LevelVec3+self.Elevator.Configuration.FloorLeveling3PhaseDistance then + if ElevatorPosition.Y<=VEC3_Y_WRAP.Y+self.Elevator.Configuration.FloorLeveling3PhaseDistance then self.Events.__eventInstances__.Leveling3Phase:Fire() self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity - if ElevatorPosition.Y<=LevelVec3+self.Elevator.Configuration.ParkedDistance then + if ElevatorPosition.Y<=VEC3_Y_WRAP.Y+self.Elevator.Configuration.ParkedDistance then self.Events.__eventInstances__.Parked:Fire() - CheckFloorQueue(self); + CheckFloorQueue(self, Direction); (self.__Connections.Moving :: RBXScriptConnection):Disconnect() end @@ -235,34 +264,48 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3 self.Events.__eventInstances__.CabTraveling:Fire(deltaTime, ElevatorPosition) end -function Elevator:__TravelToFloor(LevelInt, LevelVec3, ElevatorGoingUp) +function Elevator:GetLevel(LevelInt, Direction) + local Level = self.FloorLevelingPositions[LevelInt] + if Level then + --local VEC3_Y_WRAP_LOSSY = Vector3.yAxis*Level //lossy + return Vector3.new(0, Level, 0) + end + return nil +end + +function Elevator:__TravelToFloor(LevelInt, VEC3_Y_WRAP, Direction) if self.__Connections.Moving and self.__Connections.Moving.Connected then self.__Connections.Moving:Disconnect() end self.Attributes.Goal.Value = LevelInt - self.Attributes.GoingUp.Value = ElevatorGoingUp + self.Attributes.TravelingUpwards.Value = Direction == Enums.ElevatorCallDirection.Up - self.__Connections.Moving = RunService.Heartbeat:Connect(function(deltaTime) - CabTraveling(self, deltaTime, LevelVec3, ElevatorGoingUp) + self.__Connections.Moving = RunService.Heartbeat:Connect(function(deltaTime: number) + CabTraveling(self, deltaTime, VEC3_Y_WRAP, Direction :: Enums.ElevatorCallDirectionValues) end) --Set the elevator's AlignPosition to the floor Y vector - self.Elevator.AlignPosition.Position = Vector3.new(self.Elevator.AlignPosition.Position.X, LevelVec3, self.Elevator.AlignPosition.Position.Z) + self.Elevator.AlignPosition.Position = Vector3.new(self.Elevator.AlignPosition.Position.X, VEC3_Y_WRAP.Y, self.Elevator.AlignPosition.Position.Z) --Set the elevator's max velocity to its fastest speed when moving starts self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.MaxVelocity end -function Elevator:RequestLevel(RequestedLevel) - local LevelVec3 = self.FloorLevelingPositions[RequestedLevel] +function Elevator:RequestLevel(RequestedLevel, Direction) + local Level = self:GetLevel(RequestedLevel, Direction :: Enums.ElevatorCallDirectionValues) - if LevelVec3 then + if Level then if RequestedLevel ~= self.Attributes.CurrentFloor.Value then - local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, RequestedLevel) - self.RelayAlgorithm:AddFloor(ElevatorGoingUp, self.Attributes.GoingUp, RequestedLevel) + if (RequestedLevel == 1 and Direction == Enums.ElevatorCallDirection.Down) or (RequestedLevel == #self.FloorLevelingPositions and Direction == Enums.ElevatorCallDirection.Up) then + warn(`[{self.Elevator.Configuration.Name}]: Impossible direction requested, Direction={Direction}, RequestedLevel={Level}`) + return false + else + local DirectionQueue = Direction == Enums.ElevatorCallDirection.Up and self.RelayAlgorithm.FloorQueue.Up or self.RelayAlgorithm.FloorQueue.Down + self.RelayAlgorithm:AddFloor(Direction :: Enums.ElevatorCallDirectionValues, RequestedLevel) - if #self.RelayAlgorithm.__FloorQueue == 1 then - self:__TravelToFloor(RequestedLevel, LevelVec3, ElevatorGoingUp) + if #DirectionQueue == 1 then + self:__TravelToFloor(RequestedLevel, Level, Direction :: Enums.ElevatorCallDirectionValues) + end end else warn(`[{self.Elevator.Configuration.Name}]: The elevator is already at the requested floor. RequestLevel={RequestedLevel}, CurrentLevel={self.Attributes.CurrentFloor.Value}`) diff --git a/src/server/main/Elevators/Otis1960/init.luau b/src/server/main/Elevators/Otis1960/init.luau index 5a93eaf..1171bb0 100644 --- a/src/server/main/Elevators/Otis1960/init.luau +++ b/src/server/main/Elevators/Otis1960/init.luau @@ -5,6 +5,9 @@ local ParentDir = script.Parent local MainDir = ParentDir.Parent +local StorageService = game:GetService("ReplicatedStorage") + +local Enums = require(StorageService:WaitForChild("Enums")) local InitElevator = require(ParentDir:WaitForChild("InitElevator")) local TagsModule = require(MainDir:WaitForChild("Load"):WaitForChild("Tags")) @@ -48,7 +51,7 @@ return function(TagsConstructor: TagsModule.TagsConstructor, ButtonTags: TagsMod end) task.wait(1) - Elevator:RequestLevel(3) - Elevator:RequestLevel(5) - Elevator:RequestLevel(2) + Elevator:RequestLevel(3, Enums.ElevatorCallDirection.Up) + Elevator:RequestLevel(5, Enums.ElevatorCallDirection.Up) + Elevator:RequestLevel(2, Enums.ElevatorCallDirection.Down) end diff --git a/src/server/main/Enums/Sounds.luau b/src/server/main/Enums/Sounds.luau index d46a8de..0408f3e 100644 --- a/src/server/main/Enums/Sounds.luau +++ b/src/server/main/Enums/Sounds.luau @@ -4,8 +4,8 @@ local SoundEnums = {} +--MACROSSSSSSSSSSS export type Otis1960Sounds = typeof(SoundEnums.Otis1960) - export type Otis1960LanternChimeDirection = "rbxassetid://16990287228" export type Otis1960LanternChimeLanding = "rbxassetid://16990290265" export type Otis1960DoorClosingClick = "rbxassetid://16357740945" @@ -14,18 +14,8 @@ export type Otis1960RelayLowActivated = "rbxassetid://17701796245" export type Otis1960RelayDeActivated = "rbxassetid://17702004158" export type Otis1960BigRelayActivated = "rbxassetid://17701707630" export type Otis1960BigRelayDeActivated = "rbxassetid://17701712012" - -export type Otis1960SoundValues = Otis1960LanternChimeDirection | - Otis1960LanternChimeLanding | - Otis1960DoorClosingClick | - Otis1960RelayHighActivated | - Otis1960RelayLowActivated | - Otis1960RelayDeActivated | - Otis1960BigRelayActivated | - Otis1960BigRelayDeActivated - +export type Otis1960SoundValues = Otis1960LanternChimeDirection | Otis1960LanternChimeLanding | Otis1960DoorClosingClick | Otis1960RelayHighActivated | Otis1960RelayLowActivated | Otis1960RelayDeActivated | Otis1960BigRelayActivated | Otis1960BigRelayDeActivated export type ElevatorSoundValues = Otis1960SoundValues - SoundEnums.Otis1960 = { LanternChimeDirection = "rbxassetid://16990287228" :: Otis1960LanternChimeDirection, LanternChimeLanding = "rbxassetid://16990290265" :: Otis1960LanternChimeLanding, diff --git a/src/shared/Enums.luau b/src/shared/Enums.luau index af04bb8..07c8482 100644 --- a/src/shared/Enums.luau +++ b/src/shared/Enums.luau @@ -4,33 +4,11 @@ local Enums = {} +--MACROSSSSSSSSSSS export type EnumValue = EnumButton | EnumButtonTree | EnumElevator | EnumInteractables | EnumSpecialButton -export type EnumButton = typeof(Enums.Button) -export type EnumButtonTree = typeof(Enums.ButtonTree) -export type EnumElevator = typeof(Enums.Elevator) -export type EnumInteractables = typeof(Enums.InteractType) -export type EnumSpecialButton = typeof(Enums.SpecialButton) - -export type ButtonValues = typeof(Enums.Button.Car) | - typeof(Enums.Button.Landing) | - typeof(Enums.Button.Special) | - typeof(Enums.Button.Relay) - -export type ButtonTreeValues = typeof(Enums.ButtonTree.Car) | - typeof(Enums.ButtonTree.Landing) | - typeof(Enums.ButtonTree.Special) | - typeof(Enums.ButtonTree.Relays) | - typeof(Enums.ButtonTree.Unknown) - -export type SpecialButtonValues = typeof(Enums.SpecialButton.Stop) - -export type InteractablesValues = typeof(Enums.InteractType.LightSwitch) | - typeof(Enums.InteractType.Light) | - typeof(Enums.InteractType.LightSource) - -export type ElevatorValues = typeof(Enums.Elevator.Otis1960) | - typeof(Enums.Elevator.Haughton) +export type EnumButton = typeof(Enums.Button) +export type ButtonValues = typeof(Enums.Button.Car) | typeof(Enums.Button.Landing) | typeof(Enums.Button.Special) | typeof(Enums.Button.Relay) Enums.Button = { Car = "CarButton" :: "CarButton", Landing = "LandingButton" :: "LandingButton", @@ -38,6 +16,8 @@ Enums.Button = { Relay = "RelayButton" :: "RelayButton" } +export type EnumButtonTree = typeof(Enums.ButtonTree) +export type ButtonTreeValues = typeof(Enums.ButtonTree.Car) | typeof(Enums.ButtonTree.Landing) | typeof(Enums.ButtonTree.Special) | typeof(Enums.ButtonTree.Relays) | typeof(Enums.ButtonTree.Unknown) Enums.ButtonTree = { Car = "Car" :: "Car", Landing = "Landing" :: "Landing", @@ -46,19 +26,32 @@ Enums.ButtonTree = { Unknown = "Unknown" :: "Unknown" } +export type EnumSpecialButton = typeof(Enums.SpecialButton) +export type SpecialButtonValues = typeof(Enums.SpecialButton.Stop) Enums.SpecialButton = { Stop = "Stop" :: "Stop" } +export type EnumElevator = typeof(Enums.Elevator) +export type ElevatorValues = typeof(Enums.Elevator.Otis1960) | typeof(Enums.Elevator.Haughton) Enums.Elevator = { Otis1960 = "Otis1960" :: "Otis1960", Haughton = "Haughton" :: "Haughton" } +export type EnumInteractables = typeof(Enums.InteractType) +export type InteractablesValues = typeof(Enums.InteractType.LightSwitch) | typeof(Enums.InteractType.Light) | typeof(Enums.InteractType.LightSource) Enums.InteractType = { LightSwitch = "LightSwitch" :: "LightSwitch", Light = "Light" :: "Light", LightSource = "LightSource" :: "LightSource" } -return Enums \ No newline at end of file +export type EnumElevatorCallDirections = typeof(Enums.ElevatorCallDirection) +export type ElevatorCallDirectionValues = typeof(Enums.ElevatorCallDirection.Up) | typeof(Enums.ElevatorCallDirection.Down) +Enums.ElevatorCallDirection = { + Up = "Up" :: "Up", + Down = "Down" :: "Down" +} + +return Enums diff --git a/src/shared/Output.luau b/src/shared/Output.luau new file mode 100644 index 0000000..ecf32a7 --- /dev/null +++ b/src/shared/Output.luau @@ -0,0 +1,50 @@ +--!optimize 2 +--!native +--!strict + +local RunService = game:GetService("RunService") + +local function printStudio(...: T...) + if RunService:IsStudio() then + print(...) + end +end + +local function printServer(...: T...) + if RunService:IsServer() then + print(...) + end +end + +local function printClient(...: T...) + if RunService:IsClient() then + print(...) + end +end + +local function warnStudio(...: T...) + if RunService:IsStudio() then + warn(...) + end +end + +local function warnServer(...: T...) + if RunService:IsServer() then + warn(...) + end +end + +local function warnClient(...: T...) + if RunService:IsClient() then + warn(...) + end +end + +return { + printStudio = printStudio, + printServer = printServer, + printClient = printClient, + warnStudio = warnStudio, + warnServer = warnServer, + warnClient = warnClient +}