No work motiviation but hooked the relay algorithm to the elevator

This commit is contained in:
2024-05-20 23:04:58 -04:00
parent b67c70aad1
commit 70d58e9727
4 changed files with 62 additions and 75 deletions

View File

@@ -36,7 +36,7 @@ type Impl_Static_Props = {
__DontLeakMemory: RBXScriptConnection?,
Attributes: {
DoorsOpen: BoolValue
Open: BoolValue
}
}
type Constructor_Return_Props = {
@@ -67,13 +67,13 @@ Doors.ElevatorDoorTime = 4
Doors.ElevatorDoorStyle = Enum.EasingStyle.Quad
Doors.Attributes = {
DoorsOpen = Instance.new("BoolValue") :: BoolValue
Open = Instance.new("BoolValue") :: BoolValue
}
Doors.Attributes.DoorsOpen.Value = false
Doors.Attributes.Open.Value = false
Doors.Attributes.DoorsOpen:GetPropertyChangedSignal("Value"):Connect(function()
print("DoorsOpen=",Doors.Attributes.DoorsOpen.Value)
Doors.Attributes.Open:GetPropertyChangedSignal("Value"):Connect(function()
print("Open=",Doors.Attributes.Open.Value)
end)
local Attributes = Doors.Attributes
@@ -199,7 +199,7 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
end
end
Attributes.DoorsOpen.Value = true
Attributes.Open.Value = true
else
local Door1Tween = self.DoorTween1:Start(nil, {
Position = ElevatorDoor1_P+Doors.Door1Stopped_X
@@ -252,7 +252,7 @@ end
function Doors:__DetectSensorHit(DoorTween1, DoorTween2)
local Step = nil
if Doors.Sensors and Attributes.DoorsOpen.Value then
if Doors.Sensors and Attributes.Open.Value then
raycastParams.FilterDescendantsInstances = {self.ElevatorBox, table.unpack(RayIgnoring)}
Step = RS.Heartbeat:Connect(function(_dt)
@@ -274,15 +274,15 @@ end
function Doors:ToggleElevatorDoorsAsync(opening, floor)
--short circuiting central
if opening then
if not Attributes.DoorsOpen.Value then
Attributes.DoorsOpen.Value = not Attributes.DoorsOpen.Value
if not Attributes.Open.Value then
Attributes.Open.Value = not Attributes.Open.Value
else
warn("Doors are already closed, doing nothing")
return
end
else
if Attributes.DoorsOpen.Value then
Attributes.DoorsOpen.Value = not Attributes.DoorsOpen.Value
if Attributes.Open.Value then
Attributes.Open.Value = not Attributes.Open.Value
else
warn("Doors are already open, doing nothing")
return
@@ -298,10 +298,10 @@ function Doors:ToggleElevatorDoorsAsync(opening, floor)
if Door2Tween then
Door2Tween.Completed:Wait()
Attributes.DoorsOpen.Value = opening ~= nil and opening or false
Attributes.Open.Value = opening ~= nil and opening or false
elseif Door1Tween then
Door1Tween.Completed:Wait()
Attributes.DoorsOpen.Value = opening ~= nil and opening or false
Attributes.Open.Value = opening ~= nil and opening or false
end
self.ElevatorDoor1.CanCollide = true

View File

@@ -78,7 +78,7 @@ function MovingObjects:Frame_Pullies(Delta, ElevatorVelocity_Y)
local PullAngle = math.rad(RotAngle)
MR.Pulley.CFrame = MR_C.PulleyCFrame *CFrame.Angles(-PullAngle_2, 0, 0)
MR.Pulley2.CFrame = MR_C.Pulley2CFrame *CFrame.Angles(PullAngle_2, 0, 0)
MR.Pulley2.CFrame = MR_C.Pulley2CFrame *CFrame.Angles(PullAngle_2, 0, 0)
MR.Governor.CFrame = MR_C.GovernorCFrame *CFrame.Angles(0, PullAngle_2, 0)
MR.GovernorFlyballs.CFrame = MR_C.GovernorFlyballsCFrame*CFrame.Angles(PullAngle, 0, 0)
MR.PiePlatePulley.CFrame = MR_C.PieplatePulleyCFrame *CFrame.Angles(PullAngle_2, 0, 0)

View File

@@ -7,9 +7,10 @@ type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
Insert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
RawInsert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> boolean
}
type Constructor_Fun = (BoxAlignPosition: AlignPosition, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes) -> ClassConstructor
@@ -17,19 +18,18 @@ type Constructor_Return_Props = {
BoxAlignPosition: AlignPosition,
ElevatorAttributes: ElevatorAttributes,
DoorAttributes: DoorAttributes,
__FloorQueue: Floors
__FloorQueue: {number}
}
type Floors = {number}
type ElevatorAttributes = {
CurrentFloor: IntValue,
Goal: IntValue,
GoingUp: BoolValue,
GoalFloor: IntValue
Moving: BoolValue
}
type DoorAttributes = {
DoorsOpen: BoolValue
Open: BoolValue
}
export type RelayAlgorithmConstructor = ClassConstructor
@@ -49,23 +49,6 @@ end
--The Otis relay based call logic
--https://youtu.be/BCN9mQOT3RQ
--Sort the queue based on direction
--[[
Up: {
[1] = 5,
[2] = 6,
[3] = 7,
[4] = 8,
[5] = 9,
[6] = 10
}
Down: {
[1] = 5,
[2] = 3,
[3] = 2,
[4] = 1
}
]]
function RelayAlgorithm:Sort(ElevatorGoingUp)
table.sort(self.__FloorQueue, function(a: number, b: number): boolean
if ElevatorGoingUp then
@@ -85,13 +68,26 @@ function RelayAlgorithm:Check(ElevatorGoingUp)
self:Sort(ElevatorGoingUp)
return true
end
return false
end
function RelayAlgorithm:Insert(ElevatorGoingUp, RequestedLevel)
function RelayAlgorithm:RawInsert(ElevatorGoingUp, RequestedLevel)
table.insert(self.__FloorQueue, ElevatorGoingUp == self.ElevatorAttributes.GoingUp.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
self:Sort(ElevatorGoingUp)
end
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
if self.ElevatorAttributes.Moving.Value then
self:RawInsert(ElevatorGoingUp, RequestedLevel)
else
if self.DoorAttributes.Open.Value then
self:RawInsert(ElevatorGoingUp, RequestedLevel)
return true
else
self:RawInsert(ElevatorGoingUp, RequestedLevel)
end
end
return false
end
return RelayAlgorithm

View File

@@ -58,7 +58,7 @@ type Impl_Constructor = {
FloorPassingUp: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
FloorPassingDown: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
__GoToFloor: (self: ClassConstructor, Level: number, GoingUp: boolean) -> (),
__Move: (self: ClassConstructor, Level: number, GoingUp: boolean) -> (),
__MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean) -> (),
} & Impl_Static_Props
@@ -83,7 +83,7 @@ type Impl_Static_Props = {
},
Attributes: {
CurrentFloor: IntValue,
GoalFloor: IntValue,
Goal: IntValue,
Moving: BoolValue,
GoingUp: BoolValue,
Stopped: BoolValue
@@ -146,7 +146,7 @@ Elevator.Colors = {
Elevator.Attributes = {
CurrentFloor = Instance.new("IntValue") :: IntValue,
GoalFloor = Instance.new("IntValue") :: IntValue,
Goal = Instance.new("IntValue") :: IntValue,
Moving = Instance.new("BoolValue") :: BoolValue,
GoingUp = Instance.new("BoolValue") :: BoolValue,
Stopped = Instance.new("BoolValue") :: BoolValue
@@ -157,7 +157,7 @@ Elevator.Events = {
}
Elevator.Attributes.CurrentFloor.Value = 1
Elevator.Attributes.GoalFloor.Value = 1
Elevator.Attributes.Goal.Value = 1
Elevator.Attributes.Moving.Value = false
Elevator.Attributes.GoingUp.Value = false
@@ -176,7 +176,7 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
local FloorTracker: RBXScriptConnection
FloorTracker = Attributes.CurrentFloor:GetPropertyChangedSignal("Value"):Connect(function()
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.GoalFloor.Value == ButtonFloor then
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Goal.Value == ButtonFloor then
FloorTracker:Disconnect()
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
@@ -185,6 +185,7 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
end)
else
warn(`Failed to call floor: {ButtonFloor}`)
ButtonTree.Prompt.Enabled = true
end
end
@@ -220,7 +221,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
self.LanternsConstructor:Reset()
self:__GoToFloor(Leveling[Attributes.CurrentFloor.Value], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.GoalFloor.Value))
self:__GoToFloor(Leveling[Attributes.CurrentFloor.Value], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Goal.Value))
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
end
end)
@@ -318,7 +319,6 @@ function Elevator:Leveled(RequestedLevel)
Attributes.Moving.Value = false
Attributes.CurrentFloor.Value = RequestedLevel
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
task.wait(Elevator.QueueWaitTime)
@@ -327,8 +327,7 @@ function Elevator:Leveled(RequestedLevel)
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then
--More floors in the queue
Attributes.GoingUp.Value = ElevatorGoingUp
self:__GoToFloor(Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorGoingUp)
self:__Move(Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorGoingUp)
end
end
@@ -356,22 +355,21 @@ function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
end
function Elevator:__MovingHeartbeat(GoingUp)
local Delta = 0
local DoorsOpeningEvent = false
Attributes.GoingUp.Value = GoingUp
if self.__MovingConnection and self.__MovingConnection.Connected then
self.__MovingConnection:Disconnect()
end
--Only used for the X and Z axis
local ElevatorPositionInit: Vector3 = self.ElevatorBox_1960.Position
local Delta = 0
local DoorsOpeningEvent = false
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt)
Delta+=1
local FloorGoal: number = self.RelayAlgorithmConstructor.__FloorQueue[1]
Attributes.Moving.Value = true
Attributes.GoalFloor.Value = FloorGoal
Attributes.Goal.Value = FloorGoal
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
local ElevatorPositionY: number = ElevatorPosition.Y
@@ -413,16 +411,13 @@ function Elevator:__MovingHeartbeat(GoingUp)
self:Leveled(FloorGoal)
end
end
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, Leveling[FloorGoal], ElevatorPositionInit.Z)
end)
end
function Elevator:__GoToFloor(GoalLevelVEC, GoingUp)
if Doors.Attributes.DoorsOpen.Value then
function Elevator:__Move(GoalLevelVEC, GoingUp)
if Doors.Attributes.Open.Value then
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
end
if GoingUp then
self.LanternsConstructor:DirectionUp(true)
else
@@ -431,9 +426,9 @@ function Elevator:__GoToFloor(GoalLevelVEC, GoingUp)
self.MOConstructor:UpdateCFrame()
self:__MovingHeartbeat(GoingUp)
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z)
local ElevatorPositionInit = self.ElevatorBox_1960.Position
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, GoalLevelVEC, ElevatorPositionInit.Z)
end
function Elevator:RequestLevel(RequestedLevel)
@@ -441,19 +436,15 @@ function Elevator:RequestLevel(RequestedLevel)
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
if Attributes.Moving.Value then
self.RelayAlgorithmConstructor:Insert(ElevatorGoingUp, RequestedLevel)
if Proceeding then
self:__Move(GoalLevelVEC, ElevatorGoingUp)
else
if Doors.Attributes.DoorsOpen then
Attributes.GoingUp.Value = ElevatorGoingUp
if Doors.Attributes.DoorsOpen and #self.RelayAlgorithmConstructor.__FloorQueue == 0 then
self:__GoToFloor(GoalLevelVEC, ElevatorGoingUp)
end
self.RelayAlgorithmConstructor:Insert(ElevatorGoingUp, RequestedLevel)
else
self.RelayAlgorithmConstructor:Insert(ElevatorGoingUp, RequestedLevel)
if not Doors.Attributes.Open.Value then
local ElevatorPositionInit = self.ElevatorBox_1960.Position
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorPositionInit.Z)
print(Doors.Attributes.Open.Value)
end
end
else