Built with pure steam coming out of my brain, have to heal brain power after a long break of programming

This commit is contained in:
2024-07-20 16:10:05 -04:00
parent a56e5c7052
commit 96db25fcce
3 changed files with 65 additions and 85 deletions

View File

@@ -15,18 +15,6 @@ local Leveling: {number} = {
[10] = 239.245,
}
--Primarily used for the lanterns
local LevelingBetween: {number} = {}
--Calculate between leveling
for n: number = 1, #Leveling do
local FloorAhead: number? = Leveling[n+1]
if FloorAhead then
LevelingBetween[n] = (Leveling[n]+FloorAhead)/2
end
end
return {
Leveling = Leveling,
LevelingBetween = LevelingBetween
Leveling = Leveling
}

View File

@@ -81,7 +81,9 @@ type Impl_Static_Props = {
LanternDisplayOff: Color3,
},
Attributes: {
PreviousFloor: IntValue,
CurrentFloor: IntValue,
NextFloor: IntValue,
Moving: BoolValue,
GoingUp: BoolValue,
Stopped: BoolValue,
@@ -142,7 +144,7 @@ Elevator.Name = Enums.Elevator.Otis1960
Elevator.FloorLevelingDistance = 4
Elevator.FloorLeveling3PhaseDistance = 1.5
Elevator.ParkedDistance = 0.2
Elevator.Responsiveness = 10
Elevator.Responsiveness = 20
Elevator.MaxVelocity = 7
Elevator.LevelingVelocity = 2
Elevator.Phase3LevelingVelocity = .5
@@ -168,7 +170,9 @@ Elevator.Events = {
}
Elevator.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,
@@ -176,6 +180,7 @@ Elevator.Attributes = {
}
Elevator.Attributes.CurrentFloor.Value = 1
Elevator.Attributes.NextFloor.Value = Elevator.Attributes.CurrentFloor.Value+1
Elevator.Attributes.Moving.Value = false
Elevator.Attributes.GoingUp.Value = false
Elevator.Attributes.Goal.Value = 1
@@ -189,14 +194,6 @@ local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: nu
return CurrentFloor<RequestedFloor
end
local function elevatorwarn<T...>(...: T...)
warn("🛗 ["..Elevator.Name.."]:", ...)
end
local function elevatorprint<T...>(...: T...)
print("🛗 ["..Elevator.Name.."]:", ...)
end
function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
local self = {} :: Constructor_Return_Props
@@ -267,48 +264,49 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
local ClassConstructor = setmetatable(self, Elevator)
elevatorprint("Initialized and ready")
print(`🛗 [{Elevator.Name}]: Initialized and ready`)
return ClassConstructor
end
local function CheckFloorQueue(self: ClassConstructor)
if self.RelayAlgorithmConstructor.__FloorQueue[1] ~= Attributes.CurrentFloor.Value then
elevatorwarn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", Attributes.CurrentFloor.Value, "FloorQueue[1]=", self.RelayAlgorithmConstructor.__FloorQueue[1])
warn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", Attributes.CurrentFloor.Value, "FloorQueue[1]=", self.RelayAlgorithmConstructor.__FloorQueue[1])
end
table.remove(self.RelayAlgorithmConstructor.__FloorQueue, 1)
local NextFloor = self.RelayAlgorithmConstructor.__FloorQueue[1]
if NextFloor then
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, NextFloor)
local LevelVec3 = LevelingModule.Leveling[NextFloor]
local NextFloorInQueue = self.RelayAlgorithmConstructor.__FloorQueue[1]
if NextFloorInQueue then
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, NextFloorInQueue)
local LevelVec3 = LevelingModule.Leveling[NextFloorInQueue]
self:__TravelToFloor(NextFloor, LevelVec3, ElevatorGoingUp)
self:__TravelToFloor(NextFloorInQueue, LevelVec3, ElevatorGoingUp)
end
end
local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3: number, ElevatorGoingUp: boolean)
local Elevator_Position = self.ElevatorBox_1960.Position
local Between_Levels = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value]
local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelInt: number, LevelVec3: number, ElevatorGoingUp: boolean)
local ElevatorPosition = self.ElevatorBox_1960.Position
local AtFloorY = LevelingModule.Leveling[ElevatorGoingUp and Attributes.CurrentFloor.Value+1 or Attributes.CurrentFloor.Value-1]
if ElevatorGoingUp then
--Detecting between the floors
if Elevator_Position.Y>=Between_Levels then
local PreviousFloor = Attributes.CurrentFloor.Value
if ElevatorPosition.Y>=AtFloorY-Elevator.FloorLevelingDistance then
Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value
Attributes.CurrentFloor.Value+=1
Attributes.NextFloor.Value = math.clamp(1, Attributes.CurrentFloor.Value+1, #LevelingModule.Leveling)
Events.CabProgression:Fire(PreviousFloor, Attributes.CurrentFloor.Value)
Events.CabProgression:Fire(Attributes.PreviousFloor.Value, Attributes.CurrentFloor.Value, Attributes.NextFloor.Value)
end
--Elevator is riding upwards towards the destination
if Elevator_Position.Y>=LevelVec3-Elevator.FloorLevelingDistance then
if ElevatorPosition.Y>=LevelVec3-Elevator.FloorLevelingDistance then
Events.Leveling:Fire()
self.BoxAlignPosition.MaxVelocity = Elevator.LevelingVelocity
if Elevator_Position.Y>=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
if ElevatorPosition.Y>=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
Events.Leveling3Phase:Fire()
self.BoxAlignPosition.MaxVelocity = Elevator.Phase3LevelingVelocity
if Elevator_Position.Y>=LevelVec3-Elevator.ParkedDistance then
if ElevatorPosition.Y>=LevelVec3-Elevator.ParkedDistance then
Events.Parked:Fire()
CheckFloorQueue(self);
@@ -317,25 +315,24 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3
end
end
else
--Detecting between the floors
--leaving floor ElevatorPosition Y=62, Between_levels=75
if Elevator_Position.Y<=Between_Levels then
local PreviousFloor = Attributes.CurrentFloor.Value
if ElevatorPosition.Y<=AtFloorY+Elevator.FloorLevelingDistance then
Attributes.PreviousFloor.Value = Attributes.CurrentFloor.Value
Attributes.CurrentFloor.Value-=1
Attributes.NextFloor.Value = math.clamp(1, Attributes.CurrentFloor.Value-1, #LevelingModule.Leveling)
Events.CabProgression:Fire(PreviousFloor, Attributes.CurrentFloor.Value)
Events.CabProgression:Fire(Attributes.PreviousFloor.Value, Attributes.CurrentFloor.Value, Attributes.NextFloor.Value)
end
--Elevator is riding upwards towards the destination
if Elevator_Position.Y<=LevelVec3-Elevator.FloorLevelingDistance then
if ElevatorPosition.Y<=LevelVec3+Elevator.FloorLevelingDistance then
Events.Leveling:Fire()
self.BoxAlignPosition.MaxVelocity = Elevator.LevelingVelocity
if Elevator_Position.Y<=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
if ElevatorPosition.Y<=LevelVec3+Elevator.FloorLeveling3PhaseDistance then
Events.Leveling3Phase:Fire()
self.BoxAlignPosition.MaxVelocity = Elevator.Phase3LevelingVelocity
if Elevator_Position.Y<=LevelVec3-Elevator.ParkedDistance then
if ElevatorPosition.Y<=LevelVec3+Elevator.ParkedDistance then
Events.Parked:Fire()
CheckFloorQueue(self);
@@ -345,7 +342,7 @@ local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3
end
end
Events.CabTraveling:Fire(Elevator_Position, Attributes.CurrentFloor.Value)
Events.CabTraveling:Fire(deltaTime, ElevatorPosition)
end
function Elevator:__TravelToFloor(LevelInt, LevelVec3, ElevatorGoingUp)
@@ -357,7 +354,7 @@ function Elevator:__TravelToFloor(LevelInt, LevelVec3, ElevatorGoingUp)
Attributes.GoingUp.Value = ElevatorGoingUp
self.__Connections.Moving = RS.Heartbeat:Connect(function(deltaTime)
CabTraveling(self, deltaTime, LevelVec3, ElevatorGoingUp)
CabTraveling(self, deltaTime, LevelInt, LevelVec3, ElevatorGoingUp)
end)
--Set the elevator's AlignPosition to the floor Y vector
@@ -380,7 +377,7 @@ function Elevator:RequestLevel(RequestedLevel)
return true
end
elevatorwarn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`)
warn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`)
return false
end

View File

@@ -55,19 +55,14 @@ local Otis1960Buttons = Buttons[Enums.Elevator.Otis1960]
local Otis1960LandingDoors = LandingDoors[Enums.Elevator.Otis1960]
local Otis1960 = Otis1960_Module.constructor(TagsConstructor, Otis1960Buttons, Otis1960Lanterns, Otis1960LandingDoors)
task.wait(5)
Otis1960:RequestLevel(3)
Otis1960_Module.Events.Parked.Event:Connect(function()
print("Cab parked")
task.wait(3)
Otis1960:RequestLevel(1)
end)
Otis1960_Module.Events.CabProgression.Event:Connect(function(previousFloor: number?, nextFloor: number)
--print("previousFloor=",previousFloor, "nextFloor=",nextFloor)
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(Elevator_Position: Vector3, CurrentFloor: number)
print("CurrentFloor=",CurrentFloor)
Otis1960_Module.Events.CabTraveling.Event:Connect(function(deltaTime: number, Elevator_Position: Vector3)
end)