|
|
|
|
@@ -9,7 +9,10 @@ local MainDir = ElevatorsDir.Parent
|
|
|
|
|
local Storage = game:GetService("ReplicatedStorage")
|
|
|
|
|
local RS = game:GetService("RunService")
|
|
|
|
|
|
|
|
|
|
local DoorEnums = require(MainDir:WaitForChild("Types"):WaitForChild("Enums"):WaitForChild("Doors"))
|
|
|
|
|
local Types = MainDir:WaitForChild("Types")
|
|
|
|
|
|
|
|
|
|
local DoorEnums = require(Types:WaitForChild("Enums"):WaitForChild("Doors"))
|
|
|
|
|
local ElevatorEnums = require(Types:WaitForChild("Elevator"))
|
|
|
|
|
local Tags = require(MainDir:WaitForChild("Map"):WaitForChild("Load"):WaitForChild("Tags"))
|
|
|
|
|
local Algebra = require(Storage:WaitForChild("Algebra"))
|
|
|
|
|
|
|
|
|
|
@@ -20,22 +23,18 @@ type Impl_Constructor = {
|
|
|
|
|
--Class functions
|
|
|
|
|
OpenCabAsync: (self: ClassConstructor, ObjectSpaceDistance: Vector3) -> (),
|
|
|
|
|
CloseCabAsync: (self: ClassConstructor, ObjectSpaceDistance: Vector3) -> (),
|
|
|
|
|
OpenFloorAsync: (self: ClassConstructor, Floor: number, ObjectSpaceDistance: Vector3) -> (),
|
|
|
|
|
CloseFloorAsync: (self: ClassConstructor, Floor: number, ObjectSpaceDistance: Vector3) -> (),
|
|
|
|
|
OpenAtFloorAsync: (self: ClassConstructor, Floor: number) -> (),
|
|
|
|
|
CloseAtFloorAsync: (self: ClassConstructor, Floor: number) -> (),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type LandingDoorsTree = {
|
|
|
|
|
[number]: {BasePart}
|
|
|
|
|
}
|
|
|
|
|
type CabDoorsTree = {
|
|
|
|
|
[number]: {BasePart}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Constructor_Fun = (
|
|
|
|
|
DoorConfig: ElevatorEnums.DoorsConfig,
|
|
|
|
|
ElevatorBox: BasePart,
|
|
|
|
|
CabDoorsType: DoorEnums.DoorEnumValues,
|
|
|
|
|
CabDoorsTree: {BasePart},
|
|
|
|
|
LandingDoorsType: DoorEnums.DoorEnumValues,
|
|
|
|
|
LandingDoorsTree: Tags.LandingTags
|
|
|
|
|
) -> ClassConstructor
|
|
|
|
|
|
|
|
|
|
@@ -45,124 +44,170 @@ type Attributes = {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Events = {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Constructor_Return_Props = {
|
|
|
|
|
DoorConfig: ElevatorEnums.DoorsConfig,
|
|
|
|
|
ElevatorBox: BasePart,
|
|
|
|
|
CabDoorsType: DoorEnums.DoorEnumValues,
|
|
|
|
|
CabDoorsTree: {BasePart},
|
|
|
|
|
LandingDoorsType: DoorEnums.DoorEnumValues,
|
|
|
|
|
LandingDoorsTree: Tags.LandingTags,
|
|
|
|
|
Attributes: Attributes
|
|
|
|
|
Attributes: Attributes,
|
|
|
|
|
|
|
|
|
|
__Connections: {
|
|
|
|
|
DoorAnimationStep: RBXScriptConnection?
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local Doors = {} :: Impl_Constructor
|
|
|
|
|
Doors.__index = Doors
|
|
|
|
|
|
|
|
|
|
function Doors.constructor(ElevatorBox, CabDoorsType, CabDoorsTree, LandingDoorsType, LandingDoorsTree)
|
|
|
|
|
function Doors.constructor(DoorConfig, ElevatorBox, CabDoorsTree, LandingDoorsTree)
|
|
|
|
|
local HallOpen = Instance.new("BoolValue") :: BoolValue
|
|
|
|
|
HallOpen.Value = true
|
|
|
|
|
|
|
|
|
|
return setmetatable({
|
|
|
|
|
DoorConfig = DoorConfig,
|
|
|
|
|
ElevatorBox = ElevatorBox,
|
|
|
|
|
CabDoorsType = CabDoorsType,
|
|
|
|
|
CabDoorsTree = CabDoorsTree,
|
|
|
|
|
LandingDoorsType = LandingDoorsType,
|
|
|
|
|
LandingDoorsTree = LandingDoorsTree,
|
|
|
|
|
|
|
|
|
|
Attributes = {
|
|
|
|
|
Hall = {
|
|
|
|
|
Open = HallOpen
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
__Connections = {}
|
|
|
|
|
}, Doors)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
type DoorAnimationCallback<T...> = (self: ClassConstructor, Alpha: number, Time: number, T...) -> ()
|
|
|
|
|
local function DoorAnimationAsync(self: ClassConstructor, Time: number, Callback: DoorAnimationCallback<()>)
|
|
|
|
|
local Alpha = 0
|
|
|
|
|
local StartTime = os.clock()
|
|
|
|
|
type DoorAnimationCallback<T...> = (self: ClassConstructor, Time: number, T...) -> ()
|
|
|
|
|
local function DoorAnimationRuntime(self: ClassConstructor, Time: number, Callback: DoorAnimationCallback<()>)
|
|
|
|
|
if self.__Connections.DoorAnimationStep and self.__Connections.DoorAnimationStep.Connected then
|
|
|
|
|
self.__Connections.DoorAnimationStep:Disconnect()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
while RS.Stepped:Wait() do
|
|
|
|
|
Alpha+=1e-3
|
|
|
|
|
local StartTime = os.clock()
|
|
|
|
|
self.__Connections.DoorAnimationStep = RS.Stepped:Connect(function(_delta: number, _dt: number)
|
|
|
|
|
local AnimationTime = Algebra.LinearElapse(StartTime, Time)
|
|
|
|
|
Callback(self, Alpha, AnimationTime)
|
|
|
|
|
Callback(self, AnimationTime)
|
|
|
|
|
|
|
|
|
|
if AnimationTime>=1 then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
(self.__Connections.DoorAnimationStep :: RBXScriptConnection):Disconnect()
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--a<T> = ...T
|
|
|
|
|
type DoorAnimationsMap = {
|
|
|
|
|
Cab: {
|
|
|
|
|
[DoorEnums.DoorEnumValues]: DoorAnimationCallback<Vector3, Vector3?, Vector3?>
|
|
|
|
|
SingleSpeed: DoorAnimationCallback<Vector3, Vector3, Vector3>,
|
|
|
|
|
DoubleSpeed: DoorAnimationCallback<Vector3, Vector3, Vector3, Vector3>,
|
|
|
|
|
TripleSpeed: DoorAnimationCallback<Vector3, Vector3, Vector3, Vector3, Vector3, Vector3>,
|
|
|
|
|
},
|
|
|
|
|
Floor: {
|
|
|
|
|
[DoorEnums.DoorEnumValues]: DoorAnimationCallback<number, Vector3, Vector3>
|
|
|
|
|
SingleSpeed: DoorAnimationCallback<number, Vector3, Vector3>,
|
|
|
|
|
DoubleSpeed: DoorAnimationCallback<number, Vector3, Vector3, Vector3>,
|
|
|
|
|
TripleSpeed: DoorAnimationCallback<number, Vector3, Vector3, Vector3, Vector3>,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
local DoorAnimations: DoorAnimationsMap = {
|
|
|
|
|
local DoorAnimations = {
|
|
|
|
|
Cab = {},
|
|
|
|
|
Floor = {}
|
|
|
|
|
}
|
|
|
|
|
} :: DoorAnimationsMap
|
|
|
|
|
|
|
|
|
|
DoorAnimations.Cab[DoorEnums.Door.SingleSpeed] = function(self, Alpha, AnimationTime, OpenFromVec1)
|
|
|
|
|
--Cab doors--
|
|
|
|
|
function DoorAnimations.Cab.SingleSpeed(self, AnimationTime, Door1Position, OpenToVec1)
|
|
|
|
|
local ElevatorY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
|
|
|
|
|
local ElevatorDoor1_Goal = Vector3.new(OpenFromVec1.X, 0, OpenFromVec1.Z)
|
|
|
|
|
local ElevatorDoor1_Goal = Vector3.new(OpenToVec1.X, 0, OpenToVec1.Z)
|
|
|
|
|
|
|
|
|
|
self.CabDoorsTree[1].Position = ElevatorY+self.CabDoorsTree[1].Position:Lerp(OpenFromVec1+ElevatorDoor1_Goal, Algebra.Easing.InOutQuart(AnimationTime))
|
|
|
|
|
self.CabDoorsTree[1].Position = ElevatorY+self.CabDoorsTree[1].Position:Lerp(OpenToVec1+ElevatorDoor1_Goal, Algebra.Easing.InOutQuart(AnimationTime))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
DoorAnimations.Cab[DoorEnums.Door.DoubleSpeed] = function(self, Alpha, AnimationTime, OpenFromVec1, OpenFromVec2)
|
|
|
|
|
function DoorAnimations.Cab.DoubleSpeed(self, AnimationTime, Door1Position, Door2Position, OpenToVec1, OpenToVec2)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
DoorAnimations.Cab[DoorEnums.Door.TripleSpeed] = function(self, Alpha, AnimationTime, OpenFromVec1, OpenFromVec2, OpenFromVec3)
|
|
|
|
|
function DoorAnimations.Cab.TripleSpeed(self, AnimationTime, Door1Position, Door2Position, Door3Position, OpenToVec1, OpenToVec2, OpenToVec3)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
DoorAnimations.Floor[DoorEnums.Door.SingleSpeed] = function(self, Alpha, AnimationTime, Floor, DoorPosition, OpenFromVec1)
|
|
|
|
|
(self.LandingDoorsTree[Floor][1] :: BasePart).Position = DoorPosition:Lerp(OpenFromVec1, Algebra.Easing.OutQuad(AnimationTime))
|
|
|
|
|
--Floor doors--
|
|
|
|
|
function DoorAnimations.Floor.SingleSpeed(self, Floor, AnimationTime, Door1Position, OpenToVec1)
|
|
|
|
|
(self.LandingDoorsTree[Floor][1] :: BasePart).Position = Door1Position:Lerp(OpenToVec1, Algebra.Easing.OutQuad(AnimationTime))
|
|
|
|
|
end
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
--Goofy ahh function
|
|
|
|
|
local function OpenVecTuple(self: ClassConstructor, FloorWithDoors: Tags.LandingDoors, Opening: boolean, Type: DoorEnums.DoorEnumValues): ...Vector3?
|
|
|
|
|
if Type == DoorEnums.Door.SingleSpeed then
|
|
|
|
|
local P = (FloorWithDoors[1] :: BasePart).Position
|
|
|
|
|
return table.unpack({
|
|
|
|
|
P,
|
|
|
|
|
P+(Opening and -self.DoorConfig.Cab.Goal or self.DoorConfig.Cab.Goal)
|
|
|
|
|
})
|
|
|
|
|
elseif Type == DoorEnums.Door.DoubleSpeed then
|
|
|
|
|
local P = (FloorWithDoors[1] :: BasePart).Position
|
|
|
|
|
local P2 = (FloorWithDoors[2] :: BasePart).Position
|
|
|
|
|
return table.unpack({
|
|
|
|
|
P,
|
|
|
|
|
P2,
|
|
|
|
|
P+(Opening and -self.DoorConfig.Cab.Goal or self.DoorConfig.Cab.Goal),
|
|
|
|
|
(P2+(Opening and -self.DoorConfig.Cab.Goal or self.DoorConfig.Cab.Goal))/2
|
|
|
|
|
})
|
|
|
|
|
elseif Type == DoorEnums.Door.TripleSpeed then
|
|
|
|
|
--idk man
|
|
|
|
|
local P = (FloorWithDoors[1] :: BasePart).Position
|
|
|
|
|
local P2 = (FloorWithDoors[2] :: BasePart).Position
|
|
|
|
|
local P3 = (FloorWithDoors[3] :: BasePart).Position
|
|
|
|
|
return table.unpack({
|
|
|
|
|
P,
|
|
|
|
|
P2,
|
|
|
|
|
P3,
|
|
|
|
|
P+(Opening and -self.DoorConfig.Cab.Goal or self.DoorConfig.Cab.Goal),
|
|
|
|
|
(P2+(Opening and -self.DoorConfig.Cab.Goal or self.DoorConfig.Cab.Goal))/1.5,
|
|
|
|
|
(P3+(Opening and -self.DoorConfig.Cab.Goal or self.DoorConfig.Cab.Goal))/2,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Doors:OpenCabAsync(ObjectSpaceDistance)
|
|
|
|
|
local OpenFromVecTuple = self.CabDoorsTree[1].Position+ObjectSpaceDistance
|
|
|
|
|
DoorAnimationAsync(self, 4, function(self, Alpha, Time)
|
|
|
|
|
DoorAnimations.Cab[self.CabDoorsType](self, Alpha, Time, OpenFromVecTuple)
|
|
|
|
|
end)
|
|
|
|
|
-- local OpenFromVecTuple = self.CabDoorsTree[1].Position+ObjectSpaceDistance
|
|
|
|
|
-- --local Open = OpenVecTuple(self, DoorEnums.DoorLocation.Cab)
|
|
|
|
|
|
|
|
|
|
-- DoorAnimationRuntime(self, self.DoorConfig.Cab.Time, function(self, AnimationTime)
|
|
|
|
|
-- DoorAnimations.Cab[self.DoorConfig.Cab.Type](self, AnimationTime, OpenFromVecTuple)
|
|
|
|
|
-- end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Doors:CloseCabAsync(ObjectSpaceDistance)
|
|
|
|
|
local CloseFromVecTuple = self.CabDoorsTree[1].Position-ObjectSpaceDistance
|
|
|
|
|
DoorAnimationAsync(self, 4, function(self, Alpha, Time)
|
|
|
|
|
DoorAnimations.Cab[self.CabDoorsType](self, Alpha, Time, CloseFromVecTuple)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Doors:CloseFloorAsync(Floor, ObjectSpaceDistance)
|
|
|
|
|
--this needs to be made custom for self.CabDoorsType
|
|
|
|
|
local DoorFloor = self.LandingDoorsTree[Floor]
|
|
|
|
|
assert(DoorFloor)
|
|
|
|
|
local Door = DoorFloor[1]
|
|
|
|
|
assert(Door)
|
|
|
|
|
local DoorPosition = (Door :: BasePart).Position
|
|
|
|
|
local OpenFromVecTuple = DoorPosition+ObjectSpaceDistance
|
|
|
|
|
DoorAnimationAsync(self, 4, function(self, Alpha, Time)
|
|
|
|
|
DoorAnimations.Floor[self.CabDoorsType](self, Alpha, Time, Floor, DoorPosition, OpenFromVecTuple)
|
|
|
|
|
--this module is built off my insanity
|
|
|
|
|
local function ToggleFloorDoors(self: ClassConstructor, Floor: number, Opening: boolean)
|
|
|
|
|
local FloorWithDoors = self.LandingDoorsTree[Floor]
|
|
|
|
|
if FloorWithDoors then
|
|
|
|
|
local OpenFromVecTuple = OpenVecTuple(self, FloorWithDoors, Opening, self.DoorConfig.Landing.Type)
|
|
|
|
|
assert(OpenFromVecTuple)
|
|
|
|
|
|
|
|
|
|
DoorAnimationRuntime(self, self.DoorConfig.Landing.Time, function(self, AnimationTime)
|
|
|
|
|
DoorAnimations.Floor[self.DoorConfig.Landing.Type](self, Floor, AnimationTime, OpenFromVecTuple)
|
|
|
|
|
end)
|
|
|
|
|
self.Attributes.Hall.Open.Value = false
|
|
|
|
|
else
|
|
|
|
|
warn(`Could not open the door at floor: {Floor}, it does not exist in the landing doors tree.`)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Doors:OpenFloorAsync(Floor, ObjectSpaceDistance)
|
|
|
|
|
--this needs to be made custom for self.CabDoorsType
|
|
|
|
|
local DoorFloor = self.LandingDoorsTree[Floor]
|
|
|
|
|
assert(DoorFloor)
|
|
|
|
|
local Door = DoorFloor[1]
|
|
|
|
|
assert(Door)
|
|
|
|
|
local DoorPosition = (Door :: BasePart).Position
|
|
|
|
|
local OpenFromVecTuple = DoorPosition-ObjectSpaceDistance
|
|
|
|
|
DoorAnimationAsync(self, 4, function(self, Alpha, Time)
|
|
|
|
|
DoorAnimations.Floor[self.CabDoorsType](self, Alpha, Time, Floor, DoorPosition, OpenFromVecTuple)
|
|
|
|
|
end)
|
|
|
|
|
self.Attributes.Hall.Open.Value = true
|
|
|
|
|
function Doors:CloseAtFloorAsync(Floor)
|
|
|
|
|
ToggleFloorDoors(self, Floor, false)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Doors:OpenAtFloorAsync(Floor)
|
|
|
|
|
ToggleFloorDoors(self, Floor, true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|