Call button fallback

This commit is contained in:
2024-05-26 01:23:13 -04:00
parent c9f0074217
commit 54d6358751
4 changed files with 65 additions and 58 deletions

View File

@@ -14,6 +14,7 @@ local PromptModule = require(Main:WaitForChild("Map"):WaitForChild("Prompts"))
local Tags = require(Load:WaitForChild("Tags"))
type FloorButtonActivatedCallback = (ButtonFloor: number) -> ()
type FloorButtonActivatedFallback = FloorButtonActivatedCallback
type StopButtonActivatedCallback = (Toggled: SpecialButtonToggle) -> ()
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
@@ -21,8 +22,8 @@ type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
CarButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback) -> (),
LandingButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback) -> (),
CarButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback, Fallback: FloorButtonActivatedFallback) -> (),
LandingButton: (self: ClassConstructor, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: FloorButtonActivatedCallback, Fallback: FloorButtonActivatedFallback) -> (),
SpecialButton: (self: ClassConstructor, ButtonName: Enums.SpecialButtonValues, ButtonID: string, ButtonTree: Tags.ButtonProperties, Callback: StopButtonActivatedCallback) -> (),
AestheticActivateButton: (self: ClassConstructor, Button: BasePart, Glass: BasePart?) -> (),
__DeactivateButton: (self: ClassConstructor, Button: BasePart, Glass: BasePart?) -> (),
@@ -76,7 +77,7 @@ function ButtonFunctions.constructor(ElevatorAttributes, ElevatorEvents, Elevato
}, ButtonFunctions)
end
function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback)
function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback, Fallback)
local DecodedCarFloorTag = Tags.Decoders.CarTag(ButtonID)
if DecodedCarFloorTag then
@@ -87,6 +88,8 @@ function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback)
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
if DecodedCarFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
Fallback(DecodedCarFloorTag)
task.delay(ButtonFunctions.AestheticDeactivateTime, function()
self:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: Instance):FindFirstChild("Glass") :: BasePart?)
end)
@@ -97,7 +100,7 @@ function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback)
end
end
function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback)
function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback, Fallback)
local DecodedHallFloorTag = Tags.Decoders.HallTag(ButtonID)
if DecodedHallFloorTag then
@@ -108,6 +111,8 @@ function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback)
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
if DecodedHallFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
Fallback(DecodedHallFloorTag)
task.delay(ButtonFunctions.AestheticDeactivateTime, function()
self:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: Instance):FindFirstChild("Glass") :: BasePart?)
end)

View File

@@ -33,7 +33,7 @@ type Impl_Static_Props = {
Door2Stopped_X: Vector3,
ElevatorDoorTime: number,
ElevatorDoorStyle: Enum.EasingStyle,
__DontLeakMemory: RBXScriptConnection?,
__DoorSensors: RBXScriptConnection?,
Attributes: {} & RelayAttributes
}
@@ -112,9 +112,8 @@ local init_floors_closed: FloorDoors = {}
local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
local Door2Tween_Floor: Tween?
local Door1Tween_Floor: Tween?
local FloorDoor1 = FloorDoors[1] :: BasePart?
local FloorDoor2 = FloorDoors[2] :: BasePart?
local FloorDoor1 = FloorDoors[1] :: BasePart?
local FloorDoor2 = FloorDoors[2] :: BasePart?
local FloorDoor1_P = FloorDoor1 and FloorDoor1.Position
local FloorDoor2_P = FloorDoor2 and FloorDoor2.Position
@@ -173,7 +172,7 @@ local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, openi
return Door1Tween_Floor, Door2Tween_Floor
end
local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
local function ElevatorDoorsAnimationAsync(self: ClassConstructor, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
--Roblox physics will freak out
self.ElevatorDoor1.CanCollide = false
self.ElevatorDoor2.CanCollide = false
@@ -217,10 +216,10 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
Enum.EasingDirection.Out
))
if Doors.__DontLeakMemory and Doors.__DontLeakMemory.Connected then
Doors.__DontLeakMemory:Disconnect()
if Doors.__DoorSensors and Doors.__DoorSensors.Connected then
Doors.__DoorSensors:Disconnect()
end
Doors.__DontLeakMemory = self:__DetectSensorHit(Door1Tween, Door2Tween)
Doors.__DoorSensors = self:__DetectSensorHit(Door1Tween, Door2Tween)
--Door clicking noise
task.delay(Doors.ElevatorDoorTime-.90, function()
@@ -230,6 +229,12 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
end
end)
if Door2Tween then
Door2Tween.Completed:Wait()
elseif Door1Tween then
Door1Tween.Completed:Wait()
end
return Door1Tween, Door2Tween
end
@@ -263,7 +268,7 @@ function Doors:__DetectSensorHit(DoorTween1, DoorTween2)
DoorTween1:Pause()
DoorTween2:Pause()
task.wait(1) --elevators irl have this delay
ElevatorDoorsAnimation(self, true, true)
ElevatorDoorsAnimationAsync(self, true, true)
end
end)
end
@@ -290,21 +295,15 @@ function Doors:ToggleElevatorDoorsAsync(opening, floor)
DoorsAnimationFloor(FloorDoorsObjects, floor, opening)
end
local Door2Tween, Door1Tween = ElevatorDoorsAnimation(self, opening)
local _Door2Tween, _Door1Tween = ElevatorDoorsAnimationAsync(self, opening)
if Door2Tween then
Door2Tween.Completed:Wait()
Attributes.Relay.Open.Value = opening ~= nil and opening or false
elseif Door1Tween then
Door1Tween.Completed:Wait()
Attributes.Relay.Open.Value = opening ~= nil and opening or false
end
Attributes.Relay.Open.Value = opening ~= nil and opening
self.ElevatorDoor1.CanCollide = true
self.ElevatorDoor2.CanCollide = true
if Doors.__DontLeakMemory and Doors.__DontLeakMemory.Connected then
Doors.__DontLeakMemory:Disconnect()
if Doors.__DoorSensors and Doors.__DoorSensors.Connected then
Doors.__DoorSensors:Disconnect()
end
end

View File

@@ -77,7 +77,7 @@ function Relay:__Ready()
if self.ElevatorAttributes.Relay.Ready.Value then
self.BoxAlignPosition.Position = Vector3.new(
self.ElevatorBox.Position.X,
self.LevelingModule.Leveling[self.RelayAlgorthm.__FloorQueue[1]],
self.ElevatorAttributes.Relay.GoalYLevel.Value,
self.ElevatorBox.Position.Z
)
end

View File

@@ -172,8 +172,9 @@ Elevator.Attributes.CurrentFloor.Value = 1
Elevator.Attributes.Moving.Value = false
Elevator.Attributes.GoingUp.Value = false
Elevator.Attributes.Relay.Goal.Value = 1
Elevator.Attributes.Relay.Ready.Value = false
Elevator.Attributes.Relay.Goal.Value = 1
Elevator.Attributes.Relay.GoalYLevel.Value = LevelingModule.Leveling[Elevator.Attributes.CurrentFloor.Value]
Elevator.Attributes.Relay.Ready.Value = false
local Attributes = Elevator.Attributes
@@ -183,16 +184,6 @@ local function ElevatorGoingUpDirection(Floor: number, RequestedFloor: number):
return -Floor+RequestedFloor>0 --Simplified equation for less computation
end
local function OpenElevatorDoorsSafe(self: ClassConstructor)
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.Ready=",Attributes.Relay.Ready.Value)
if not Doors.Attributes.Relay.Open.Value and not Attributes.Relay.Ready.Value then
task.spawn(function()
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
end)
end
end
local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number, ButtonTree: Tags.ButtonPropertiesSafe)
ButtonTree.Prompt.Enabled = false
local Some = self:RequestLevel(ButtonFloor)
@@ -204,10 +195,6 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Relay.Goal.Value == ButtonFloor then
FloorTracker:Disconnect()
--If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed,
--then open the doors
OpenElevatorDoorsSafe(self)
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
ButtonTree.Prompt.Enabled = true
end
@@ -218,15 +205,31 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
end
end
--If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed,
--then open the doors
local function OpenElevatorDoorsSafe(self: ClassConstructor)
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.Ready=",Attributes.Relay.Ready.Value)
if not Doors.Attributes.Relay.Open.Value and not Attributes.Relay.Ready.Value then
task.spawn(function()
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
end)
end
end
--Special cases inbound
local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonTreeValues, ButtonID: string, ButtonTree: Tags.ButtonPropertiesSafe)
if ButtonNameType == Enums.ButtonTree.Car then
self.ButtonsConstructor:CarButton(ButtonID, ButtonTree, function(ButtonFloor: number)
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
end, function(_ButtonFloor: number)
OpenElevatorDoorsSafe(self)
end)
elseif ButtonNameType == Enums.ButtonTree.Landing then
self.ButtonsConstructor:LandingButton(ButtonID, ButtonTree, function(ButtonFloor: number)
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
end, function(_ButtonFloor: number)
OpenElevatorDoorsSafe(self)
end)
elseif ButtonNameType == Enums.ButtonTree.Special then
if Elevator.Name == Enums.Elevator.Otis1960 then
@@ -250,7 +253,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
self.LanternsConstructor:Reset()
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value), LevelingModule.Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value), Attributes.Relay.GoalYLevel.Value)
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
end
end)
@@ -284,10 +287,8 @@ local function ElevatorInit(self: ClassConstructor)
--Open the elevator doors on server start
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
--Some hacks
Doors.Attributes.Relay.Open.Value = true
self:RequestLevel(1)
end)
end
@@ -333,7 +334,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.BoxAlignPosition,
self.BoxAlignOrientation = ElevatorMover(
self.ElevatorBox_1960,
Vector3.new(self.ElevatorBox_1960.Position.X, LevelingModule.Leveling[1], self.ElevatorBox_1960.Position.Z),
Vector3.new(self.ElevatorBox_1960.Position.X, Elevator.Attributes.Relay.GoalYLevel.Value, self.ElevatorBox_1960.Position.Z),
Elevator.Responsiveness,
Elevator.MaxVelocity
)
@@ -364,8 +365,8 @@ function Elevator:Leveled(RequestedLevel)
Attributes.Moving.Value = false
Attributes.CurrentFloor.Value = RequestedLevel
self.BoxAlignPosition.MaxVelocity = 0
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
task.wait(Elevator.QueueWaitTime)
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
@@ -393,7 +394,9 @@ function Elevator:FloorPassingUp(ElevatorPositionY, RequestedLevel)
end
function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
if ElevatorPositionY<=LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value-1] then
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value-1]
if NextLevelBetweenFloors and ElevatorPositionY<=NextLevelBetweenFloors then
Attributes.CurrentFloor.Value-=1
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
@@ -411,14 +414,14 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
self.MOConstructor:UpdateCFrame()
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
local Delta = 0
local DoorsOpeningEvent = false
local Delta = 0
local DoorsOpeningDebounce = false
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt)
Delta+=1
local FloorGoal: number = self.RelayAlgorithmConstructor.__FloorQueue[1]
Attributes.Moving.Value = true
Attributes.Moving.Value = true
Attributes.Relay.Goal.Value = FloorGoal
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
@@ -430,14 +433,14 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
--Kill the connection
if GoingUp then
if Attributes.GoingUp.Value then
self:FloorPassingUp(ElevatorPositionY, FloorGoal)
if ElevatorPositionY>=BoxAlignY-Elevator.FloorLevelingDistance then
self:Leveling(FloorGoal)
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
DoorsOpeningEvent = true
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
DoorsOpeningDebounce = true
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, FloorGoal)
end
end
@@ -451,8 +454,8 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
if ElevatorPositionY<=BoxAlignY+Elevator.FloorLevelingDistance then
self:Leveling(FloorGoal)
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
DoorsOpeningEvent = true
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
DoorsOpeningDebounce = true
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, FloorGoal)
end
end
@@ -480,18 +483,18 @@ end
function Elevator:RequestLevel(RequestedLevel)
local GoalFloor_Y: number? = LevelingModule.Leveling[RequestedLevel]
if GoalFloor_Y --[[and RequestedLevel ~= Attributes.CurrentFloor.Value]] then
if GoalFloor_Y and RequestedLevel ~= Attributes.CurrentFloor.Value then
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
if Proceeding then
self:__MoveTo(ElevatorGoingUp, GoalFloor_Y)
end
return true
else
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
return false
end
return true
return false
end
return Elevator