Introduce Ready attribute for moving

This commit is contained in:
2024-05-21 22:33:29 -04:00
parent 70d58e9727
commit b5f214f3b8
2 changed files with 36 additions and 39 deletions

View File

@@ -72,10 +72,6 @@ Doors.Attributes = {
Doors.Attributes.Open.Value = false Doors.Attributes.Open.Value = false
Doors.Attributes.Open:GetPropertyChangedSignal("Value"):Connect(function()
print("Open=",Doors.Attributes.Open.Value)
end)
local Attributes = Doors.Attributes local Attributes = Doors.Attributes
function Doors.constructor(FloorDoorsTags, ElevatorBox, ElevatorDoor1, ElevatorDoor2, ElevatorDoorSensor) function Doors.constructor(FloorDoorsTags, ElevatorBox, ElevatorDoor1, ElevatorDoor2, ElevatorDoorSensor)
@@ -198,8 +194,6 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
break break
end end
end end
Attributes.Open.Value = true
else else
local Door1Tween = self.DoorTween1:Start(nil, { local Door1Tween = self.DoorTween1:Start(nil, {
Position = ElevatorDoor1_P+Doors.Door1Stopped_X Position = ElevatorDoor1_P+Doors.Door1Stopped_X
@@ -274,16 +268,12 @@ end
function Doors:ToggleElevatorDoorsAsync(opening, floor) function Doors:ToggleElevatorDoorsAsync(opening, floor)
--short circuiting central --short circuiting central
if opening then if opening then
if not Attributes.Open.Value then if Attributes.Open.Value then
Attributes.Open.Value = not Attributes.Open.Value
else
warn("Doors are already closed, doing nothing") warn("Doors are already closed, doing nothing")
return return
end end
else else
if Attributes.Open.Value then if not Attributes.Open.Value then
Attributes.Open.Value = not Attributes.Open.Value
else
warn("Doors are already open, doing nothing") warn("Doors are already open, doing nothing")
return return
end end

View File

@@ -58,8 +58,8 @@ type Impl_Constructor = {
FloorPassingUp: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (), FloorPassingUp: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
FloorPassingDown: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (), FloorPassingDown: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean, RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
__Move: (self: ClassConstructor, Level: number, GoingUp: boolean) -> (), __MoveTo: (self: ClassConstructor, GoingUp: boolean, GoalFloor_Y: number) -> (),
__MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean) -> (), __MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean, GoalFloor_Y: number) -> (),
} & Impl_Static_Props } & Impl_Static_Props
type Impl_Static_Props = { type Impl_Static_Props = {
@@ -84,6 +84,8 @@ type Impl_Static_Props = {
Attributes: { Attributes: {
CurrentFloor: IntValue, CurrentFloor: IntValue,
Goal: IntValue, Goal: IntValue,
GoalYLevel: NumberValue,
Ready: BoolValue,
Moving: BoolValue, Moving: BoolValue,
GoingUp: BoolValue, GoingUp: BoolValue,
Stopped: BoolValue Stopped: BoolValue
@@ -147,6 +149,8 @@ Elevator.Colors = {
Elevator.Attributes = { Elevator.Attributes = {
CurrentFloor = Instance.new("IntValue") :: IntValue, CurrentFloor = Instance.new("IntValue") :: IntValue,
Goal = Instance.new("IntValue") :: IntValue, Goal = Instance.new("IntValue") :: IntValue,
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
Ready = Instance.new("BoolValue") :: BoolValue,
Moving = Instance.new("BoolValue") :: BoolValue, Moving = Instance.new("BoolValue") :: BoolValue,
GoingUp = Instance.new("BoolValue") :: BoolValue, GoingUp = Instance.new("BoolValue") :: BoolValue,
Stopped = Instance.new("BoolValue") :: BoolValue Stopped = Instance.new("BoolValue") :: BoolValue
@@ -158,6 +162,7 @@ Elevator.Events = {
Elevator.Attributes.CurrentFloor.Value = 1 Elevator.Attributes.CurrentFloor.Value = 1
Elevator.Attributes.Goal.Value = 1 Elevator.Attributes.Goal.Value = 1
Elevator.Attributes.Ready.Value = false
Elevator.Attributes.Moving.Value = false Elevator.Attributes.Moving.Value = false
Elevator.Attributes.GoingUp.Value = false Elevator.Attributes.GoingUp.Value = false
@@ -221,7 +226,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05) (ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
self.LanternsConstructor:Reset() self.LanternsConstructor:Reset()
self:__GoToFloor(Leveling[Attributes.CurrentFloor.Value], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Goal.Value)) self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Goal.Value), Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
end end
end) end)
@@ -310,6 +315,17 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value) self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
end) end)
--This is how the elevator logic works with the elevator itself
Attributes.Ready:GetPropertyChangedSignal("Value"):Connect(function()
if Attributes.Ready.Value then
self.BoxAlignPosition.Position = Vector3.new(self.ElevatorBox_1960.Position.X, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], self.ElevatorBox_1960.Position.Z)
end
end)
Doors.Attributes.Open:GetPropertyChangedSignal("Value"):Connect(function()
print(Doors.Attributes.Open.Value)
Attributes.Ready.Value = not Doors.Attributes.Open.Value
end)
print(`🔝 {Elevator.Name} initialized and ready`) print(`🔝 {Elevator.Name} initialized and ready`)
return ClassConstructor return ClassConstructor
end end
@@ -327,7 +343,7 @@ function Elevator:Leveled(RequestedLevel)
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then
--More floors in the queue --More floors in the queue
self:__Move(Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorGoingUp) self:__MoveTo(ElevatorGoingUp, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
end end
end end
@@ -354,12 +370,13 @@ function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
end end
end end
function Elevator:__MovingHeartbeat(GoingUp) function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
Attributes.GoingUp.Value = GoingUp Attributes.GoingUp.Value = GoingUp
if self.__MovingConnection and self.__MovingConnection.Connected then if self.__MovingConnection and self.__MovingConnection.Connected then
self.__MovingConnection:Disconnect() self.__MovingConnection:Disconnect()
end end
self.MOConstructor:UpdateCFrame()
local Delta = 0 local Delta = 0
local DoorsOpeningEvent = false local DoorsOpeningEvent = false
@@ -414,7 +431,7 @@ function Elevator:__MovingHeartbeat(GoingUp)
end) end)
end end
function Elevator:__Move(GoalLevelVEC, GoingUp) function Elevator:__MoveTo(GoingUp, GoalFloor_Y)
if Doors.Attributes.Open.Value then if Doors.Attributes.Open.Value then
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value) self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
end end
@@ -424,28 +441,18 @@ function Elevator:__Move(GoalLevelVEC, GoingUp)
self.LanternsConstructor:DirectionDown(true) self.LanternsConstructor:DirectionDown(true)
end end
self.MOConstructor:UpdateCFrame() self:__MovingHeartbeat(GoingUp, GoalFloor_Y)
self:__MovingHeartbeat(GoingUp)
local ElevatorPositionInit = self.ElevatorBox_1960.Position
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, GoalLevelVEC, ElevatorPositionInit.Z)
end end
function Elevator:RequestLevel(RequestedLevel) function Elevator:RequestLevel(RequestedLevel)
local GoalLevelVEC: number? = Leveling[RequestedLevel] local GoalFloor_Y: number? = Leveling[RequestedLevel]
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then if GoalFloor_Y and RequestedLevel ~= Attributes.CurrentFloor.Value then
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel) local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel) local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
if Proceeding then if Doors.Attributes.Open.Value then
self:__Move(GoalLevelVEC, ElevatorGoingUp) self:__MoveTo(ElevatorGoingUp, GoalFloor_Y)
else
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 end
else else
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`) warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)