Complete more of the rewrite and restructure

This commit is contained in:
2024-07-20 23:42:52 -04:00
parent 1c026f4a52
commit aa2b5a9c2c
8 changed files with 54 additions and 641 deletions

View File

@@ -123,12 +123,12 @@ local function Mover(ElevatorBoxModel: UnionOperation, Responsiveness: number, M
end end
function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions) function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions)
print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`)
local _BoxAttachment, local _BoxAttachment,
BoxAlignPosition, BoxAlignPosition,
_BoxAlignOrientation = Mover(ElevatorBoxModel, ElevatorConfigurationTable.Responsiveness, ElevatorConfigurationTable.MaxVelocity) _BoxAlignOrientation = Mover(ElevatorBoxModel, ElevatorConfigurationTable.Responsiveness, ElevatorConfigurationTable.MaxVelocity)
local RelayAlgorithmConstructor = RelayAlgorithm.constructor(BoxAlignPosition)
local Events = { local Events = {
CabProgression = Instance.new("BindableEvent") :: BindableEvent, CabProgression = Instance.new("BindableEvent") :: BindableEvent,
CabTraveling = Instance.new("BindableEvent") :: BindableEvent, CabTraveling = Instance.new("BindableEvent") :: BindableEvent,
@@ -150,10 +150,11 @@ function Elevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, Floo
Attributes.GoingUp.Value = false Attributes.GoingUp.Value = false
Attributes.Goal.Value = 1 Attributes.Goal.Value = 1
return setmetatable({ print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`)
RelayAlgorithm = RelayAlgorithm.constructor(BoxAlignPosition),
FloorLevelingPositions = FloorLevelingPositions,
return setmetatable({
RelayAlgorithm = RelayAlgorithmConstructor,
FloorLevelingPositions = FloorLevelingPositions,
Elevator = { Elevator = {
BoxModel = ElevatorBoxModel, BoxModel = ElevatorBoxModel,
AlignPosition = BoxAlignPosition, AlignPosition = BoxAlignPosition,

View File

@@ -1,29 +0,0 @@
--!optimize 2
--!native
--!strict
return function(ElevatorBox: BasePart, StartPosition: Vector3, Responsiveness: number, MaxVelocity: number): (Attachment, AlignPosition, AlignOrientation)
local BoxAttachment = Instance.new("Attachment")
BoxAttachment.Parent = ElevatorBox
local BoxAlignPosition = Instance.new("AlignPosition")
BoxAlignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
BoxAlignPosition.Attachment0 = BoxAttachment
BoxAlignPosition.MaxForce = math.huge
BoxAlignPosition.Position = StartPosition
-- BoxAlignPosition.RigidityEnabled = true
-- Lines below are disabled with RigidityEnabled true
BoxAlignPosition.Responsiveness = Responsiveness
BoxAlignPosition.MaxVelocity = MaxVelocity
--
BoxAlignPosition.Parent = ElevatorBox
local BoxAlignOrientation = Instance.new("AlignOrientation")
BoxAlignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
BoxAlignOrientation.Attachment0 = BoxAttachment
BoxAlignOrientation.RigidityEnabled = true
BoxAlignOrientation.CFrame = CFrame.new(0,0,0)*CFrame.fromOrientation(0,0,0)
BoxAlignOrientation.Parent = ElevatorBox
return BoxAttachment, BoxAlignPosition, BoxAlignOrientation
end

View File

@@ -0,0 +1,33 @@
--!optimize 2
--!native
--!strict
local MainDir = script.Parent.Parent.Parent
local StorageService = game:GetService("ReplicatedStorage")
local Enums = require(StorageService:WaitForChild("Enums"))
local SoundEnums = require(MainDir:WaitForChild("Enums"):WaitForChild("Sounds"))
local ElevatorConfiguration = {}
ElevatorConfiguration.Name = Enums.Elevator.Otis1960
ElevatorConfiguration.FloorLevelingDistance = 4
ElevatorConfiguration.FloorLeveling3PhaseDistance = 1.5
ElevatorConfiguration.ParkedDistance = 0.2
ElevatorConfiguration.Responsiveness = 20
ElevatorConfiguration.MaxVelocity = 7
ElevatorConfiguration.LevelingVelocity = 2
ElevatorConfiguration.Phase3LevelingVelocity = .5
ElevatorConfiguration.Sounds = {
LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection,
LanternChimeLanding = SoundEnums.Otis1960.LanternChimeLanding
}
ElevatorConfiguration.Colors = {
ButtonActivated = Color3.fromRGB(180,0,0),
ButtonDeactivated = Color3.fromRGB(139,139,139),
LanternDisplayOn = Color3.fromRGB(255,114,71),
LanternDisplayOff = Color3.fromRGB(55,55,55),
}
return ElevatorConfiguration

View File

@@ -15,6 +15,4 @@ local Leveling: {number} = {
[10] = 239.245, [10] = 239.245,
} }
return { return Leveling
Leveling = Leveling
}

View File

@@ -1,233 +0,0 @@
--!optimize 2
--!native
--!strict
local Dir = script.Parent
local ElevatorsDir = Dir.Parent
local Lanterns = require(ElevatorsDir:WaitForChild("Lanterns"))
local TractionRopes = require(ElevatorsDir:WaitForChild("TractionRopes"))
local MovingObjects = require(Dir:WaitForChild("MovingObjects"))
local LevelingModule = require(Dir:WaitForChild("Leveling"))
local PhysicalRelays = require(Dir:WaitForChild("PhysicalRelay"))
local RelayAlgorithm = require(Dir:WaitForChild("RelayAlgorithm"))
local ElevatorDoors = require(Dir:WaitForChild("Doors"))
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
Start: (self: ClassConstructor, GoingUp: boolean, RequestedLevel: number, ElevatorBox_1960: BasePart, BoxAlignPosition: AlignPosition) -> (),
}
type Constructor_Fun = (
ElevatorAttributes: ElevatorAttributes,
LanternsConstructor: Lanterns.LanternsConstructor,
TractionRopesConstructor: TractionRopes.TractionRopesConstructor,
MovingObjectsConstructor: MovingObjects.MovingObjectsConstructor,
PhysicalRelaysConstructor: PhysicalRelays.PhysicalRelayConstructor,
RelayAlgorithmConstructor: RelayAlgorithm.RelayAlgorithmConstructor,
ElevatorDoorsConstructor: ElevatorDoors.DoorConstructor
) -> ClassConstructor
type Constructor_Return_Props = {
LanternsConstructor: Lanterns.LanternsConstructor,
ElevatorAttributes: ElevatorAttributes,
TractionRopesConstructor: TractionRopes.TractionRopesConstructor,
MovingObjectsConstructor: MovingObjects.MovingObjectsConstructor,
PhysicalRelaysConstructor: PhysicalRelays.PhysicalRelayConstructor,
RelayAlgorithmConstructor: RelayAlgorithm.RelayAlgorithmConstructor,
__Connections: {
Moving: RBXScriptConnection?
}
}
type ElevatorAttributes = {
CurrentFloor: IntValue,
Moving: BoolValue,
GoingUp: BoolValue,
FloorLevelingDistance: number,
LeveledDistance: number,
DoorOpeningDistance: number,
FloorLeveling3PhaseDistance: number,
QueueWaitTime: number,
Relay: {
Goal: IntValue,
ReadyForMoving: BoolValue
}
}
export type MovingConstructor = ClassConstructor
local Moving = {} :: Impl_Constructor
Moving.__index = Moving
local RS = game:GetService("RunService")
local DoorsOpeningDebounce = false
function Moving.constructor(
ElevatorAttributes,
LanternsConstructor,
TractionRopesConstructor,
MovingObjectsConstructor,
PhysicalRelaysConstructor,
RelayAlgorithmConstructor,
ElevatorDoorsConstructor
)
return setmetatable({
ElevatorAttributes = ElevatorAttributes,
LanternsConstructor = LanternsConstructor,
TractionRopesConstructor = TractionRopesConstructor,
MovingObjectsConstructor = MovingObjectsConstructor,
PhysicalRelaysConstructor = PhysicalRelaysConstructor,
RelayAlgorithmConstructor = RelayAlgorithmConstructor,
ElevatorDoorsConstructor = ElevatorDoorsConstructor,
__Connections = {}
}, Moving)
end
local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean
return CurrentFloor<RequestedFloor
end
local function Leveled(self: ClassConstructor, RequestedLevel: number)
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
self.ElevatorAttributes.Moving.Value = false
self.ElevatorAttributes.CurrentFloor.Value = RequestedLevel
--self.BoxAlignPosition.MaxVelocity = 0
self.LanternsConstructor:Reset(self.ElevatorAttributes.CurrentFloor.Value)
self.PhysicalRelaysConstructor:SetState("UP", false, false)
self.PhysicalRelaysConstructor:SetState("DOWN", false, false)
self.PhysicalRelaysConstructor:SetState("440 V", false, false)
self.PhysicalRelaysConstructor:SetState("240 V", false, false)
task.wait(self.ElevatorAttributes.QueueWaitTime)
local ElevatorGoingUp = ElevatorGoingUpDirection(self.ElevatorAttributes.CurrentFloor.Value, self.ElevatorAttributes.Relay.Goal.Value)
local NextLevel = self.RelayAlgorithmConstructor:Check(ElevatorGoingUp)
if NextLevel then
else
--The elevator is at a full park now
self.ElevatorAttributes.Relay.ReadyForMoving.Value = false
end
end
local function Leveling(self: ClassConstructor, RequestedLevel: number)
self.PhysicalRelaysConstructor:SetState("440 V", false, true)
self.BoxAlignPosition.MaxVelocity = 1
self.LanternsConstructor:Toggle(true, RequestedLevel)
end
local function Leveling3Phase(self: ClassConstructor, RequestedLevel: number)
self.BoxAlignPosition.MaxVelocity = .4
end
local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[self.ElevatorAttributes.CurrentFloor.Value+1]
if NextLevelBetweenFloors and ElevatorPositionY>=NextLevelBetweenFloors then
self.ElevatorAttributes.CurrentFloor.Value+=1
self.LanternsConstructor:Toggle(true, self.ElevatorAttributes.CurrentFloor.Value)
self.LanternsConstructor:Toggle(false, self.ElevatorAttributes.CurrentFloor.Value-1)
end
end
local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[self.ElevatorAttributes.CurrentFloor.Value-1]
if NextLevelBetweenFloors and ElevatorPositionY<=NextLevelBetweenFloors then
self.ElevatorAttributes.CurrentFloor.Value-=1
self.LanternsConstructor:Toggle(true, self.ElevatorAttributes.CurrentFloor.Value)
self.LanternsConstructor:Toggle(false, self.ElevatorAttributes.CurrentFloor.Value+1)
end
end
local function UpDirection(self: ClassConstructor, ElevatorPositionY: number, BoxAlignY: number, RequestedLevel: number)
FloorPassingUp(self, ElevatorPositionY, self.ElevatorAttributes.Relay.Goal.Value)
if ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.FloorLevelingDistance then
Leveling(self, self.ElevatorAttributes.Relay.Goal.Value)
if ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.FloorLeveling3PhaseDistance then
Leveling3Phase(self, RequestedLevel)
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.DoorOpeningDistance then
DoorsOpeningDebounce = true
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, self.ElevatorAttributes.Relay.Goal.Value)
end
end
end
if ElevatorPositionY>=BoxAlignY-self.ElevatorAttributes.LeveledDistance then
Leveled(self, self.ElevatorAttributes.Relay.Goal.Value)
end
end
local function DownDirection(self: ClassConstructor, ElevatorPositionY: number, BoxAlignY: number, RequestedLevel: number)
FloorPassingDown(self, ElevatorPositionY, self.ElevatorAttributes.Relay.Goal.Value)
if ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.FloorLevelingDistance then
Leveling(self, self.ElevatorAttributes.Relay.Goal.Value)
if ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.FloorLeveling3PhaseDistance then
Leveling3Phase(self, RequestedLevel)
if not DoorsOpeningDebounce and ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.DoorOpeningDistance then
DoorsOpeningDebounce = true
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, self.ElevatorAttributes.Relay.Goal.Value)
end
end
end
if ElevatorPositionY<=BoxAlignY+self.ElevatorAttributes.LeveledDistance then
Leveled(self, self.ElevatorAttributes.Relay.Goal.Value)
end
end
function Moving:Start(GoingUp, RequestedLevel, ElevatorBox_1960, BoxAlignPosition)
local MovingDelta = 0
self.ElevatorAttributes.GoingUp.Value = GoingUp
self.ElevatorAttributes.Relay.Goal.Value = RequestedLevel
self.ElevatorAttributes.Moving.Value = true
self.PhysicalRelaysConstructor:SetState(GoingUp and "UP" or "DOWN", true, false)
self.PhysicalRelaysConstructor:SetState("240 V", true, false)
self.PhysicalRelaysConstructor:SetState("440 V", true, false)
self.MovingObjectsConstructor:UpdateCFrame()
if self.__Connections.Moving and self.__Connections.Moving.Connected then
self.__Connections.Moving:Disconnect()
end
self.__Connections.Moving = RS.Heartbeat:Connect(function(_)
MovingDelta+=1
local ElevatorPosition = ElevatorBox_1960.Position
local ElevatorPositionY = ElevatorPosition.Y
local ElevatorVelocityY = ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
local BoxAlignY = BoxAlignPosition.Position.Y
self.TractionRopesConstructor:Move(27, ElevatorPosition)
self.MovingObjectsConstructor:FramePullies(MovingDelta, ElevatorVelocityY)
if self.ElevatorAttributes.GoingUp.Value then
UpDirection(self, ElevatorPositionY, BoxAlignY, RequestedLevel)
else
DownDirection(self, ElevatorPositionY, BoxAlignY, RequestedLevel)
end
end)
end
return Moving

View File

@@ -1,115 +0,0 @@
--!optimize 2
--!native
--!strict
local ElevatorDir = script.Parent
local RelayAlgorithmModule = require(ElevatorDir:WaitForChild("RelayAlgorithm"))
local DoorsModule = require(ElevatorDir:WaitForChild("Doors"))
local PhysicalRelay = require(ElevatorDir:WaitForChild("PhysicalRelay"))
type Leveling = {
Leveling: {number},
LevelingBetween: {number}
}
type ElevatorBox = BasePart
type BoxAlignPosition = AlignPosition
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
BulkConnect: (self: ClassConstructor) -> (),
BulkDisconnect: (self: ClassConstructor) -> (),
__Open: (self: ClassConstructor) -> (),
__Goal: (self: ClassConstructor) -> (),
}
type Constructor_Fun = (
PhysicalRelay: PhysicalRelay.PhysicalRelayConstructor,
RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor,
ElevatorAttributes: ElevatorAttributes,
DoorAttributes: DoorAttributes,
Leveling: Leveling,
BoxAlignPosition: BoxAlignPosition,
ElevatorBox: ElevatorBox
) -> ClassConstructor
type Constructor_Return_Props = {
PhysicalRelay: PhysicalRelay.PhysicalRelayConstructor,
RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor,
ElevatorAttributes: ElevatorAttributes,
DoorAttributes: DoorAttributes,
LevelingModule: Leveling,
BoxAlignPosition: BoxAlignPosition,
ElevatorBox: ElevatorBox,
__Connections: {
ReadyForMoving: RBXScriptConnection?,
Open: RBXScriptConnection?,
Goal: RBXScriptConnection?
}
}
type ElevatorAttributes = {
Relay: {
ReadyForMoving: BoolValue,
Goal: IntValue
},
Stopped: BoolValue
}
type DoorAttributes = DoorsModule.RelayAttributes
export type RelayConstructor = ClassConstructor
local Relay = {} :: Impl_Constructor
Relay.__index = Relay
function Relay.constructor(PhysicalRelay, RelayAlgorthm, ElevatorAttributes, DoorAttributes, LevelingModule, BoxAlignPosition, ElevatorBox)
return setmetatable({
PhysicalRelay = PhysicalRelay,
RelayAlgorthm = RelayAlgorthm,
ElevatorAttributes = ElevatorAttributes,
DoorAttributes = DoorAttributes,
LevelingModule = LevelingModule,
BoxAlignPosition = BoxAlignPosition,
ElevatorBox = ElevatorBox,
__Connections = {}
}, Relay)
end
function Relay:__Open()
self.ElevatorAttributes.Relay.ReadyForMoving.Value = not self.DoorAttributes.Relay.Open.Value
end
function Relay:BulkConnect()
local ReadyForMovingRelay = self.ElevatorAttributes.Relay.ReadyForMoving
local OpenRelay = self.DoorAttributes.Relay.Open
self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function()
self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value, false)
end)
self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function()
self.PhysicalRelay:SetState("DO", OpenRelay.Value, true)
if not self.ElevatorAttributes.Stopped.Value then
self:__Open()
end
end)
end
function Relay:BulkDisconnect()
if self.__Connections.ReadyForMoving and self.__Connections.ReadyForMoving.Connected then
self.__Connections.ReadyForMoving:Disconnect()
end
if self.__Connections.Open and self.__Connections.Open.Connected then
self.__Connections.Open:Disconnect()
end
end
return Relay

View File

@@ -2,246 +2,19 @@
--!native --!native
--!strict --!strict
--Set relay tags through studio command line local ParentDir = script.Parent
--[[ local MainDir = ParentDir.Parent
local s = game.Selection:Get()[1]
for i,v in s:GetChildren() do
if v:IsA("Model") then
local main = v:FindFirstChild("main")
if main then
local label = v:FindFirstChildWhichIsA("TextLabel", true)
if label then
main:AddTag(`Otis1960_RelayButton_{label.Text}`)
end
end
end
end
]]
local Elevators = script.Parent
local MainDir = Elevators.Parent
local EnumsDir = MainDir:WaitForChild("Enums")
local LoadDir = MainDir:WaitForChild("Load")
local StorageService = game:GetService("ReplicatedStorage") local StorageService = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local InitElevator = require(ParentDir:WaitForChild("InitElevator"))
local TagsModule = require(MainDir:WaitForChild("Load"):WaitForChild("Tags"))
local SoundEnums = require(MainDir:WaitForChild("Enums"):WaitForChild("Sounds"))
local Enums = require(StorageService:WaitForChild("Enums")) local Enums = require(StorageService:WaitForChild("Enums"))
local SoundEnums = require(EnumsDir:WaitForChild("Sounds"))
local LevelingModule = require(script:WaitForChild("Leveling")) local ElevatorConfigurationTable = require(script:WaitForChild("Config"))
local FloorLevelingPositions = require(script:WaitForChild("Leveling"))
local Tags = require(LoadDir:WaitForChild("Tags")) return function(ButtonTags: TagsModule.ElevatorButtons, LanternTags: TagsModule.Lanterns, LandingDoorTags: TagsModule.LandingTags)
local Elevator = InitElevator.constructor(ElevatorBoxModel, ElevatorConfigurationTable, FloorLevelingPositions)
type Tags = Tags.ExportedTags
type TagsConstructor = Tags.TagsConstructor
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
__TravelToFloor: (self: ClassConstructor, LevelInt: number, LevelVec3: number, ElevatorGoingUp: boolean) -> (),
} & Impl_Static_Props
type ElevatorConfigurationTable = {
Name: Enums.ElevatorValues,
Responsiveness: number,
MaxVelocity: number,
FloorLevelingDistance: number,
FloorLeveling3PhaseDistance: number,
ParkedDistance: number,
LevelingVelocity: number,
Phase3LevelingVelocity: number,
Sounds: {
LanternChimeDirection: SoundEnums.ElevatorSoundValues,
LanternChimeLanding: SoundEnums.ElevatorSoundValues,
},
Colors: {
ButtonActivated: Color3,
ButtonDeactivated: Color3,
LanternDisplayOn: Color3,
LanternDisplayOff: Color3,
},
}
type Impl_Static_Props = {}
type Constructor_Fun = (ElevatorConfigurationTable: ElevatorConfigurationTable) -> ClassConstructor
type Constructor_Return_Props = {
ElevatorConfiguration: ElevatorConfigurationTable,
Attributes: {
PreviousFloor: IntValue,
CurrentFloor: IntValue,
NextFloor: IntValue,
Moving: BoolValue,
GoingUp: BoolValue,
Stopped: BoolValue,
Goal: IntValue
},
Events: {
CabProgression: BindableEvent,
CabTraveling: BindableEvent,
Parked: BindableEvent,
Leveling: BindableEvent,
Leveling3Phase: BindableEvent,
},
__Connections: {
Moving: RBXScriptConnection?,
}
}
local Elevator = {} :: Impl_Constructor
Elevator.__index = Elevator
local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean
-- -(CurrentFloor-RequestedFloor)>0
-- -CurrentFloor+RequestedFloor>0
return CurrentFloor<RequestedFloor
end end
function Elevator.constructor(ElevatorConfigurationTable: ElevatorConfigurationTable)
print(`🛗 [{ElevatorConfigurationTable.Name}]: Initialized and ready`)
return setmetatable({
ElevatorConfiguration = ElevatorConfigurationTable,
Attributes = {
PreviousFloor = Instance.new("IntValue") :: IntValue,
CurrentFloor = Instance.new("IntValue") :: IntValue,
NextFloor = Instance.new("IntValue") :: IntValue,
Moving = Instance.new("BoolValue") :: BoolValue,
GoingUp = Instance.new("BoolValue") :: BoolValue,
Stopped = Instance.new("BoolValue") :: BoolValue,
Goal = Instance.new("IntValue") :: IntValue
},
Events = {
CabProgression = Instance.new("BindableEvent") :: BindableEvent,
CabTraveling = Instance.new("BindableEvent") :: BindableEvent,
Parked = Instance.new("BindableEvent") :: BindableEvent,
Leveling = Instance.new("BindableEvent") :: BindableEvent,
Leveling3Phase = Instance.new("BindableEvent") :: BindableEvent,
},
__Connections = {}
}, Elevator)
end
local function CheckFloorQueue(self: ClassConstructor)
if self.RelayAlgorithmConstructor.__FloorQueue[1] ~= self.Attributes.CurrentFloor.Value then
warn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", self.Attributes.CurrentFloor.Value, "FloorQueue[1]=", self.RelayAlgorithmConstructor.__FloorQueue[1])
end
table.remove(self.RelayAlgorithmConstructor.__FloorQueue, 1)
local NextFloorInQueue = self.RelayAlgorithmConstructor.__FloorQueue[1]
if NextFloorInQueue then
local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, NextFloorInQueue)
local LevelVec3 = LevelingModule.Leveling[NextFloorInQueue]
self:__TravelToFloor(NextFloorInQueue, LevelVec3, ElevatorGoingUp)
end
end
local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3: number, ElevatorGoingUp: boolean)
local ElevatorPosition = self.ElevatorBox_1960.Position
local AtFloorY = LevelingModule.Leveling[ElevatorGoingUp and self.Attributes.CurrentFloor.Value+1 or self.Attributes.CurrentFloor.Value-1]
if ElevatorGoingUp then
--Detecting between the floors
if ElevatorPosition.Y>=AtFloorY-self.ElevatorConfiguration.FloorLevelingDistance then
self.Attributes.PreviousFloor.Value = self.Attributes.CurrentFloor.Value
self.Attributes.CurrentFloor.Value+=1
self.Attributes.NextFloor.Value = math.clamp(1, self.Attributes.CurrentFloor.Value+1, #LevelingModule.Leveling)
self.Events.CabProgression:Fire(self.Attributes.PreviousFloor.Value, self.Attributes.CurrentFloor.Value, self.Attributes.NextFloor.Value)
end
--Elevator is riding upwards towards the destination
if ElevatorPosition.Y>=LevelVec3-self.ElevatorConfiguration.FloorLevelingDistance then
self.Events.Leveling:Fire()
self.BoxAlignPosition.MaxVelocity = self.ElevatorConfiguration.LevelingVelocity
if ElevatorPosition.Y>=LevelVec3-self.ElevatorConfiguration.FloorLeveling3PhaseDistance then
self.Events.Leveling3Phase:Fire()
self.BoxAlignPosition.MaxVelocity = self.ElevatorConfiguration.Phase3LevelingVelocity
if ElevatorPosition.Y>=LevelVec3-self.ElevatorConfiguration.ParkedDistance then
self.Events.Parked:Fire()
CheckFloorQueue(self);
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
end
end
end
else
if ElevatorPosition.Y<=AtFloorY+self.ElevatorConfiguration.FloorLevelingDistance then
self.Attributes.PreviousFloor.Value = self.Attributes.CurrentFloor.Value
self.Attributes.CurrentFloor.Value-=1
self.Attributes.NextFloor.Value = math.clamp(1, self.Attributes.CurrentFloor.Value-1, #LevelingModule.Leveling)
self.Events.CabProgression:Fire(self.Attributes.PreviousFloor.Value, self.Attributes.CurrentFloor.Value, self.Attributes.NextFloor.Value)
end
--Elevator is riding upwards towards the destination
if ElevatorPosition.Y<=LevelVec3+self.ElevatorConfiguration.FloorLevelingDistance then
self.Events.Leveling:Fire()
self.BoxAlignPosition.MaxVelocity = self.ElevatorConfiguration.LevelingVelocity
if ElevatorPosition.Y<=LevelVec3+self.ElevatorConfiguration.FloorLeveling3PhaseDistance then
self.Events.Leveling3Phase:Fire()
self.BoxAlignPosition.MaxVelocity = self.ElevatorConfiguration.Phase3LevelingVelocity
if ElevatorPosition.Y<=LevelVec3+self.ElevatorConfiguration.ParkedDistance then
self.Events.Parked:Fire()
CheckFloorQueue(self);
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
end
end
end
end
self.Events.CabTraveling:Fire(deltaTime, ElevatorPosition)
end
function Elevator:__TravelToFloor(LevelInt, LevelVec3, ElevatorGoingUp)
if self.__Connections.Moving and self.__Connections.Moving.Connected then
self.__Connections.Moving:Disconnect()
end
self.Attributes.Goal.Value = LevelInt
self.Attributes.GoingUp.Value = ElevatorGoingUp
self.__Connections.Moving = RunService.Heartbeat:Connect(function(deltaTime)
CabTraveling(self, deltaTime, LevelVec3, ElevatorGoingUp)
end)
--Set the elevator's AlignPosition to the floor Y vector
self.BoxAlignPosition.Position = Vector3.new(self.BoxAlignPosition.Position.X, LevelVec3, self.BoxAlignPosition.Position.Z)
--Set the elevator's max velocity to its fastest speed when moving starts
self.BoxAlignPosition.MaxVelocity = self.ElevatorConfiguration.MaxVelocity
end
function Elevator:RequestLevel(RequestedLevel)
local LevelVec3 = LevelingModule.Leveling[RequestedLevel]
if LevelVec3 then
local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, RequestedLevel)
self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
if #self.RelayAlgorithmConstructor.__FloorQueue == 1 then
self:__TravelToFloor(RequestedLevel, LevelVec3, ElevatorGoingUp)
end
return true
end
warn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`)
return false
end
return Elevator

View File

@@ -18,9 +18,9 @@ local StarterPlayer_Stuff = require(Load:WaitForChild("StarterPlayer"))
local Elevators = script:WaitForChild("Elevators") local Elevators = script:WaitForChild("Elevators")
local Maps = script:WaitForChild("Map") local Maps = script:WaitForChild("Map")
local Interactions = Maps:WaitForChild("Interactions") local Interactions = Maps:WaitForChild("Interactions")
local LightSwitches = require(Interactions:WaitForChild("LightSwitches")) local LightSwitches = require(Interactions:WaitForChild("LightSwitches"))
local Otis1960_Module = require(Elevators:WaitForChild("Otis1960")) local Otis1960 = require(Elevators:WaitForChild("Otis1960"))
local Enums = require(Storage:WaitForChild("Enums")) local Enums = require(Storage:WaitForChild("Enums"))
@@ -50,19 +50,4 @@ print("[DEBUG] Lanterns=", Lanterns)
local LandingDoors = TagsConstructor:__ElevatorDoors() local LandingDoors = TagsConstructor:__ElevatorDoors()
print("[DEBUG] Elevator Landing Doors=", LandingDoors) print("[DEBUG] Elevator Landing Doors=", LandingDoors)
local Otis1960Lanterns= Lanterns[Enums.Elevator.Otis1960] Otis1960(Buttons[Enums.Elevator.Otis1960], Lanterns[Enums.Elevator.Otis1960], LandingDoors[Enums.Elevator.Otis1960])
local Otis1960Buttons = Buttons[Enums.Elevator.Otis1960]
local Otis1960LandingDoors = LandingDoors[Enums.Elevator.Otis1960]
local Otis1960 = Otis1960_Module.constructor(TagsConstructor, Otis1960Buttons, Otis1960Lanterns, Otis1960LandingDoors)
Otis1960_Module.Events.Parked.Event:Connect(function()
end)
Otis1960_Module.Events.CabProgression.Event:Connect(function(previousFloor: number, currentFloor: number, nextFloor: number)
print("previousFloor=",previousFloor, "currentFloor=",currentFloor, "nextFloor=",nextFloor)
end)
Otis1960_Module.Events.CabTraveling.Event:Connect(function(deltaTime: number, Elevator_Position: Vector3)
end)