mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
r
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -2,28 +2,35 @@
|
|||||||
--!native
|
--!native
|
||||||
--!strict
|
--!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 ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||||
type Impl_Constructor = {
|
type Impl_Constructor = {
|
||||||
__index: Impl_Constructor,
|
__index: Impl_Constructor,
|
||||||
constructor: Constructor_Fun,
|
constructor: Constructor_Fun,
|
||||||
--Class functions
|
--Class functions
|
||||||
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
Sort: (self: ClassConstructor, Direction: Enums.ElevatorCallDirectionValues) -> (),
|
||||||
AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, GoingUpAttribute: BoolValue, RequestedLevel: number) -> (),
|
AddFloor: (self: ClassConstructor, Direction: Enums.ElevatorCallDirectionValues, RequestedLevel: number) -> (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type RelayAlgorithmEvents = {
|
||||||
|
Sorted: RBXScriptSignal<Enums.ElevatorCallDirectionValues, FloorDirectionQueue>,
|
||||||
|
Added: RBXScriptSignal<Enums.ElevatorCallDirectionValues, number>,
|
||||||
|
__eventInstances__: {
|
||||||
|
Sorted: BindableEvent,
|
||||||
|
Added: BindableEvent
|
||||||
|
}
|
||||||
|
}
|
||||||
type Constructor_Fun = (ElevatorBoxModel: AlignPosition) -> ClassConstructor
|
type Constructor_Fun = (ElevatorBoxModel: AlignPosition) -> ClassConstructor
|
||||||
type Constructor_Return_Props = {
|
type Constructor_Return_Props = {
|
||||||
ElevatorBoxModel: AlignPosition,
|
ElevatorBoxModel: AlignPosition,
|
||||||
__FloorQueue: FloorQueue,
|
FloorQueue: FloorQueue,
|
||||||
|
Events: RelayAlgorithmEvents,
|
||||||
Events: {
|
|
||||||
Sorted: RBXScriptSignal,
|
|
||||||
Added: RBXScriptSignal<number>,
|
|
||||||
__eventInstances__: {
|
|
||||||
Sorted: BindableEvent,
|
|
||||||
Added: BindableEvent
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DoorAttributes = {
|
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
|
export type RelayAlgorithmConstructor = ClassConstructor
|
||||||
|
|
||||||
@@ -45,7 +56,10 @@ function RelayAlgorithm.constructor(ElevatorBoxModel)
|
|||||||
|
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
ElevatorBoxModel = ElevatorBoxModel,
|
ElevatorBoxModel = ElevatorBoxModel,
|
||||||
__FloorQueue = {},
|
FloorQueue = {
|
||||||
|
Up = {},
|
||||||
|
Down = {},
|
||||||
|
},
|
||||||
Events = {
|
Events = {
|
||||||
Sorted = Sorted.Event,
|
Sorted = Sorted.Event,
|
||||||
Added = Added.Event,
|
Added = Added.Event,
|
||||||
@@ -57,23 +71,26 @@ function RelayAlgorithm.constructor(ElevatorBoxModel)
|
|||||||
}, RelayAlgorithm)
|
}, RelayAlgorithm)
|
||||||
end
|
end
|
||||||
|
|
||||||
--The Otis relay based call logic
|
function RelayAlgorithm:Sort(Direction)
|
||||||
--https://youtu.be/BCN9mQOT3RQ
|
if Direction == Enums.ElevatorCallDirection.Up then
|
||||||
|
table.sort(self.FloorQueue.Up, function(FirstFloorIndex, LastFloorIndex): boolean
|
||||||
function RelayAlgorithm:Sort(ElevatorGoingUp)
|
return FirstFloorIndex<LastFloorIndex
|
||||||
table.sort(self.__FloorQueue, function(a, b): boolean
|
end)
|
||||||
if ElevatorGoingUp then
|
self.Events.__eventInstances__.Sorted:Fire(Enums.ElevatorCallDirection.Up, self.FloorQueue.Up)
|
||||||
return a<b
|
elseif Direction == Enums.ElevatorCallDirection.Down then
|
||||||
end
|
table.sort(self.FloorQueue.Down, function(FirstFloorIndex, LastFloorIndex): boolean
|
||||||
return a>b
|
return FirstFloorIndex>LastFloorIndex
|
||||||
end)
|
end)
|
||||||
self.Events.__eventInstances__.Sorted:Fire()
|
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
|
end
|
||||||
|
|
||||||
function RelayAlgorithm:AddFloor(ElevatorGoingUp, GoingUpAttribute, RequestedLevel)
|
function RelayAlgorithm:AddFloor(Direction, RequestedLevel)
|
||||||
table.insert(self.__FloorQueue, ElevatorGoingUp == GoingUpAttribute.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
|
table.insert(Direction == Enums.ElevatorCallDirection.Up and self.FloorQueue.Up or self.FloorQueue.Down, RequestedLevel)
|
||||||
self.Events.__eventInstances__.Added:Fire(RequestedLevel)
|
self.Events.__eventInstances__.Added:Fire(Direction, RequestedLevel)
|
||||||
self:Sort(ElevatorGoingUp)
|
self:Sort(Direction :: Enums.ElevatorCallDirectionValues)
|
||||||
end
|
end
|
||||||
|
|
||||||
return RelayAlgorithm
|
return RelayAlgorithm
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ local Elevators = script.Parent
|
|||||||
local MainDir = Elevators.Parent
|
local MainDir = Elevators.Parent
|
||||||
local LoadDir = MainDir:WaitForChild("Load")
|
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 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"))
|
||||||
@@ -20,8 +23,9 @@ type Impl_Constructor = {
|
|||||||
__index: Impl_Constructor,
|
__index: Impl_Constructor,
|
||||||
constructor: Constructor_Fun,
|
constructor: Constructor_Fun,
|
||||||
--Class functions
|
--Class functions
|
||||||
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
|
GetLevel: (self: ClassConstructor, Level: number, Direction: Enums.ElevatorCallDirectionValues) -> Vector3?,
|
||||||
__TravelToFloor: (self: ClassConstructor, LevelInt: number, LevelVec3: number, ElevatorGoingUp: boolean) -> (),
|
RequestLevel: (self: ClassConstructor, RequestedLevel: number, Direction: Enums.ElevatorCallDirectionValues) -> boolean,
|
||||||
|
__TravelToFloor: (self: ClassConstructor, LevelInt: number, VEC3_Y_WRAP: Vector3, Direction: Enums.ElevatorCallDirectionValues) -> (),
|
||||||
}
|
}
|
||||||
|
|
||||||
type FloorLevelingPositions = {number}
|
type FloorLevelingPositions = {number}
|
||||||
@@ -32,17 +36,18 @@ type Constructor_Return_Props = {
|
|||||||
FloorLevelingPositions: FloorLevelingPositions,
|
FloorLevelingPositions: FloorLevelingPositions,
|
||||||
|
|
||||||
Elevator: {
|
Elevator: {
|
||||||
BoxModel: UnionOperation,
|
TravelingDirection: Enums.ElevatorCallDirectionValues,
|
||||||
AlignPosition: AlignPosition,
|
BoxModel: UnionOperation,
|
||||||
Configuration: ElevatorTypes.ElevatorConfigurationTable
|
AlignPosition: AlignPosition,
|
||||||
|
Configuration: ElevatorTypes.ElevatorConfigurationTable
|
||||||
},
|
},
|
||||||
Attributes: {
|
Attributes: {
|
||||||
PreviousFloor: IntValue,
|
PreviousFloor: IntValue,
|
||||||
CurrentFloor: IntValue,
|
CurrentFloor: IntValue,
|
||||||
NextFloor: IntValue,
|
NextFloor: IntValue,
|
||||||
Goal: IntValue,
|
Goal: IntValue,
|
||||||
GoingUp: BoolValue,
|
TravelingUpwards: BoolValue,
|
||||||
Stopped: BoolValue
|
Stopped: BoolValue
|
||||||
},
|
},
|
||||||
Events: {
|
Events: {
|
||||||
CabProgression: RBXScriptSignal<number, number, number>,
|
CabProgression: RBXScriptSignal<number, number, number>,
|
||||||
@@ -100,7 +105,7 @@ local function Mover(ElevatorBoxModel: UnionOperation, Responsiveness: number, M
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions)
|
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,
|
local _BoxAttachment,
|
||||||
BoxAlignPosition,
|
BoxAlignPosition,
|
||||||
@@ -115,28 +120,27 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
|
|||||||
local Leveling3Phase = Instance.new("BindableEvent") :: BindableEvent
|
local Leveling3Phase = Instance.new("BindableEvent") :: BindableEvent
|
||||||
|
|
||||||
local Attributes = {
|
local Attributes = {
|
||||||
PreviousFloor = Instance.new("IntValue") :: IntValue,
|
PreviousFloor = Instance.new("IntValue") :: IntValue,
|
||||||
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
||||||
NextFloor = Instance.new("IntValue") :: IntValue,
|
NextFloor = Instance.new("IntValue") :: IntValue,
|
||||||
Goal = Instance.new("IntValue") :: IntValue,
|
Goal = Instance.new("IntValue") :: IntValue,
|
||||||
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
TravelingUpwards = Instance.new("BoolValue") :: BoolValue,
|
||||||
Stopped = Instance.new("BoolValue") :: BoolValue
|
Stopped = Instance.new("BoolValue") :: BoolValue
|
||||||
}
|
}
|
||||||
Attributes.CurrentFloor.Value = 1
|
Attributes.CurrentFloor.Value = 1
|
||||||
Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value
|
Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value
|
||||||
Attributes.NextFloor.Value = Attributes.CurrentFloor.Value+1
|
Attributes.NextFloor.Value = Attributes.CurrentFloor.Value+1
|
||||||
Attributes.GoingUp.Value = false
|
Attributes.TravelingUpwards.Value = true
|
||||||
Attributes.Goal.Value = 1
|
Attributes.Goal.Value = 1
|
||||||
|
|
||||||
print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`)
|
local ElevatorClass = setmetatable({
|
||||||
|
|
||||||
return setmetatable({
|
|
||||||
RelayAlgorithm = RelayAlgorithmConstructor,
|
RelayAlgorithm = RelayAlgorithmConstructor,
|
||||||
FloorLevelingPositions = FloorLevelingPositions,
|
FloorLevelingPositions = FloorLevelingPositions,
|
||||||
Elevator = {
|
Elevator = {
|
||||||
BoxModel = ElevatorBoxModel,
|
TravelingDirection = Enums.ElevatorCallDirection.Up,
|
||||||
AlignPosition = BoxAlignPosition,
|
BoxModel = ElevatorBoxModel,
|
||||||
Configuration = ElevatorConfigurationTable,
|
AlignPosition = BoxAlignPosition,
|
||||||
|
Configuration = ElevatorConfigurationTable,
|
||||||
},
|
},
|
||||||
Events = {
|
Events = {
|
||||||
CabProgression = CabProgression.Event,
|
CabProgression = CabProgression.Event,
|
||||||
@@ -155,29 +159,54 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
|
|||||||
Attributes = Attributes,
|
Attributes = Attributes,
|
||||||
__Connections = {}
|
__Connections = {}
|
||||||
}, Elevator)
|
}, 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
|
end
|
||||||
|
|
||||||
local function CheckFloorQueue(self: ClassConstructor)
|
local function CheckFloorQueue(self: ClassConstructor, Direction: Enums.ElevatorCallDirectionValues)
|
||||||
if self.RelayAlgorithm.__FloorQueue[1] ~= self.Attributes.CurrentFloor.Value then
|
local DirectionFloorQueue = Direction == Enums.ElevatorCallDirection.Up and self.RelayAlgorithm.FloorQueue.Up or self.RelayAlgorithm.FloorQueue.Down
|
||||||
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 NextFloorInQueue = self.RelayAlgorithm.__FloorQueue[1]
|
if DirectionFloorQueue[1] ~= self.Attributes.CurrentFloor.Value then
|
||||||
print(NextFloorInQueue)
|
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
|
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
|
||||||
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 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
|
--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
|
||||||
@@ -188,17 +217,17 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Elevator is riding upwards towards the destination
|
--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.Events.__eventInstances__.Leveling:Fire()
|
||||||
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity
|
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.Events.__eventInstances__.Leveling3Phase:Fire()
|
||||||
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity
|
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()
|
self.Events.__eventInstances__.Parked:Fire()
|
||||||
CheckFloorQueue(self);
|
CheckFloorQueue(self, Direction);
|
||||||
|
|
||||||
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
||||||
end
|
end
|
||||||
@@ -214,17 +243,17 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Elevator is riding upwards towards the destination
|
--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.Events.__eventInstances__.Leveling:Fire()
|
||||||
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.LevelingVelocity
|
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.Events.__eventInstances__.Leveling3Phase:Fire()
|
||||||
self.Elevator.AlignPosition.MaxVelocity = self.Elevator.Configuration.Phase3LevelingVelocity
|
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()
|
self.Events.__eventInstances__.Parked:Fire()
|
||||||
CheckFloorQueue(self);
|
CheckFloorQueue(self, Direction);
|
||||||
|
|
||||||
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
||||||
end
|
end
|
||||||
@@ -235,34 +264,48 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3
|
|||||||
self.Events.__eventInstances__.CabTraveling:Fire(deltaTime, ElevatorPosition)
|
self.Events.__eventInstances__.CabTraveling:Fire(deltaTime, ElevatorPosition)
|
||||||
end
|
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
|
if self.__Connections.Moving and self.__Connections.Moving.Connected then
|
||||||
self.__Connections.Moving:Disconnect()
|
self.__Connections.Moving:Disconnect()
|
||||||
end
|
end
|
||||||
|
|
||||||
self.Attributes.Goal.Value = LevelInt
|
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)
|
self.__Connections.Moving = RunService.Heartbeat:Connect(function(deltaTime: number)
|
||||||
CabTraveling(self, deltaTime, LevelVec3, ElevatorGoingUp)
|
CabTraveling(self, deltaTime, VEC3_Y_WRAP, Direction :: Enums.ElevatorCallDirectionValues)
|
||||||
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, 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
|
--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)
|
function Elevator:RequestLevel(RequestedLevel, Direction)
|
||||||
local LevelVec3 = self.FloorLevelingPositions[RequestedLevel]
|
local Level = self:GetLevel(RequestedLevel, Direction :: Enums.ElevatorCallDirectionValues)
|
||||||
|
|
||||||
if LevelVec3 then
|
if Level then
|
||||||
if RequestedLevel ~= self.Attributes.CurrentFloor.Value then
|
if RequestedLevel ~= self.Attributes.CurrentFloor.Value then
|
||||||
local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, RequestedLevel)
|
if (RequestedLevel == 1 and Direction == Enums.ElevatorCallDirection.Down) or (RequestedLevel == #self.FloorLevelingPositions and Direction == Enums.ElevatorCallDirection.Up) then
|
||||||
self.RelayAlgorithm:AddFloor(ElevatorGoingUp, self.Attributes.GoingUp, RequestedLevel)
|
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
|
if #DirectionQueue == 1 then
|
||||||
self:__TravelToFloor(RequestedLevel, LevelVec3, ElevatorGoingUp)
|
self:__TravelToFloor(RequestedLevel, Level, Direction :: Enums.ElevatorCallDirectionValues)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
warn(`[{self.Elevator.Configuration.Name}]: The elevator is already at the requested floor. RequestLevel={RequestedLevel}, CurrentLevel={self.Attributes.CurrentFloor.Value}`)
|
warn(`[{self.Elevator.Configuration.Name}]: The elevator is already at the requested floor. RequestLevel={RequestedLevel}, CurrentLevel={self.Attributes.CurrentFloor.Value}`)
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
local ParentDir = script.Parent
|
local ParentDir = script.Parent
|
||||||
local MainDir = ParentDir.Parent
|
local MainDir = ParentDir.Parent
|
||||||
|
|
||||||
|
local StorageService = game:GetService("ReplicatedStorage")
|
||||||
|
|
||||||
|
local Enums = require(StorageService:WaitForChild("Enums"))
|
||||||
local InitElevator = require(ParentDir:WaitForChild("InitElevator"))
|
local InitElevator = require(ParentDir:WaitForChild("InitElevator"))
|
||||||
local TagsModule = require(MainDir:WaitForChild("Load"):WaitForChild("Tags"))
|
local TagsModule = require(MainDir:WaitForChild("Load"):WaitForChild("Tags"))
|
||||||
|
|
||||||
@@ -48,7 +51,7 @@ return function(TagsConstructor: TagsModule.TagsConstructor, ButtonTags: TagsMod
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
task.wait(1)
|
task.wait(1)
|
||||||
Elevator:RequestLevel(3)
|
Elevator:RequestLevel(3, Enums.ElevatorCallDirection.Up)
|
||||||
Elevator:RequestLevel(5)
|
Elevator:RequestLevel(5, Enums.ElevatorCallDirection.Up)
|
||||||
Elevator:RequestLevel(2)
|
Elevator:RequestLevel(2, Enums.ElevatorCallDirection.Down)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
local SoundEnums = {}
|
local SoundEnums = {}
|
||||||
|
|
||||||
|
--MACROSSSSSSSSSSS
|
||||||
export type Otis1960Sounds = typeof(SoundEnums.Otis1960)
|
export type Otis1960Sounds = typeof(SoundEnums.Otis1960)
|
||||||
|
|
||||||
export type Otis1960LanternChimeDirection = "rbxassetid://16990287228"
|
export type Otis1960LanternChimeDirection = "rbxassetid://16990287228"
|
||||||
export type Otis1960LanternChimeLanding = "rbxassetid://16990290265"
|
export type Otis1960LanternChimeLanding = "rbxassetid://16990290265"
|
||||||
export type Otis1960DoorClosingClick = "rbxassetid://16357740945"
|
export type Otis1960DoorClosingClick = "rbxassetid://16357740945"
|
||||||
@@ -14,18 +14,8 @@ export type Otis1960RelayLowActivated = "rbxassetid://17701796245"
|
|||||||
export type Otis1960RelayDeActivated = "rbxassetid://17702004158"
|
export type Otis1960RelayDeActivated = "rbxassetid://17702004158"
|
||||||
export type Otis1960BigRelayActivated = "rbxassetid://17701707630"
|
export type Otis1960BigRelayActivated = "rbxassetid://17701707630"
|
||||||
export type Otis1960BigRelayDeActivated = "rbxassetid://17701712012"
|
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
|
export type ElevatorSoundValues = Otis1960SoundValues
|
||||||
|
|
||||||
SoundEnums.Otis1960 = {
|
SoundEnums.Otis1960 = {
|
||||||
LanternChimeDirection = "rbxassetid://16990287228" :: Otis1960LanternChimeDirection,
|
LanternChimeDirection = "rbxassetid://16990287228" :: Otis1960LanternChimeDirection,
|
||||||
LanternChimeLanding = "rbxassetid://16990290265" :: Otis1960LanternChimeLanding,
|
LanternChimeLanding = "rbxassetid://16990290265" :: Otis1960LanternChimeLanding,
|
||||||
|
|||||||
@@ -4,33 +4,11 @@
|
|||||||
|
|
||||||
local Enums = {}
|
local Enums = {}
|
||||||
|
|
||||||
|
--MACROSSSSSSSSSSS
|
||||||
export type EnumValue = EnumButton | EnumButtonTree | EnumElevator | EnumInteractables | EnumSpecialButton
|
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 = {
|
Enums.Button = {
|
||||||
Car = "CarButton" :: "CarButton",
|
Car = "CarButton" :: "CarButton",
|
||||||
Landing = "LandingButton" :: "LandingButton",
|
Landing = "LandingButton" :: "LandingButton",
|
||||||
@@ -38,6 +16,8 @@ Enums.Button = {
|
|||||||
Relay = "RelayButton" :: "RelayButton"
|
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 = {
|
Enums.ButtonTree = {
|
||||||
Car = "Car" :: "Car",
|
Car = "Car" :: "Car",
|
||||||
Landing = "Landing" :: "Landing",
|
Landing = "Landing" :: "Landing",
|
||||||
@@ -46,19 +26,32 @@ Enums.ButtonTree = {
|
|||||||
Unknown = "Unknown" :: "Unknown"
|
Unknown = "Unknown" :: "Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type EnumSpecialButton = typeof(Enums.SpecialButton)
|
||||||
|
export type SpecialButtonValues = typeof(Enums.SpecialButton.Stop)
|
||||||
Enums.SpecialButton = {
|
Enums.SpecialButton = {
|
||||||
Stop = "Stop" :: "Stop"
|
Stop = "Stop" :: "Stop"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type EnumElevator = typeof(Enums.Elevator)
|
||||||
|
export type ElevatorValues = typeof(Enums.Elevator.Otis1960) | typeof(Enums.Elevator.Haughton)
|
||||||
Enums.Elevator = {
|
Enums.Elevator = {
|
||||||
Otis1960 = "Otis1960" :: "Otis1960",
|
Otis1960 = "Otis1960" :: "Otis1960",
|
||||||
Haughton = "Haughton" :: "Haughton"
|
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 = {
|
Enums.InteractType = {
|
||||||
LightSwitch = "LightSwitch" :: "LightSwitch",
|
LightSwitch = "LightSwitch" :: "LightSwitch",
|
||||||
Light = "Light" :: "Light",
|
Light = "Light" :: "Light",
|
||||||
LightSource = "LightSource" :: "LightSource"
|
LightSource = "LightSource" :: "LightSource"
|
||||||
}
|
}
|
||||||
|
|
||||||
return Enums
|
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
|
||||||
|
|||||||
50
src/shared/Output.luau
Normal file
50
src/shared/Output.luau
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
--!optimize 2
|
||||||
|
--!native
|
||||||
|
--!strict
|
||||||
|
|
||||||
|
local RunService = game:GetService("RunService")
|
||||||
|
|
||||||
|
local function printStudio<T...>(...: T...)
|
||||||
|
if RunService:IsStudio() then
|
||||||
|
print(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function printServer<T...>(...: T...)
|
||||||
|
if RunService:IsServer() then
|
||||||
|
print(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function printClient<T...>(...: T...)
|
||||||
|
if RunService:IsClient() then
|
||||||
|
print(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function warnStudio<T...>(...: T...)
|
||||||
|
if RunService:IsStudio() then
|
||||||
|
warn(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function warnServer<T...>(...: T...)
|
||||||
|
if RunService:IsServer() then
|
||||||
|
warn(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function warnClient<T...>(...: T...)
|
||||||
|
if RunService:IsClient() then
|
||||||
|
warn(...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
printStudio = printStudio,
|
||||||
|
printServer = printServer,
|
||||||
|
printClient = printClient,
|
||||||
|
warnStudio = warnStudio,
|
||||||
|
warnServer = warnServer,
|
||||||
|
warnClient = warnClient
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user