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, [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 { return {
Leveling = Leveling, Leveling = Leveling
LevelingBetween = LevelingBetween
} }

View File

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

View File

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