mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
relay system
This commit is contained in:
@@ -23,9 +23,8 @@ type Constructor_Return_Props = {
|
|||||||
|
|
||||||
type ElevatorAttributes = {
|
type ElevatorAttributes = {
|
||||||
CurrentFloor: IntValue,
|
CurrentFloor: IntValue,
|
||||||
Goal: IntValue,
|
|
||||||
GoingUp: BoolValue,
|
GoingUp: BoolValue,
|
||||||
Moving: BoolValue
|
Moving: BoolValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
type DoorAttributes = {
|
type DoorAttributes = {
|
||||||
@@ -77,17 +76,9 @@ function RelayAlgorithm:RawInsert(ElevatorGoingUp, RequestedLevel)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||||
if self.ElevatorAttributes.Moving.Value then
|
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
|
||||||
else
|
return not self.ElevatorAttributes.Moving.Value and self.DoorAttributes.Open.Value
|
||||||
if self.DoorAttributes.Open.Value then
|
|
||||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return RelayAlgorithm
|
return RelayAlgorithm
|
||||||
@@ -83,12 +83,15 @@ type Impl_Static_Props = {
|
|||||||
},
|
},
|
||||||
Attributes: {
|
Attributes: {
|
||||||
CurrentFloor: IntValue,
|
CurrentFloor: IntValue,
|
||||||
Goal: IntValue,
|
|
||||||
GoalYLevel: NumberValue,
|
|
||||||
Ready: BoolValue,
|
|
||||||
Moving: BoolValue,
|
Moving: BoolValue,
|
||||||
GoingUp: BoolValue,
|
GoingUp: BoolValue,
|
||||||
Stopped: BoolValue
|
Stopped: BoolValue,
|
||||||
|
|
||||||
|
Relay: {
|
||||||
|
Goal: IntValue,
|
||||||
|
GoalYLevel: NumberValue,
|
||||||
|
Ready: BoolValue,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Events: {
|
Events: {
|
||||||
ButtonActivated: BindableEvent
|
ButtonActivated: BindableEvent
|
||||||
@@ -147,13 +150,16 @@ Elevator.Colors = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Elevator.Attributes = {
|
Elevator.Attributes = {
|
||||||
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
||||||
Goal = Instance.new("IntValue") :: IntValue,
|
Moving = Instance.new("BoolValue") :: BoolValue,
|
||||||
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
|
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
||||||
Ready = Instance.new("BoolValue") :: BoolValue,
|
Stopped = Instance.new("BoolValue") :: BoolValue,
|
||||||
Moving = Instance.new("BoolValue") :: BoolValue,
|
|
||||||
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
Relay = {
|
||||||
Stopped = Instance.new("BoolValue") :: BoolValue
|
Ready = Instance.new("BoolValue") :: BoolValue,
|
||||||
|
Goal = Instance.new("IntValue") :: IntValue,
|
||||||
|
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Elevator.Events = {
|
Elevator.Events = {
|
||||||
@@ -161,11 +167,12 @@ Elevator.Events = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Elevator.Attributes.CurrentFloor.Value = 1
|
Elevator.Attributes.CurrentFloor.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
|
||||||
|
|
||||||
|
Elevator.Attributes.Relay.Goal.Value = 1
|
||||||
|
Elevator.Attributes.Relay.Ready.Value = false
|
||||||
|
|
||||||
local Attributes = Elevator.Attributes
|
local Attributes = Elevator.Attributes
|
||||||
|
|
||||||
--My clever math function for determining if the elevator goal is to move upwards or not
|
--My clever math function for determining if the elevator goal is to move upwards or not
|
||||||
@@ -181,7 +188,7 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
|
|||||||
local FloorTracker: RBXScriptConnection
|
local FloorTracker: RBXScriptConnection
|
||||||
|
|
||||||
FloorTracker = Attributes.CurrentFloor:GetPropertyChangedSignal("Value"):Connect(function()
|
FloorTracker = Attributes.CurrentFloor:GetPropertyChangedSignal("Value"):Connect(function()
|
||||||
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Goal.Value == ButtonFloor then
|
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Relay.Goal.Value == ButtonFloor then
|
||||||
FloorTracker:Disconnect()
|
FloorTracker:Disconnect()
|
||||||
|
|
||||||
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
|
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
|
||||||
@@ -226,7 +233,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:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Goal.Value), Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
|
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value), Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
|
||||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -261,6 +268,33 @@ local function IterateButtons(self: ClassConstructor, ButtonsTagsConstructor: Bu
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function ElevatorReactionEvents(self: ClassConstructor)
|
||||||
|
--This is how the elevator logic works with the elevator itself
|
||||||
|
Attributes.Relay.Ready:GetPropertyChangedSignal("Value"):Connect(function()
|
||||||
|
if not Attributes.Stopped.Value and Attributes.Relay.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()
|
||||||
|
if not Attributes.Stopped.Value then
|
||||||
|
Attributes.Relay.Ready.Value = Doors.Attributes.Open.Value
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Attributes.Relay.GoalYLevel:GetPropertyChangedSignal("Value"):Connect(function()
|
||||||
|
if not Attributes.Stopped.Value then
|
||||||
|
self.BoxAlignPosition.Position = Vector3.new(self.ElevatorBox_1960.Position.X, Attributes.Relay.GoalYLevel.Value, self.ElevatorBox_1960.Position.Z)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Attributes.Relay.Goal:GetPropertyChangedSignal("Value"):Connect(function()
|
||||||
|
if not Attributes.Stopped.Value then
|
||||||
|
local Level: number? = Leveling[Attributes.Relay.Goal.Value]
|
||||||
|
|
||||||
|
Attributes.Relay.GoalYLevel.Value = Level or Leveling[1]
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
|
function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
|
||||||
local self = {} :: Constructor_Return_Props
|
local self = {} :: Constructor_Return_Props
|
||||||
|
|
||||||
@@ -313,18 +347,12 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
|||||||
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
|
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
|
||||||
self.HallDisplaysConstructor:SetHallDisplays(Attributes.CurrentFloor.Value)
|
self.HallDisplaysConstructor:SetHallDisplays(Attributes.CurrentFloor.Value)
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
||||||
|
|
||||||
|
--Some hacks
|
||||||
|
Doors.Attributes.Open.Value = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--This is how the elevator logic works with the elevator itself
|
ElevatorReactionEvents(self)
|
||||||
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
|
||||||
@@ -386,7 +414,7 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
|
|||||||
local FloorGoal: number = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
local FloorGoal: number = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
||||||
|
|
||||||
Attributes.Moving.Value = true
|
Attributes.Moving.Value = true
|
||||||
Attributes.Goal.Value = FloorGoal
|
Attributes.Relay.Goal.Value = FloorGoal
|
||||||
|
|
||||||
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
||||||
local ElevatorPositionY: number = ElevatorPosition.Y
|
local ElevatorPositionY: number = ElevatorPosition.Y
|
||||||
@@ -451,7 +479,7 @@ function Elevator:RequestLevel(RequestedLevel)
|
|||||||
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 Doors.Attributes.Open.Value then
|
if Proceeding then
|
||||||
self:__MoveTo(ElevatorGoingUp, GoalFloor_Y)
|
self:__MoveTo(ElevatorGoingUp, GoalFloor_Y)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user