Working state !! and more event control and elevator functions

This commit is contained in:
2024-07-31 21:15:07 -04:00
parent 0aa2edaccd
commit 2b326e1036
5 changed files with 127 additions and 107 deletions

View File

@@ -90,7 +90,6 @@ end
function RelayAlgorithm:AddFloor(Direction, RequestedLevel) function RelayAlgorithm:AddFloor(Direction, RequestedLevel)
table.insert(Direction == Enums.ElevatorCallDirection.Up and self.FloorQueue.Up or self.FloorQueue.Down, RequestedLevel) table.insert(Direction == Enums.ElevatorCallDirection.Up and self.FloorQueue.Up or self.FloorQueue.Down, RequestedLevel)
self.Events.__eventInstances__.Added:Fire(Direction, RequestedLevel) self.Events.__eventInstances__.Added:Fire(Direction, RequestedLevel)
self:Sort(Direction :: Enums.ElevatorCallDirectionValues)
end end
return RelayAlgorithm return RelayAlgorithm

View File

@@ -11,6 +11,7 @@ local StorageService = game:GetService("ReplicatedStorage")
local Enums = require(StorageService:WaitForChild("Enums")) local Enums = require(StorageService:WaitForChild("Enums"))
local Out = require(StorageService:WaitForChild("Output")) local Out = require(StorageService:WaitForChild("Output"))
local Algebra = require(StorageService:WaitForChild("Algebra"))
local ElevatorTypes = require(MainDir:WaitForChild("Types"):WaitForChild("Elevator")) local ElevatorTypes = require(MainDir:WaitForChild("Types"):WaitForChild("Elevator"))
local Tags = require(LoadDir:WaitForChild("Tags")) local Tags = require(LoadDir:WaitForChild("Tags"))
local RelayAlgorithm = require(script:WaitForChild("RelayAlgorithm")) local RelayAlgorithm = require(script:WaitForChild("RelayAlgorithm"))
@@ -23,9 +24,10 @@ type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
GetLevel: (self: ClassConstructor, Level: number, Direction: Enums.ElevatorCallDirectionValues) -> Vector3?, GetLevel: (self: ClassConstructor, Level: number) -> Vector3?,
RequestLevel: (self: ClassConstructor, RequestedLevel: number, Direction: Enums.ElevatorCallDirectionValues) -> boolean, RequestLevelAsync: (self: ClassConstructor, RequestedLevel: number, Direction: Enums.ElevatorCallDirectionValues) -> boolean,
__TravelToFloor: (self: ClassConstructor, LevelInt: number, VEC3_Y_WRAP: Vector3, Direction: Enums.ElevatorCallDirectionValues) -> (), StartTraveling: (self: ClassConstructor) -> (),
__TravelToFloorAsync: (self: ClassConstructor, LevelInt: number, VEC3_Y_WRAP: Vector3) -> (),
} }
type FloorLevelingPositions = {number} type FloorLevelingPositions = {number}
@@ -37,6 +39,7 @@ type Constructor_Return_Props = {
eprint: <T...>(T...) -> (), eprint: <T...>(T...) -> (),
ewarn: <T...>(T...) -> (), ewarn: <T...>(T...) -> (),
eprintStudio: <T...>(T...) -> (), eprintStudio: <T...>(T...) -> (),
ewarnStudio: <T...>(T...) -> (),
Elevator: { Elevator: {
TravelingDirection: Enums.ElevatorCallDirectionValues, TravelingDirection: Enums.ElevatorCallDirectionValues,
@@ -53,20 +56,22 @@ type Constructor_Return_Props = {
Stopped: BoolValue Stopped: BoolValue
}, },
Events: { Events: {
CabProgression: RBXScriptSignal<number, number, number>, Progression: RBXScriptSignal<number, number, number>,
CabTraveling: RBXScriptSignal<number, Vector3>, Traveling: RBXScriptSignal<number, Vector3>,
Parked: RBXScriptSignal, Parked: RBXScriptSignal,
Leveling: RBXScriptSignal, Leveling: RBXScriptSignal,
Leveling3Phase: RBXScriptSignal, Leveling3Phase: RBXScriptSignal,
__eventInstances__: { __eventInstances__: {
CabProgression: BindableEvent, Progression: BindableEvent,
CabTraveling: BindableEvent, Traveling: BindableEvent,
Parked: BindableEvent, Parked: BindableEvent,
Leveling: BindableEvent, Leveling: BindableEvent,
Leveling3Phase: BindableEvent, Leveling3Phase: BindableEvent,
} }
}, },
__functionEvents: {
StartTraveling: BindableEvent
},
__Connections: { __Connections: {
Moving: RBXScriptConnection?, Moving: RBXScriptConnection?,
} }
@@ -119,6 +124,10 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
local function eprintStudio<T...>(...: T...) local function eprintStudio<T...>(...: T...)
Out.printStudio(`[{ElevatorConfigurationTable.Name}]:`, ...) Out.printStudio(`[{ElevatorConfigurationTable.Name}]:`, ...)
end end
local function ewarnStudio<T...>(...: T...)
Out.warnStudio(`[{ElevatorConfigurationTable.Name}]:`, ...)
end
local _BoxAttachment, local _BoxAttachment,
BoxAlignPosition, BoxAlignPosition,
_BoxAlignOrientation = Mover(ElevatorBoxModel, ElevatorConfigurationTable.Responsiveness, ElevatorConfigurationTable.MaxVelocity) _BoxAlignOrientation = Mover(ElevatorBoxModel, ElevatorConfigurationTable.Responsiveness, ElevatorConfigurationTable.MaxVelocity)
@@ -150,6 +159,7 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
eprint = eprint, eprint = eprint,
ewarn = ewarn, ewarn = ewarn,
eprintStudio = eprintStudio, eprintStudio = eprintStudio,
ewarnStudio = ewarnStudio,
Elevator = { Elevator = {
TravelingDirection = Enums.ElevatorCallDirection.Up, TravelingDirection = Enums.ElevatorCallDirection.Up,
@@ -158,20 +168,23 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
Configuration = ElevatorConfigurationTable, Configuration = ElevatorConfigurationTable,
}, },
Events = { Events = {
CabProgression = CabProgression.Event, Progression = CabProgression.Event,
CabTraveling = CabTraveling.Event, Traveling = CabTraveling.Event,
Parked = Parked.Event, Parked = Parked.Event,
Leveling = Leveling.Event, Leveling = Leveling.Event,
Leveling3Phase = Leveling3Phase.Event, Leveling3Phase = Leveling3Phase.Event,
__eventInstances__ = { __eventInstances__ = {
CabProgression = CabProgression, Progression = CabProgression,
CabTraveling = CabTraveling, Traveling = CabTraveling,
Parked = Parked, Parked = Parked,
Leveling = Leveling, Leveling = Leveling,
Leveling3Phase = Leveling3Phase, Leveling3Phase = Leveling3Phase,
} }
}, },
Attributes = Attributes, Attributes = Attributes,
__functionEvents = {
StartTraveling = Instance.new("BindableEvent") :: BindableEvent
},
__Connections = {} __Connections = {}
}, Elevator) }, Elevator)
@@ -180,7 +193,7 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
local NextFloorAsTraveling = FloorDirectionQueue[1] local NextFloorAsTraveling = FloorDirectionQueue[1]
if NextFloorAsTraveling then if NextFloorAsTraveling then
local Level = FloorLevelingPositions[NextFloorAsTraveling] local Level = FloorLevelingPositions[NextFloorAsTraveling]
ElevatorClass:__TravelToFloor(Level, Vector3.new(0, Level, 0), AddedFloorDirection) ElevatorClass:__TravelToFloorAsync(Level, Vector3.new(0, Level, 0), AddedFloorDirection)
end end
ElevatorClass.eprintStudio(`Floors sorted in proceeding direction. direction={AddedFloorDirection}, FloorDirectionQueue={FloorDirectionQueue}`) ElevatorClass.eprintStudio(`Floors sorted in proceeding direction. direction={AddedFloorDirection}, FloorDirectionQueue={FloorDirectionQueue}`)
end end
@@ -190,88 +203,94 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
return ElevatorClass return ElevatorClass
end end
local function ProceedToNextLevel(self: ClassConstructor, Level: number, Direction: Enums.ElevatorCallDirectionValues): Vector3? local function ProceedToNextLevel(self: ClassConstructor, Level_Int: number): Vector3?
local VEC3_Y_WRAP = self:GetLevel(Level, Direction) local VEC3_Y_WRAP = self:GetLevel(Level_Int)
if VEC3_Y_WRAP then if VEC3_Y_WRAP then
self:__TravelToFloor(Level, VEC3_Y_WRAP, Direction) self:__TravelToFloorAsync(Level_Int, VEC3_Y_WRAP)
self.eprintStudio(`Traveling to Level={Level} VEC3_Y_WRAP={VEC3_Y_WRAP} Direct={Direction}`) self.eprintStudio(`Traveling to Level={Level_Int} VEC3_Y_WRAP={VEC3_Y_WRAP}`)
else else
self.ewarn(`Failed to get the requested level's Y position. VEC3_Y_WRAP={VEC3_Y_WRAP} Level={Level} Direction={Direction}`) self.ewarn(`Failed to get the requested level's Y position. VEC3_Y_WRAP={VEC3_Y_WRAP} Level={Level_Int}`)
end end
return VEC3_Y_WRAP return VEC3_Y_WRAP
end end
local function CheckFloorQueue(self: ClassConstructor, Direction: Enums.ElevatorCallDirectionValues) local function GoingUpDirectionToDirectionEnum(CurrentFloor: number, RequestedFloor: number): Enums.ElevatorCallDirectionValues
local DirectionFloorQueue = Direction == Enums.ElevatorCallDirection.Up and self.RelayAlgorithm.FloorQueue.Up or self.RelayAlgorithm.FloorQueue.Down return ElevatorGoingUpDirection(CurrentFloor, RequestedFloor) and Enums.ElevatorCallDirection.Up or Enums.ElevatorCallDirection.Down
end
if DirectionFloorQueue[1] ~= self.Attributes.CurrentFloor.Value then local function CheckFloorQueue(self: ClassConstructor)
self.ewarn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", self.Attributes.CurrentFloor.Value, "FloorQueue[1]=", DirectionFloorQueue[1]) local DirectionToDirectionQueue = self.Attributes.TravelingUpwards.Value and self.RelayAlgorithm.FloorQueue.Up or self.RelayAlgorithm.FloorQueue.Down
local DirectionToOppositeDirectionQueue = self.Attributes.TravelingUpwards.Value and self.RelayAlgorithm.FloorQueue.Down or self.RelayAlgorithm.FloorQueue.Up
if DirectionToOppositeDirectionQueue[1] ~= self.Attributes.CurrentFloor.Value then
self.ewarn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", self.Attributes.CurrentFloor.Value, "FloorQueue[1]=", DirectionToOppositeDirectionQueue[1])
end end
table.remove(DirectionFloorQueue, 1)
self.RelayAlgorithm:Sort(Direction)
self.eprintStudio("Checking more floors in direction queue. Direction=", Direction, "DirectionFloorQueue=", DirectionFloorQueue)
local NextFloorInQueue = DirectionFloorQueue[1] table.remove(DirectionToDirectionQueue, 1)
local IdenticalOpposite = table.find(DirectionToOppositeDirectionQueue, self.Attributes.CurrentFloor.Value)
if IdenticalOpposite then
table.remove(DirectionToOppositeDirectionQueue, IdenticalOpposite)
self.eprintStudio(`Removed the current floor from the opposite direction, ElevatorTravelingUpwards={self.Attributes.TravelingUpwards.Value} CurrentFloor={self.Attributes.CurrentFloor.Value}`)
end
self.eprintStudio("Checking more floors in direction queue. DirectionToDirectionQueue=", DirectionToDirectionQueue)
local NextFloorInQueue = DirectionToOppositeDirectionQueue[1]
if NextFloorInQueue then if NextFloorInQueue then
local ProceedingToTheNextLevel = ProceedToNextLevel(self, NextFloorInQueue, Direction) local NewDirection = GoingUpDirectionToDirectionEnum(self.Attributes.CurrentFloor.Value, NextFloorInQueue)
self.RelayAlgorithm:Sort(NewDirection :: Enums.ElevatorCallDirectionValues)
local ProceedingToTheNextLevel = ProceedToNextLevel(self, NextFloorInQueue)
if not ProceedingToTheNextLevel then if not ProceedingToTheNextLevel then
self.RelayAlgorithm:Sort(Enums.ElevatorCallDirection.Down) self.RelayAlgorithm:Sort(Enums.ElevatorCallDirection.Down)
ProceedToNextLevel(self, 1, Enums.ElevatorCallDirection.Down) ProceedToNextLevel(self, 1)
end end
else else
--No more floors in the current direction? --No more floors in the current direction?
--Check the opposite --Check the opposite
self.eprintStudio(`No more floors in the direction "{Direction}" checking the opposite direction floors`) self.eprintStudio(`No more floors in the direction TravelingUpwards="{self.Attributes.TravelingUpwards.Value}" checking the opposite direction floors`)
if Direction == Enums.ElevatorCallDirection.Up then if #DirectionToOppositeDirectionQueue ~= 0 then
if #self.RelayAlgorithm.FloorQueue.Down ~= 0 then local NextLevelOpposite = DirectionToOppositeDirectionQueue[1]
local NextLevelDown = self.RelayAlgorithm.FloorQueue.Down[1] if NextLevelOpposite then
if NextLevelDown then local NewDirection = GoingUpDirectionToDirectionEnum(self.Attributes.CurrentFloor.Value, NextLevelOpposite)
local NewDirection = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, NextLevelDown) and Enums.ElevatorCallDirection.Up or Enums.ElevatorCallDirection.Down self.RelayAlgorithm:Sort(NewDirection :: Enums.ElevatorCallDirectionValues)
self.RelayAlgorithm:Sort(NewDirection :: Enums.ElevatorCallDirectionValues) self.eprint("Floors found in the opposite direction. Direction=", Enums.ElevatorCallDirection.Down, "NextLevel=", NextLevelOpposite)
self.eprint("Floors found in the opposite direction. Direction=", Enums.ElevatorCallDirection.Down, "NextLevel=", NextLevelDown) ProceedToNextLevel(self, NextLevelOpposite)
ProceedToNextLevel(self, NextLevelDown, Enums.ElevatorCallDirection.Down)
end
end
else
if #self.RelayAlgorithm.FloorQueue.Up ~= 0 then
local NextLevelUp = self.RelayAlgorithm.FloorQueue.Up[1]
if NextLevelUp then
local NewDirection = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, NextLevelUp) and Enums.ElevatorCallDirection.Up or Enums.ElevatorCallDirection.Down
self.RelayAlgorithm:Sort(NewDirection :: Enums.ElevatorCallDirectionValues)
self.eprint("Floors found in the opposite direction. Direction=", Enums.ElevatorCallDirection.Up, "NextLevel=", NextLevelUp)
ProceedToNextLevel(self, NextLevelUp, Enums.ElevatorCallDirection.Up)
end
end end
end end
end end
end end
local function CabTraveling(self: ClassConstructor, deltaTime: number, VEC3_Y_WRAP: Vector3, Direction: Enums.ElevatorCallDirectionValues, ElevatorTravelingUpwards: boolean) local function FloorsClamp(self: ClassConstructor, n: number): number
local ElevatorPosition = self.Elevator.BoxModel.Position return Algebra.minmax(1, n, #self.FloorLevelingPositions)
local AtFloorY = self.FloorLevelingPositions[ElevatorTravelingUpwards and self.Attributes.CurrentFloor.Value+1 or self.Attributes.CurrentFloor.Value-1] end
if ElevatorTravelingUpwards then local function CabTraveling(self: ClassConstructor, deltaTime: number, LEVEL_VEC3_Y_WRAP: Vector3)
local ElevatorPosition = self.Elevator.BoxModel.Position
local AtFloorY = self.FloorLevelingPositions[FloorsClamp(self, self.Attributes.TravelingUpwards.Value and self.Attributes.CurrentFloor.Value+1 or self.Attributes.CurrentFloor.Value-1)]
if self.Attributes.TravelingUpwards.Value then
--Detecting between the floors --Detecting between the floors
if ElevatorPosition.Y>=AtFloorY-self.Elevator.Configuration.FloorLevelingDistance then if ElevatorPosition.Y>=AtFloorY-self.Elevator.Configuration.FloorLevelingDistance then
self.Attributes.PreviousFloor.Value = self.Attributes.CurrentFloor.Value self.Attributes.PreviousFloor.Value = self.Attributes.CurrentFloor.Value
self.Attributes.CurrentFloor.Value+=1 self.Attributes.CurrentFloor.Value+=1
self.Attributes.NextFloor.Value = math.clamp(1, self.Attributes.CurrentFloor.Value+1, #self.FloorLevelingPositions) self.Attributes.NextFloor.Value = FloorsClamp(self, self.Attributes.CurrentFloor.Value+1)
self.Events.__eventInstances__.CabProgression:Fire(self.Attributes.PreviousFloor.Value, self.Attributes.CurrentFloor.Value, self.Attributes.NextFloor.Value) self.Events.__eventInstances__.Progression:Fire(self.Attributes.PreviousFloor.Value, self.Attributes.CurrentFloor.Value, self.Attributes.NextFloor.Value)
end end
--Elevator is riding upwards towards the destination --Elevator is riding upwards towards the destination
if ElevatorPosition.Y>=VEC3_Y_WRAP.Y-self.Elevator.Configuration.FloorLevelingDistance then if ElevatorPosition.Y>=LEVEL_VEC3_Y_WRAP.Y-self.Elevator.Configuration.FloorLevelingDistance then
self.Events.__eventInstances__.Leveling:Fire() self.Events.__eventInstances__.Leveling:Fire()
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity
if ElevatorPosition.Y>=VEC3_Y_WRAP.Y-self.Elevator.Configuration.FloorLeveling3PhaseDistance then if ElevatorPosition.Y>=LEVEL_VEC3_Y_WRAP.Y-self.Elevator.Configuration.FloorLeveling3PhaseDistance then
self.Events.__eventInstances__.Leveling3Phase:Fire() self.Events.__eventInstances__.Leveling3Phase:Fire()
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity
if ElevatorPosition.Y>=VEC3_Y_WRAP.Y-self.Elevator.Configuration.ParkedDistance then if ElevatorPosition.Y>=LEVEL_VEC3_Y_WRAP.Y-self.Elevator.Configuration.ParkedDistance then
self.Events.__eventInstances__.Parked:Fire() self.Events.__eventInstances__.Parked:Fire()
CheckFloorQueue(self, Direction); CheckFloorQueue(self);
(self.__Connections.Moving :: RBXScriptConnection):Disconnect() (self.__Connections.Moving :: RBXScriptConnection):Disconnect()
end end
@@ -281,23 +300,23 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, VEC3_Y_WR
if ElevatorPosition.Y<=AtFloorY+self.Elevator.Configuration.FloorLevelingDistance then if ElevatorPosition.Y<=AtFloorY+self.Elevator.Configuration.FloorLevelingDistance then
self.Attributes.PreviousFloor.Value = self.Attributes.CurrentFloor.Value self.Attributes.PreviousFloor.Value = self.Attributes.CurrentFloor.Value
self.Attributes.CurrentFloor.Value-=1 self.Attributes.CurrentFloor.Value-=1
self.Attributes.NextFloor.Value = math.clamp(1, self.Attributes.CurrentFloor.Value-1, #self.FloorLevelingPositions) self.Attributes.NextFloor.Value = FloorsClamp(self, self.Attributes.CurrentFloor.Value-1)
self.Events.__eventInstances__.CabProgression:Fire(self.Attributes.PreviousFloor.Value, self.Attributes.CurrentFloor.Value, self.Attributes.NextFloor.Value) self.Events.__eventInstances__.Progression:Fire(self.Attributes.PreviousFloor.Value, self.Attributes.CurrentFloor.Value, self.Attributes.NextFloor.Value)
end end
--Elevator is riding upwards towards the destination --Elevator is riding upwards towards the destination
if ElevatorPosition.Y<=VEC3_Y_WRAP.Y+self.Elevator.Configuration.FloorLevelingDistance then if ElevatorPosition.Y<=LEVEL_VEC3_Y_WRAP.Y+self.Elevator.Configuration.FloorLevelingDistance then
self.Events.__eventInstances__.Leveling:Fire() self.Events.__eventInstances__.Leveling:Fire()
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity
if ElevatorPosition.Y<=VEC3_Y_WRAP.Y+self.Elevator.Configuration.FloorLeveling3PhaseDistance then if ElevatorPosition.Y<=LEVEL_VEC3_Y_WRAP.Y+self.Elevator.Configuration.FloorLeveling3PhaseDistance then
self.Events.__eventInstances__.Leveling3Phase:Fire() self.Events.__eventInstances__.Leveling3Phase:Fire()
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity
if ElevatorPosition.Y<=VEC3_Y_WRAP.Y+self.Elevator.Configuration.ParkedDistance then if ElevatorPosition.Y<=LEVEL_VEC3_Y_WRAP.Y+self.Elevator.Configuration.ParkedDistance then
self.Events.__eventInstances__.Parked:Fire() self.Events.__eventInstances__.Parked:Fire()
CheckFloorQueue(self, Direction); CheckFloorQueue(self);
(self.__Connections.Moving :: RBXScriptConnection):Disconnect() (self.__Connections.Moving :: RBXScriptConnection):Disconnect()
end end
@@ -305,62 +324,61 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, VEC3_Y_WR
end end
end end
self.Events.__eventInstances__.CabTraveling:Fire(deltaTime, ElevatorPosition) self.Events.__eventInstances__.Traveling:Fire(deltaTime, ElevatorPosition)
end end
function Elevator:GetLevel(LevelInt, Direction) function Elevator:GetLevel(Level_Int)
local Level = self.FloorLevelingPositions[LevelInt] local Level = self.FloorLevelingPositions[Level_Int]
if Level then if Level then
--local VEC3_Y_WRAP_LOSSY = Vector3.yAxis*Level //lossy --local VEC3_Y_WRAP_LOSSY = Vector3.yAxis*Level
return Vector3.new(0, Level, 0) return Vector3.new(0, Level, 0)
end end
return nil return nil
end end
function Elevator:__TravelToFloor(LevelInt, VEC3_Y_WRAP, Direction) function Elevator:__TravelToFloorAsync(Level_Int, LEVEL_VEC3_Y_WRAP)
if self.Elevator.Configuration.Functions.ManualTravelStart then
self.__functionEvents.StartTraveling.Event:Wait()
end
if self.__Connections.Moving and self.__Connections.Moving.Connected then if self.__Connections.Moving and self.__Connections.Moving.Connected then
self.__Connections.Moving:Disconnect() self.__Connections.Moving:Disconnect()
end end
local ElevatorTravelingUpwards = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, LevelInt) local ElevatorTravelingUpwards = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, Level_Int)
self.Attributes.Goal.Value = LevelInt self.Attributes.Goal.Value = Level_Int
self.Attributes.TravelingUpwards.Value = ElevatorTravelingUpwards self.Attributes.TravelingUpwards.Value = ElevatorTravelingUpwards
self.__Connections.Moving = RunService.Heartbeat:Connect(function(deltaTime: number) self.__Connections.Moving = RunService.Heartbeat:Connect(function(deltaTime: number)
CabTraveling(self, deltaTime, VEC3_Y_WRAP, Direction :: Enums.ElevatorCallDirectionValues, ElevatorTravelingUpwards) CabTraveling(self, deltaTime, LEVEL_VEC3_Y_WRAP)
end) end)
--Set the elevator's AlignPosition to the floor Y vector --Set the elevator's AlignPosition to the floor Y vector
self.Elevator.AlignPosition.Position = Vector3.new(self.Elevator.AlignPosition.Position.X, VEC3_Y_WRAP.Y, self.Elevator.AlignPosition.Position.Z) self.Elevator.AlignPosition.Position = Vector3.new(self.Elevator.AlignPosition.Position.X, LEVEL_VEC3_Y_WRAP.Y, self.Elevator.AlignPosition.Position.Z)
--Set the elevator's max velocity to its fastest speed when moving starts --Set the elevator's max velocity to its fastest speed when moving starts
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.MaxVelocity self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.MaxVelocity
end end
function Elevator:RequestLevel(RequestedLevel, Direction) function Elevator:RequestLevelAsync(RequestedLevel, Direction)
local Level = self:GetLevel(RequestedLevel, Direction :: Enums.ElevatorCallDirectionValues) local Level = self:GetLevel(RequestedLevel)
if Level then if Level then
if RequestedLevel ~= self.Attributes.CurrentFloor.Value then if (RequestedLevel == 1 and Direction == Enums.ElevatorCallDirection.Down) or (RequestedLevel == #self.FloorLevelingPositions and Direction == Enums.ElevatorCallDirection.Up) then
if (RequestedLevel == 1 and Direction == Enums.ElevatorCallDirection.Down) or (RequestedLevel == #self.FloorLevelingPositions and Direction == Enums.ElevatorCallDirection.Up) then self.ewarn(`Impossible direction requested, Direction={Direction}, RequestedLevel={Level}`)
self.ewarn(`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 #DirectionQueue == 1 then
self:__TravelToFloor(RequestedLevel, Level, Direction :: Enums.ElevatorCallDirectionValues)
end
end
else
self.ewarn(`The elevator is already at the requested floor. RequestLevel={RequestedLevel}, CurrentLevel={self.Attributes.CurrentFloor.Value}`)
return false 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 #DirectionQueue == 1 then
self:__TravelToFloorAsync(RequestedLevel, Level)
end
end end
return true return true
end end
self.ewarn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`) self.ewarn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`)
return false return false
end end
function Elevator:StartTraveling()
self.__functionEvents.StartTraveling:Fire()
end
return Elevator return Elevator

View File

@@ -19,6 +19,10 @@ ElevatorConfiguration.MaxVelocity = 7
ElevatorConfiguration.LevelingVelocity = 2 ElevatorConfiguration.LevelingVelocity = 2
ElevatorConfiguration.Phase3LevelingVelocity = .5 ElevatorConfiguration.Phase3LevelingVelocity = .5
ElevatorConfiguration.Functions = {
ManualTravelStart = true
}
ElevatorConfiguration.Sounds = { ElevatorConfiguration.Sounds = {
LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection, LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection,
LanternChimeLanding = SoundEnums.Otis1960.LanternChimeLanding LanternChimeLanding = SoundEnums.Otis1960.LanternChimeLanding

View File

@@ -34,23 +34,18 @@ return function(TagsConstructor: TagsModule.TagsConstructor, ButtonTags: TagsMod
local Elevator = InitElevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions) local Elevator = InitElevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions)
Elevator.Events.CabTraveling:Connect(function(deltaTime: number, ElevatorPosition: Vector3) Elevator.Events.Progression:Connect(function(PreviousFloor: number, CurrentFloor: number, NextFloor: number)
end)
Elevator.Events.CabProgression:Connect(function(PreviousFloor: number, CurrentFloor: number, NextFloor: number)
print(CurrentFloor) print(CurrentFloor)
end) end)
Elevator.Events.Leveling:Connect(function()
end)
Elevator.Events.Leveling3Phase:Connect(function()
end)
Elevator.Events.Parked:Connect(function()
end)
task.wait(1) task.wait(1)
Elevator:RequestLevel(10, Enums.ElevatorCallDirection.Down) task.spawn(function()
Elevator:RequestLevel(6, Enums.ElevatorCallDirection.Down) Elevator:RequestLevelAsync(2, Enums.ElevatorCallDirection.Down)
end)
Elevator:StartTraveling()
Elevator.Events.Parked:Wait()
task.spawn(function()
Elevator:RequestLevelAsync(1, Enums.ElevatorCallDirection.Up)
end)
Elevator:StartTraveling()
end end

View File

@@ -15,6 +15,10 @@ export type ElevatorConfigurationTable = {
ParkedDistance: number, ParkedDistance: number,
LevelingVelocity: number, LevelingVelocity: number,
Phase3LevelingVelocity: number, Phase3LevelingVelocity: number,
Functions: {
ManualTravelStart: boolean,
},
Sounds: { Sounds: {
LanternChimeDirection: SoundEnums.ElevatorSoundValues, LanternChimeDirection: SoundEnums.ElevatorSoundValues,
LanternChimeLanding: SoundEnums.ElevatorSoundValues, LanternChimeLanding: SoundEnums.ElevatorSoundValues,