This commit is contained in:
2024-06-09 01:59:43 -04:00
parent 4b8379e0f3
commit f68767ed77
7 changed files with 197 additions and 164 deletions

View File

@@ -31,7 +31,7 @@ CrosshairModule.__index = CrosshairModule
CrosshairModule.Icon = "rbxassetid://12643750723" CrosshairModule.Icon = "rbxassetid://12643750723"
local Storage = game:GetService("ReplicatedStorage") local Storage = game:GetService("ReplicatedStorage")
local Easings = require(Storage:WaitForChild("Algebra")) local Algbera = require(Storage:WaitForChild("Algebra"))
function CrosshairModule.constructor(PlayerGui: PlayerGui) function CrosshairModule.constructor(PlayerGui: PlayerGui)
local Screen = PlayerGui:WaitForChild("Crosshair") :: ScreenGui local Screen = PlayerGui:WaitForChild("Crosshair") :: ScreenGui
@@ -57,7 +57,7 @@ end
function CrosshairModule:Jump(RootVelocity: Vector3) function CrosshairModule:Jump(RootVelocity: Vector3)
local X, Y = RootVelocity.X, RootVelocity.Y; local X, Y = RootVelocity.X, RootVelocity.Y;
self.Icon.Position = UDim2.fromScale( self.Icon.Position = UDim2.fromScale(
Y>1 and Easings.Linear(.5,.5+(X/1000),.3) or .5, Y>1 and Algbera.Easing.Linear(.5,.5+(X/1000),.3) or .5,
math.clamp(.4, .5-(-Y/1000), .6) math.clamp(.4, .5-(-Y/1000), .6)
) )
end end

View File

@@ -180,8 +180,8 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
self.ElevatorDoor1.CanCollide = false self.ElevatorDoor1.CanCollide = false
self.ElevatorDoor2.CanCollide = false self.ElevatorDoor2.CanCollide = false
local ElevatorDoor1_P: Vector3 = self.ElevatorDoor1.Position local ElevatorDoor1_P = self.ElevatorDoor1.Position
local ElevatorDoor2_P: Vector3 = self.ElevatorDoor2.Position local ElevatorDoor2_P = self.ElevatorDoor2.Position
local StartTime = os.clock() local StartTime = os.clock()
local Timing = Doors.ElevatorDoorTime-1 local Timing = Doors.ElevatorDoorTime-1
@@ -189,13 +189,14 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
if opening then if opening then
while task.wait() do while task.wait() do
local Time = Algebra.LinearElapse(StartTime, Timing) local Time = Algebra.LinearElapse(StartTime, Timing)
local Ease = Algebra.Easing.InOutQuad(Time)
local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0) local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z) local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z) local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z)
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector-Doors.Door1Stopped_X, Time) self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector-Doors.Door1Stopped_X, Ease)
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector-Doors.Door2Stopped_X, Time) self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector-Doors.Door2Stopped_X, Ease)
if Time>=1 then if Time>=1 then
break break
@@ -204,13 +205,14 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
else else
while task.wait() do while task.wait() do
local Time = Algebra.LinearElapse(StartTime, Timing) local Time = Algebra.LinearElapse(StartTime, Timing)
local Ease = Algebra.Easing.InOutQuad(Time)
local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0) local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z) local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z) local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z)
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector+Doors.Door1Stopped_X, Time) self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector+Doors.Door1Stopped_X, Ease)
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector+Doors.Door2Stopped_X, Time) self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector+Doors.Door2Stopped_X, Ease)
if Time>=1 then if Time>=1 then
break break

View File

@@ -21,7 +21,8 @@ type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
SetState: (self: ClassConstructor, RelayName: string, State: boolean, ActivateImmediately: boolean) -> () SetState: (self: ClassConstructor, RelayName: string, State: boolean, ActivateImmediately: boolean) -> (),
DisconnectButCabButtons: (self: ClassConstructor) -> ()
} }
type Constructor_Fun = (ElevatorModel: Enums.ElevatorValues, RelayTagList: Tags.RelayDictionary) -> ClassConstructor type Constructor_Fun = (ElevatorModel: Enums.ElevatorValues, RelayTagList: Tags.RelayDictionary) -> ClassConstructor
@@ -60,6 +61,51 @@ local function OtimLowPassSoundEffect(Model: Enums.ElevatorValues): OtimSoundEff
} }
end end
local function OtimSoundAndRelayConfiguration(RelayAudioActivated: Sound, RelayAudioDeActivated: Sound, SoundEffects: OtimSoundEffects, RelayProperties: Tags.RelayProperties)
RelayAudioActivated.SoundGroup = SoundEffects.SoundGroup
RelayAudioDeActivated.SoundGroup = SoundEffects.SoundGroup
if RelayProperties.Name == "240 V" or
RelayProperties.Name == "440 V" or
RelayProperties.Name == "UP" or
RelayProperties.Name == "DOWN"
then
--Bigger relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.BigRelayActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.BigRelayDeActivated
RelayAudioActivated.Volume = .5
RelayAudioDeActivated.Volume = .5
RelayProperties.Unique = true
else
--High placed relays for better spatial sound
if RelayProperties.Name == "F1C" or
RelayProperties.Name == "F2C" or
RelayProperties.Name == "F3C" or
RelayProperties.Name == "F4C" or
RelayProperties.Name == "F5C" or
RelayProperties.Name == "F6C" or
RelayProperties.Name == "F7C" or
RelayProperties.Name == "F8C" or
RelayProperties.Name == "F9C" or
RelayProperties.Name == "F10C"
then
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayHighActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
if RelayProperties.Prompt and (RelayProperties.Name ~= "F1C" and RelayProperties.Name ~= "F2C") then
RelayProperties.Prompt.MaxActivationDistance = 4
end
else
--Low placed relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayLowActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
end
end
RelayAudioActivated.RollOffMaxDistance = 130
RelayAudioActivated.RollOffMinDistance = 5
end
function PhysicalRelay.constructor(ElevatorModel, RelayTagList) function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
local SoundEffects: OtimSoundEffects? local SoundEffects: OtimSoundEffects?
@@ -72,54 +118,14 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
for RelayName, RelayProperties in RelayTagList do for RelayName, RelayProperties in RelayTagList do
if RelayProperties.Inst then if RelayProperties.Inst then
--Audio --Audio
local RelayAudioActivated = Instance.new("Sound") :: Sound local RelayAudioActivated = Instance.new("Sound") :: Sound
local RelayAudioDeActivated = Instance.new("Sound") :: Sound local RelayAudioDeActivated = Instance.new("Sound") :: Sound
if ElevatorModel == Enums.Elevator.Otis1960 then if ElevatorModel == Enums.Elevator.Otis1960 then
if SoundEffects then
RelayAudioActivated.SoundGroup = (SoundEffects :: OtimSoundEffects).SoundGroup OtimSoundAndRelayConfiguration(RelayAudioActivated, RelayAudioDeActivated, SoundEffects, RelayProperties)
RelayAudioDeActivated.SoundGroup = (SoundEffects :: OtimSoundEffects).SoundGroup
if RelayProperties.Name == "240 V" or
RelayProperties.Name == "440 V" or
RelayProperties.Name == "UP" or
RelayProperties.Name == "DOWN"
then
--Bigger relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.BigRelayActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.BigRelayDeActivated
RelayAudioActivated.Volume = .5
RelayAudioDeActivated.Volume = .5
RelayProperties.Unique = true
else
--High placed relays for better spatial sound
if RelayProperties.Name == "F1C" or
RelayProperties.Name == "F2C" or
RelayProperties.Name == "F3C" or
RelayProperties.Name == "F4C" or
RelayProperties.Name == "F5C" or
RelayProperties.Name == "F6C" or
RelayProperties.Name == "F7C" or
RelayProperties.Name == "F8C" or
RelayProperties.Name == "F9C" or
RelayProperties.Name == "F10C"
then
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayHighActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
if RelayProperties.Prompt then
RelayProperties.Prompt.MaxActivationDistance = 4
end
else
--Low placed relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayLowActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
end
end end
RelayAudioActivated.RollOffMaxDistance = 130
RelayAudioActivated.RollOffMinDistance = 5
RelayAudioActivated.Parent = RelayProperties.Inst RelayAudioActivated.Parent = RelayProperties.Inst
RelayAudioDeActivated.Parent = RelayProperties.Inst RelayAudioDeActivated.Parent = RelayProperties.Inst
end end
@@ -172,7 +178,7 @@ function PhysicalRelay:SetState(RelayName, State, ActivateImmediately)
if ActivateImmediately then if ActivateImmediately then
OtimRelayAnimation(Relay, State) OtimRelayAnimation(Relay, State)
else else
task.delay(Random.new():NextNumber(.1,.8), function() task.delay(Random.new():NextNumber(.1,1), function()
OtimRelayAnimation(Relay, State) OtimRelayAnimation(Relay, State)
end) end)
end end
@@ -186,4 +192,12 @@ function PhysicalRelay:SetState(RelayName, State, ActivateImmediately)
end end
end end
function PhysicalRelay:DisconnectButCabButtons()
for RelayName, Relay in self.RelayTagList do
if not RelayName:match('F%d+C') and Relay.Inst then
OtimRelayAnimation(Relay, false)
end
end
end
return PhysicalRelay return PhysicalRelay

View File

@@ -22,10 +22,8 @@ type Impl_Constructor = {
--Class functions --Class functions
BulkConnect: (self: ClassConstructor) -> (), BulkConnect: (self: ClassConstructor) -> (),
BulkDisconnect: (self: ClassConstructor) -> (), BulkDisconnect: (self: ClassConstructor) -> (),
__Ready: (self: ClassConstructor) -> (),
__Open: (self: ClassConstructor) -> (), __Open: (self: ClassConstructor) -> (),
__Goal: (self: ClassConstructor) -> (), __Goal: (self: ClassConstructor) -> (),
__GoalYLevel: (self: ClassConstructor) -> (),
} }
type Constructor_Fun = ( type Constructor_Fun = (
@@ -50,7 +48,6 @@ type Constructor_Return_Props = {
__Connections: { __Connections: {
ReadyForMoving: RBXScriptConnection?, ReadyForMoving: RBXScriptConnection?,
Open: RBXScriptConnection?, Open: RBXScriptConnection?,
GoalYLevel: RBXScriptConnection?,
Goal: RBXScriptConnection? Goal: RBXScriptConnection?
} }
} }
@@ -58,7 +55,6 @@ type Constructor_Return_Props = {
type ElevatorAttributes = { type ElevatorAttributes = {
Relay: { Relay: {
ReadyForMoving: BoolValue, ReadyForMoving: BoolValue,
GoalYLevel: NumberValue,
Goal: IntValue Goal: IntValue
}, },
@@ -86,40 +82,16 @@ function Relay.constructor(PhysicalRelay, RelayAlgorthm, ElevatorAttributes, Doo
}, Relay) }, Relay)
end end
function Relay:__Ready()
if not self.ElevatorAttributes.Relay.ReadyForMoving.Value then
self:__GoalYLevel()
end
end
function Relay:__Open() function Relay:__Open()
self.ElevatorAttributes.Relay.ReadyForMoving.Value = not self.DoorAttributes.Relay.Open.Value self.ElevatorAttributes.Relay.ReadyForMoving.Value = not self.DoorAttributes.Relay.Open.Value
end end
function Relay:__GoalYLevel()
if self.ElevatorAttributes.Relay.ReadyForMoving.Value then
self.BoxAlignPosition.Position = Vector3.new(
self.ElevatorBox.Position.X,
self.ElevatorAttributes.Relay.GoalYLevel.Value,
self.ElevatorBox.Position.Z
)
end
end
function Relay:__Goal()
self.ElevatorAttributes.Relay.GoalYLevel.Value = self.LevelingModule.Leveling[self.ElevatorAttributes.Relay.Goal.Value] or self.LevelingModule.Leveling[1] :: number
end
function Relay:BulkConnect() function Relay:BulkConnect()
local ReadyForMovingRelay = self.ElevatorAttributes.Relay.ReadyForMoving local ReadyForMovingRelay = self.ElevatorAttributes.Relay.ReadyForMoving
local OpenRelay = self.DoorAttributes.Relay.Open local OpenRelay = self.DoorAttributes.Relay.Open
self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function() self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function()
self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value, false) self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value, false)
if not self.ElevatorAttributes.Stopped.Value then
self:__Ready()
end
end) end)
self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function() self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function()
@@ -129,22 +101,6 @@ function Relay:BulkConnect()
self:__Open() self:__Open()
end end
end) end)
self.__Connections.GoalYLevel = self.ElevatorAttributes.Relay.GoalYLevel:GetPropertyChangedSignal("Value"):Connect(function()
if not self.ElevatorAttributes.Stopped.Value then
self:__GoalYLevel()
end
end)
self.__Connections.Goal = self.ElevatorAttributes.Relay.Goal:GetPropertyChangedSignal("Value"):Connect(function()
if not self.ElevatorAttributes.Stopped.Value then
self:__Goal()
end
end)
end end
function Relay:BulkDisconnect() function Relay:BulkDisconnect()
@@ -154,12 +110,6 @@ function Relay:BulkDisconnect()
if self.__Connections.Open and self.__Connections.Open.Connected then if self.__Connections.Open and self.__Connections.Open.Connected then
self.__Connections.Open:Disconnect() self.__Connections.Open:Disconnect()
end end
if self.__Connections.GoalYLevel and self.__Connections.GoalYLevel.Connected then
self.__Connections.GoalYLevel:Disconnect()
end
if self.__Connections.Goal and self.__Connections.Goal.Connected then
self.__Connections.Goal:Disconnect()
end
end end
return Relay return Relay

View File

@@ -8,7 +8,7 @@ type Impl_Constructor = {
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (), Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (), Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> number?,
RawInsert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (), RawInsert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> boolean AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> boolean
} }
@@ -69,9 +69,8 @@ function RelayAlgorithm:Sort(ElevatorGoingUp)
table.sort(self.__FloorQueue, function(a, b): boolean table.sort(self.__FloorQueue, function(a, b): boolean
if ElevatorGoingUp then if ElevatorGoingUp then
return a<b return a<b
else
return a>b
end end
return a>b
end) end)
self.Events.Sorted:Fire(self.__FloorQueue) self.Events.Sorted:Fire(self.__FloorQueue)
end end
@@ -82,9 +81,9 @@ function RelayAlgorithm:Check(ElevatorGoingUp)
end end
if #self.__FloorQueue ~= 0 then if #self.__FloorQueue ~= 0 then
self:Sort(ElevatorGoingUp) self:Sort(ElevatorGoingUp)
return true return self.__FloorQueue[1]
end end
return false return nil
end end
function RelayAlgorithm:RawInsert(ElevatorGoingUp, RequestedLevel) function RelayAlgorithm:RawInsert(ElevatorGoingUp, RequestedLevel)

View File

@@ -62,13 +62,14 @@ type Impl_Constructor = {
} & Impl_Static_Props } & Impl_Static_Props
type Impl_Static_Props = { type Impl_Static_Props = {
Name: Enums.ElevatorValues, Name: Enums.ElevatorValues,
Responsiveness: number, Responsiveness: number,
MaxVelocity: number, MaxVelocity: number,
FloorLevelingDistance: number, FloorLevelingDistance: number,
DoorOpeningDistance: number, FloorLeveling3PhaseDistance: number,
LeveledDistance: number, DoorOpeningDistance: number,
QueueWaitTime: number, LeveledDistance: number,
QueueWaitTime: number,
Sounds: { Sounds: {
LanternChimeDirection: SoundEnums.Otis1960LanternChimeDirection, LanternChimeDirection: SoundEnums.Otis1960LanternChimeDirection,
@@ -88,7 +89,6 @@ type Impl_Static_Props = {
Relay: { Relay: {
Goal: IntValue, Goal: IntValue,
GoalYLevel: NumberValue,
ReadyForMoving: BoolValue, ReadyForMoving: BoolValue,
} }
} }
@@ -137,13 +137,14 @@ type Constructor_Return_Props = {
local Elevator = {} :: Impl_Constructor local Elevator = {} :: Impl_Constructor
Elevator.__index = Elevator Elevator.__index = Elevator
Elevator.Name = Enums.Elevator.Otis1960 Elevator.Name = Enums.Elevator.Otis1960
Elevator.FloorLevelingDistance = 2.5 Elevator.FloorLevelingDistance = 4
Elevator.DoorOpeningDistance = Elevator.FloorLevelingDistance/2.8 Elevator.FloorLeveling3PhaseDistance = 1.5
Elevator.LeveledDistance = 0.5 Elevator.DoorOpeningDistance = Elevator.FloorLeveling3PhaseDistance/2.8
Elevator.Responsiveness = 10 Elevator.LeveledDistance = 0.5
Elevator.MaxVelocity = 8 Elevator.Responsiveness = 10
Elevator.QueueWaitTime = 5 Elevator.MaxVelocity = 7
Elevator.QueueWaitTime = 5
Elevator.Sounds = { Elevator.Sounds = {
LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection, LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection,
@@ -164,9 +165,8 @@ Elevator.Attributes = {
Stopped = Instance.new("BoolValue") :: BoolValue, Stopped = Instance.new("BoolValue") :: BoolValue,
Relay = { Relay = {
ReadyForMoving = Instance.new("BoolValue") :: BoolValue, ReadyForMoving = Instance.new("BoolValue") :: BoolValue,
Goal = Instance.new("IntValue") :: IntValue, Goal = Instance.new("IntValue") :: IntValue,
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
}, },
} }
@@ -175,7 +175,6 @@ Elevator.Attributes.Moving.Value = false
Elevator.Attributes.GoingUp.Value = false Elevator.Attributes.GoingUp.Value = false
Elevator.Attributes.Relay.Goal.Value = 1 Elevator.Attributes.Relay.Goal.Value = 1
Elevator.Attributes.Relay.GoalYLevel.Value = LevelingModule.Leveling[Elevator.Attributes.CurrentFloor.Value]
Elevator.Attributes.Relay.ReadyForMoving.Value = false Elevator.Attributes.Relay.ReadyForMoving.Value = false
local Attributes = Elevator.Attributes local Attributes = Elevator.Attributes
@@ -212,8 +211,6 @@ end
--If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed, --If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed,
--then open the doors --then open the doors
local function OpenElevatorDoorsSafe(self: ClassConstructor) local function OpenElevatorDoorsSafe(self: ClassConstructor)
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.ReadyForMoving=",Attributes.Relay.ReadyForMoving.Value)
if not Attributes.Relay.ReadyForMoving.Value then if not Attributes.Relay.ReadyForMoving.Value then
task.spawn(function() task.spawn(function()
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value) self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
@@ -344,7 +341,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.BoxAlignPosition, self.BoxAlignPosition,
self.BoxAlignOrientation = ElevatorMover( self.BoxAlignOrientation = ElevatorMover(
self.ElevatorBox_1960, self.ElevatorBox_1960,
Vector3.new(self.ElevatorBox_1960.Position.X, Elevator.Attributes.Relay.GoalYLevel.Value, self.ElevatorBox_1960.Position.Z), Vector3.new(self.ElevatorBox_1960.Position.X, LevelingModule.Leveling[Attributes.Relay.Goal.Value] or LevelingModule.Leveling[1], self.ElevatorBox_1960.Position.Z),
Elevator.Responsiveness, Elevator.Responsiveness,
Elevator.MaxVelocity Elevator.MaxVelocity
) )
@@ -365,8 +362,11 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.RelayConstructor:BulkConnect() self.RelayConstructor:BulkConnect()
self.__Connections.FloorSorted = self.RelayAlgorithmConstructor.Events.Sorted.Event:Connect(function(FloorQueue: RelayAlgorithm.FloorQueue) self.__Connections.FloorSorted = self.RelayAlgorithmConstructor.Events.Sorted.Event:Connect(function(FloorQueue: RelayAlgorithm.FloorQueue)
if Attributes.Moving.Value and FloorQueue[1] then print("Floors sorted")
if FloorQueue[1] then
Attributes.Relay.Goal.Value = FloorQueue[1] :: number Attributes.Relay.Goal.Value = FloorQueue[1] :: number
else
Attributes.Relay.Goal.Value = 1
end end
end) end)
@@ -381,8 +381,8 @@ end
local function Leveled(self: ClassConstructor, RequestedLevel: number) local function Leveled(self: ClassConstructor, RequestedLevel: number)
(self.__Connections.Moving :: RBXScriptConnection):Disconnect() (self.__Connections.Moving :: RBXScriptConnection):Disconnect()
Attributes.Moving.Value = false Attributes.Moving.Value = false
Attributes.CurrentFloor.Value = RequestedLevel Attributes.CurrentFloor.Value = RequestedLevel
--self.BoxAlignPosition.MaxVelocity = 0 --self.BoxAlignPosition.MaxVelocity = 0
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value) self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
@@ -392,12 +392,15 @@ local function Leveled(self: ClassConstructor, RequestedLevel: number)
self.PhysicalRelays:SetState("240 V", false, false) self.PhysicalRelays:SetState("240 V", false, false)
task.wait(Elevator.QueueWaitTime) task.wait(Elevator.QueueWaitTime)
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value)
print("CurrentFloor=",Attributes.CurrentFloor.Value,"Goal=",Attributes.Relay.Goal.Value)
local NextLevel = self.RelayAlgorithmConstructor:Check(ElevatorGoingUp)
if NextLevel then
--More floors in the queue --More floors in the queue
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel) print(self.RelayAlgorithmConstructor.__FloorQueue)
--self:__MoveToAsync(ElevatorGoingUp, NextLevel)
else else
--The elevator is at a full park now --The elevator is at a full park now
Attributes.Relay.ReadyForMoving.Value = false Attributes.Relay.ReadyForMoving.Value = false
@@ -405,12 +408,16 @@ local function Leveled(self: ClassConstructor, RequestedLevel: number)
end end
local function Leveling(self: ClassConstructor, RequestedLevel: number) local function Leveling(self: ClassConstructor, RequestedLevel: number)
self.PhysicalRelays:SetState("440 V", false, false) self.PhysicalRelays:SetState("440 V", false, true)
self.BoxAlignPosition.MaxVelocity = 1 self.BoxAlignPosition.MaxVelocity = 1
self.LanternsConstructor:Toggle(true, RequestedLevel) self.LanternsConstructor:Toggle(true, RequestedLevel)
end end
local function Leveling3Phase(self: ClassConstructor, RequestedLevel: number)
self.BoxAlignPosition.MaxVelocity = .4
end
local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value+1] local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value+1]
@@ -438,6 +445,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
self.__Connections.Moving:Disconnect() self.__Connections.Moving:Disconnect()
end end
local GoingTo_Y_Level = LevelingModule.Leveling[RequestedLevel]
if not GoingTo_Y_Level then
--fail safe
warn(`{Elevator.Name}: floor request "{RequestedLevel}" failed`)
GoingTo_Y_Level = LevelingModule.Leveling[1]
end
local Delta = 0 local Delta = 0
local DoorsOpeningDebounce = false local DoorsOpeningDebounce = false
@@ -448,18 +462,25 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
self.PhysicalRelays:SetState(GoingUp and "UP" or "DOWN", true, false) self.PhysicalRelays:SetState(GoingUp and "UP" or "DOWN", true, false)
self.PhysicalRelays:SetState("240 V", true, false) self.PhysicalRelays:SetState("240 V", true, false)
self.PhysicalRelays:SetState("440 V", true, false) self.PhysicalRelays:SetState("440 V", true, false)
self.MOConstructor:UpdateCFrame() self.MOConstructor:UpdateCFrame()
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
self.BoxAlignPosition.Position = Vector3.new(
self.ElevatorBox_1960.Position.X,
GoingTo_Y_Level,
self.ElevatorBox_1960.Position.Z
)
--task.wait(1)
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt) self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
Delta+=1 Delta+=1
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position local ElevatorPosition = self.ElevatorBox_1960.Position
local ElevatorPositionY: number = ElevatorPosition.Y local ElevatorPositionY = ElevatorPosition.Y
local BoxAlignY: number = self.BoxAlignPosition.Position.Y local BoxAlignY = self.BoxAlignPosition.Position.Y
local ElevatorVelocityY: number = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y local ElevatorVelocityY = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
self.TractionRopesConstructor:Move(27, self.ElevatorBox_1960.Position) self.TractionRopesConstructor:Move(27, ElevatorPosition)
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY) self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
--Kill the connection --Kill the connection
@@ -469,9 +490,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
if ElevatorPositionY>=BoxAlignY-Elevator.FloorLevelingDistance then if ElevatorPositionY>=BoxAlignY-Elevator.FloorLevelingDistance then
Leveling(self, Attributes.Relay.Goal.Value) Leveling(self, Attributes.Relay.Goal.Value)
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then if ElevatorPositionY>=BoxAlignY-Elevator.FloorLeveling3PhaseDistance then
DoorsOpeningDebounce = true Leveling3Phase(self, RequestedLevel)
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
DoorsOpeningDebounce = true
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
end
end end
end end
@@ -484,9 +509,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
if ElevatorPositionY<=BoxAlignY+Elevator.FloorLevelingDistance then if ElevatorPositionY<=BoxAlignY+Elevator.FloorLevelingDistance then
Leveling(self, Attributes.Relay.Goal.Value) Leveling(self, Attributes.Relay.Goal.Value)
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then if ElevatorPositionY<=BoxAlignY+Elevator.FloorLeveling3PhaseDistance then
DoorsOpeningDebounce = true Leveling3Phase(self, RequestedLevel)
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
if not DoorsOpeningDebounce and ElevatorPositionY<=BoxAlignY+Elevator.DoorOpeningDistance then
DoorsOpeningDebounce = true
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
end
end end
end end
@@ -501,6 +530,7 @@ function Elevator:__MoveToAsync(GoingUp, RequestedLevel)
if Doors.Attributes.Relay.Open.Value then if Doors.Attributes.Relay.Open.Value then
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value) self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
end end
if GoingUp then if GoingUp then
self.LanternsConstructor:DirectionUp(true) self.LanternsConstructor:DirectionUp(true)
else else
@@ -511,11 +541,11 @@ function Elevator:__MoveToAsync(GoingUp, RequestedLevel)
end end
function Elevator:RequestLevelAsync(RequestedLevel) function Elevator:RequestLevelAsync(RequestedLevel)
local FloorExist: number? = LevelingModule.Leveling[RequestedLevel] local FloorY_Level: number? = LevelingModule.Leveling[RequestedLevel]
if FloorExist and RequestedLevel ~= Attributes.CurrentFloor.Value then if FloorY_Level and RequestedLevel ~= Attributes.CurrentFloor.Value then
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)
--Mmm... temporary, cant distinguish here if this will be a cab or hall call --Mmm... temporary, cant distinguish here if this will be a cab or hall call
self.PhysicalRelays:SetState(`F{RequestedLevel}C`, true, true) self.PhysicalRelays:SetState(`F{RequestedLevel}C`, true, true)
@@ -523,11 +553,21 @@ function Elevator:RequestLevelAsync(RequestedLevel)
if Proceeding then if Proceeding then
self.PhysicalRelays:SetState("RUN", true, false) --This needs to be on a timer for the generator after 60 seconds self.PhysicalRelays:SetState("RUN", true, false) --This needs to be on a timer for the generator after 60 seconds
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel) self:__MoveToAsync(ElevatorGoingUp, RequestedLevel)
else
if ElevatorGoingUp == Attributes.GoingUp.Value then
self.BoxAlignPosition.Position = Vector3.new(
self.ElevatorBox_1960.Position.X,
LevelingModule.Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1] or 1],
self.ElevatorBox_1960.Position.Z
)
end
end end
return true return true
else else
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`) warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
end end
return false return false
end end

View File

@@ -4,8 +4,8 @@
--My versions --My versions
type EaseFunction = (n: number) -> number type Ease = (n: number) -> number
type LinearFunction = (a: number, b: number, t: number) -> number type Linear = (a: number, b: number, t: number) -> number
export type RotationMatrix = { export type RotationMatrix = {
Ixx: number, Ixx: number,
@@ -18,15 +18,22 @@ export type RotationMatrix = {
export type Scalar = { export type Scalar = {
Distance: number, Distance: number,
Center: Vector2, Center: Vector2,
Rotation: number Rotation: number
} }
export type Easing = {
Linear: Linear,
InOutBack: Ease,
OutBounce: Ease,
InQuad: Ease,
OutQuad: Ease,
InOutQuad: Ease,
InOutQuart: Ease,
}
export type Math = { export type Math = {
Linear: LinearFunction, Easing: Easing,
InOutBack: EaseFunction,
OutBounce: EaseFunction,
InQuad: EaseFunction,
IsOdd: (n: number) -> boolean, IsOdd: (n: number) -> boolean,
IsEven: (n: number) -> boolean, IsEven: (n: number) -> boolean,
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix, RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
@@ -36,7 +43,9 @@ export type Math = {
minmax: (min: number, n: number, max: number) -> number minmax: (min: number, n: number, max: number) -> number
} }
local Math = {} :: Math local Math = {
Easing = {}
} :: Math
function Math.IsOdd(n) function Math.IsOdd(n)
return bit32.btest(bit32.band(n, 1)) return bit32.btest(bit32.band(n, 1))
@@ -81,24 +90,43 @@ function Math.LinearElapse(StartTime, Timing)
end end
--My versions --My versions
function Math.Linear(a, b, t) function Math.Easing.Linear(a, b, t)
return a-a*t+b*t return a-a*t+b*t
end end
local c = 2.59491 local c = 2.59491
function Math.InOutBack(n) function Math.Easing.InOutBack(n)
return n<.5 and 2*n*n*(-c+2*n+2*c*n) or 3*(-1+n)*(-1+n)*(-2-c+2*n+2*c*n) return n<.5 and 2*n*n*(-c+2*n+2*c*n) or 3*(-1+n)*(-1+n)*(-2-c+2*n+2*c*n)
end end
local n1, d1 = 7.5625, 2.75 local n1, d1 = 7.5625, 2.75
function Math.OutBounce(n) function Math.Easing.OutBounce(n)
return (n<0.363636 and n*n*n1 or return (n<0.363636 and n*n*n1 or
n<0.727273 and (.75*(1.*d1-2.*n*n1)) or n<0.727273 and (.75*(1.*d1-2.*n*n1)) or
n<0.909091 and (.9375*(1.*d1-2.4*n*n1)/d1)) or (.984375*(1.*d1-2.66667*n*n1))/d1 n<0.909091 and (.9375*(1.*d1-2.4*n*n1)/d1)) or (.984375*(1.*d1-2.66667*n*n1))/d1
end end
function Math.InQuad(n) function Math.Easing.InQuad(n)
return n*n return n*n
end end
function Math.Easing.OutQuad(n)
return -((-2+n)*n)
end
function Math.Easing.InOutQuad(n)
-- n<.5 and 2*n*n or -1-2*(-2+n)*n
-- -n*math.abs(n)+n
-- n-.5*n*math.abs(n)
-- n-n*math.abs(n)
return n<.5 and 2*n*n or -1-2*(-2+n)*n
end
function Math.Easing.InOutQuart(n)
--n<.5 and 8*n*n*n*n or 1-(-2*n+2)*(-2*n+2)*(-2*n+2)*(-2*n+2)/2
return n<.5 and 8*n*n*n*n or 1-8*(-1+n)*(-1+n)*(-1+n)*(-1+n)
end
return Math return Math