Relay logic

This commit is contained in:
2024-05-24 01:39:47 -04:00
parent 7387e759c8
commit 61153b53e1
5 changed files with 186 additions and 59 deletions

View File

@@ -32,10 +32,11 @@ local ButtonTags = require(TagsDir:WaitForChild("Buttons"))
local Enums = require(Storage:WaitForChild("Enums"))
local SoundEnums = require(EnumsDir:WaitForChild("Sounds"))
local Leveling = require(script:WaitForChild("Leveling"))
local LevelingModule = require(script:WaitForChild("Leveling"))
local Doors = require(script:WaitForChild("Doors"))
local MovingObjects = require(script:WaitForChild("MovingObjects"))
local RelayAlgorithm = require(script:WaitForChild("RelayAlgorithm"))
local Relay = require(script:WaitForChild("Relay"))
local HallDisplays = require(Elevators:WaitForChild("HallDisplays"))
local ElevatorMover = require(Elevators:WaitForChild("Mover"))
@@ -123,6 +124,7 @@ type Constructor_Return_Props = {
HallDisplays: {Instance},
ButtonsConstructor: Buttons.ButtonsConstructor,
RelayAlgorithmConstructor: RelayAlgorithm.RelayAlgorithmConstructor,
RelayConstructor: Relay.RelayConstructor,
__MovingConnection: RBXScriptConnection?,
}
@@ -233,7 +235,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), Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value), LevelingModule.Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
end
end)
@@ -251,50 +253,15 @@ end
local function IterateButtons(self: ClassConstructor, ButtonsTagsConstructor: ButtonTags.ButtonsTagsConstructor)
for ButtonNameType, ButtonList in ButtonsTagsConstructor.Buttons do
for ButtonID, ButtonTree in ButtonList do
if ButtonTree.Prompt then
if ButtonTree.Inst then
if ButtonTree.Attachment then
HookButtons(self, ButtonNameType :: Enums.ButtonTreeValues, ButtonID, ButtonTree :: Tags.ButtonPropertiesSafe)
else
warn(`{ButtonTree} is missing the field "Attachment"`)
end
else
warn(`{ButtonTree} is missing the field "Inst"`)
end
if ButtonTree.Prompt and ButtonTree.Inst and ButtonTree.Attachment then
HookButtons(self, ButtonNameType :: Enums.ButtonTreeValues, ButtonID, ButtonTree :: Tags.ButtonPropertiesSafe)
else
warn(`{ButtonTree} is missing the field "Prompt"`)
warn(`{ButtonTree} is missing a field, {ButtonTree}`)
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)
local self = {} :: Constructor_Return_Props
@@ -322,7 +289,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
} :: MovingObjects.InstanceTree)
self.HallDisplaysConstructor = HallDisplays.constructor(Attributes.CurrentFloor, self.HallDisplays)
self.ElevatorDoorsConstructor = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
self.TractionRopesConstructor = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, Leveling)
self.TractionRopesConstructor = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, LevelingModule.Leveling)
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, LanternsTags, Elevator.Sounds, Elevator.Colors)
@@ -337,7 +304,10 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.BoxAlignPosition,
self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position, Elevator.Responsiveness, Elevator.MaxVelocity)
self.RelayAlgorithmConstructor = RelayAlgorithm.constructor(self.BoxAlignPosition, Attributes, Doors.Attributes)
self.RelayAlgorithmConstructor = RelayAlgorithm.constructor(self.BoxAlignPosition, Attributes, Doors.Attributes.Relay)
self.RelayConstructor = Relay.constructor(self.RelayAlgorithmConstructor, Attributes, Doors.Attributes, LevelingModule, self.BoxAlignPosition, self.ElevatorBox_1960)
self.RelayConstructor:BulkConnect()
local ClassConstructor = setmetatable(self, Elevator)
IterateButtons(ClassConstructor, ButtonsTagsConstructor)
@@ -349,10 +319,10 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
--Some hacks
Doors.Attributes.Open.Value = true
Doors.Attributes.Relay.Open.Value = true
end)
ElevatorReactionEvents(self)
print(LevelingModule.LevelingBetween)
print(`🔝 {Elevator.Name} initialized and ready`)
return ClassConstructor
@@ -371,7 +341,7 @@ function Elevator:Leveled(RequestedLevel)
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then
--More floors in the queue
self:__MoveTo(ElevatorGoingUp, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
self:__MoveTo(ElevatorGoingUp, LevelingModule.Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
end
end
@@ -381,7 +351,7 @@ function Elevator:Leveling(RequestedLevel)
end
function Elevator:FloorPassingUp(ElevatorPositionY, RequestedLevel)
if ElevatorPositionY>=Leveling[Attributes.CurrentFloor.Value+1] then
if ElevatorPositionY>=LevelingModule.Leveling[Attributes.CurrentFloor.Value+1] then
Attributes.CurrentFloor.Value+=1
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
@@ -390,7 +360,7 @@ function Elevator:FloorPassingUp(ElevatorPositionY, RequestedLevel)
end
function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
if ElevatorPositionY<=Leveling[Attributes.CurrentFloor.Value-1] then
if ElevatorPositionY<=LevelingModule.Leveling[Attributes.CurrentFloor.Value-1] then
Attributes.CurrentFloor.Value-=1
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
@@ -460,7 +430,7 @@ function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
end
function Elevator:__MoveTo(GoingUp, GoalFloor_Y)
if Doors.Attributes.Open.Value then
if Doors.Attributes.Relay.Open.Value then
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
end
if GoingUp then
@@ -473,7 +443,7 @@ function Elevator:__MoveTo(GoingUp, GoalFloor_Y)
end
function Elevator:RequestLevel(RequestedLevel)
local GoalFloor_Y: number? = Leveling[RequestedLevel]
local GoalFloor_Y: number? = LevelingModule.Leveling[RequestedLevel]
if GoalFloor_Y and RequestedLevel ~= Attributes.CurrentFloor.Value then
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)