From ef05f10cefae49e2e525fb66bbb60f8b34192fb3 Mon Sep 17 00:00:00 2001 From: unixtensor Date: Sat, 31 Aug 2024 17:17:34 -0400 Subject: [PATCH] Working landing doors, cab doors attempt --- .../main/Elevators/Map/Haughton/Config.luau | 2 +- .../main/Elevators/Map/Haughton/Doors.luau | 147 +++++++++++------- .../main/Elevators/Map/Haughton/init.luau | 10 +- src/server/main/Map/Load/Tags/init.luau | 47 ++++-- src/server/main/Types/Elevator.luau | 18 +-- 5 files changed, 135 insertions(+), 89 deletions(-) diff --git a/src/server/main/Elevators/Map/Haughton/Config.luau b/src/server/main/Elevators/Map/Haughton/Config.luau index 69cdf99..d79bd95 100644 --- a/src/server/main/Elevators/Map/Haughton/Config.luau +++ b/src/server/main/Elevators/Map/Haughton/Config.luau @@ -70,7 +70,7 @@ local DoorsConfig: ElevatorTypes.DoorsConfig = { Landing = { Type = DoorEnums.Door.SingleSpeed, Time = 4, - Goal = Vector3.new(4.15,0,0) + Goal = Vector3.new(4.221,0,0) } } diff --git a/src/server/main/Elevators/Map/Haughton/Doors.luau b/src/server/main/Elevators/Map/Haughton/Doors.luau index 06dd9af..4cf9e5c 100644 --- a/src/server/main/Elevators/Map/Haughton/Doors.luau +++ b/src/server/main/Elevators/Map/Haughton/Doors.luau @@ -21,21 +21,16 @@ type Impl_Constructor = { __index: Impl_Constructor, constructor: Constructor_Fun, --Class functions - OpenCabAsync: (self: ClassConstructor, ObjectSpaceDistance: Vector3) -> (), - CloseCabAsync: (self: ClassConstructor, ObjectSpaceDistance: Vector3) -> (), + OpenCabAsync: (self: ClassConstructor) -> (), + CloseCabAsync: (self: ClassConstructor) -> (), OpenAtFloorAsync: (self: ClassConstructor, Floor: number) -> (), CloseAtFloorAsync: (self: ClassConstructor, Floor: number) -> (), } -type CabDoorsTree = { - [number]: {BasePart} -} - type Constructor_Fun = ( DoorConfig: ElevatorEnums.DoorsConfig, ElevatorBox: BasePart, - CabDoorsTree: {BasePart}, - LandingDoorsTree: Tags.LandingTags + DoorsTree: Tags.LandingTags ) -> ClassConstructor type Attributes = { @@ -51,8 +46,7 @@ type Events = { type Constructor_Return_Props = { DoorConfig: ElevatorEnums.DoorsConfig, ElevatorBox: BasePart, - CabDoorsTree: {BasePart}, - LandingDoorsTree: Tags.LandingTags, + DoorsTree: Tags.LandingTags, Attributes: Attributes, __Connections: { @@ -63,15 +57,14 @@ type Constructor_Return_Props = { local Doors = {} :: Impl_Constructor Doors.__index = Doors -function Doors.constructor(DoorConfig, ElevatorBox, CabDoorsTree, LandingDoorsTree) +function Doors.constructor(DoorConfig, ElevatorBox, LandingDoorsTree) local HallOpen = Instance.new("BoolValue") :: BoolValue HallOpen.Value = true return setmetatable({ DoorConfig = DoorConfig, ElevatorBox = ElevatorBox, - CabDoorsTree = CabDoorsTree, - LandingDoorsTree = LandingDoorsTree, + DoorsTree = LandingDoorsTree, Attributes = { Hall = { @@ -106,7 +99,7 @@ type DoorAnimationsMap = { DoubleSpeed: DoorAnimationCallback, TripleSpeed: DoorAnimationCallback, }, - Floor: { + Landing: { SingleSpeed: DoorAnimationCallback, DoubleSpeed: DoorAnimationCallback, TripleSpeed: DoorAnimationCallback, @@ -114,101 +107,135 @@ type DoorAnimationsMap = { } local DoorAnimations = { Cab = {}, - Floor = {} + Landing = {} } :: DoorAnimationsMap --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(OpenToVec1.X, 0, OpenToVec1.Z) + local CabDoor1 = self.DoorsTree.Cab[1] :: BasePart - self.CabDoorsTree[1].Position = ElevatorY+self.CabDoorsTree[1].Position:Lerp(OpenToVec1+ElevatorDoor1_Goal, Algebra.Easing.InOutQuart(AnimationTime)) + CabDoor1.Position = ElevatorY+CabDoor1.Position:Lerp(OpenToVec1+ElevatorDoor1_Goal, Algebra.Easing.OutQuad(AnimationTime)) end function DoorAnimations.Cab.DoubleSpeed(self, AnimationTime, Door1Position, Door2Position, OpenToVec1, OpenToVec2) + local OutQuad = Algebra.Easing.OutQuad(AnimationTime) + local ElevatorY = Vector3.new(0, self.ElevatorBox.Position.Y, 0) + local ElevatorDoor1_Goal = Vector3.new(OpenToVec1.X, 0, OpenToVec1.Z) + local ElevatorDoor2_Goal = Vector3.new(OpenToVec2.X, 0, OpenToVec2.Z) + local CabDoor1 = self.DoorsTree.Cab[1] :: BasePart + local CabDoor2 = self.DoorsTree.Cab[2] :: BasePart + CabDoor1.Position = ElevatorY+CabDoor1.Position:Lerp(ElevatorDoor1_Goal, OutQuad) + CabDoor2.Position = ElevatorY+CabDoor2.Position:Lerp(ElevatorDoor2_Goal, OutQuad) end function DoorAnimations.Cab.TripleSpeed(self, AnimationTime, Door1Position, Door2Position, Door3Position, OpenToVec1, OpenToVec2, OpenToVec3) + local OutQuad = Algebra.Easing.OutQuad(AnimationTime) + local ElevatorY = Vector3.new(0, self.ElevatorBox.Position.Y, 0) + local ElevatorDoor1_Goal = Vector3.new(OpenToVec1.X, 0, OpenToVec1.Z) + local ElevatorDoor2_Goal = Vector3.new(OpenToVec2.X, 0, OpenToVec2.Z) + local ElevatorDoor3_Goal = Vector3.new(OpenToVec3.X, 0, OpenToVec3.Z) + local CabDoor1 = self.DoorsTree.Cab[1] :: BasePart + local CabDoor2 = self.DoorsTree.Cab[2] :: BasePart + local CabDoor3 = self.DoorsTree.Cab[3] :: BasePart + CabDoor1.Position = ElevatorY+CabDoor1.Position:Lerp(ElevatorDoor1_Goal, OutQuad) + CabDoor2.Position = ElevatorY+CabDoor2.Position:Lerp(ElevatorDoor2_Goal, OutQuad) + CabDoor3.Position = ElevatorY+CabDoor3.Position:Lerp(ElevatorDoor3_Goal, OutQuad) end ---- --Floor doors-- -function DoorAnimations.Floor.SingleSpeed(self, Floor, AnimationTime, Door1Position, OpenToVec1) - (self.LandingDoorsTree[Floor][1] :: BasePart).Position = Door1Position:Lerp(OpenToVec1, Algebra.Easing.OutQuad(AnimationTime)) +function DoorAnimations.Landing.SingleSpeed(self, Floor, AnimationTime, Door1Position, OpenToVec1) + (self.DoorsTree.Hall[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 +local function OpenVecTuple(self: ClassConstructor, Opening: boolean, Type: DoorEnums.DoorLocationValues, HallFloor: number?): ...Vector3? + if Type == DoorEnums.DoorLocation.Landing and not HallFloor then + warn("Hall/landing doors were called but no HallFloor number was received") + return nil + end + local DoorsType: {Instance} = Type == DoorEnums.DoorLocation.Cab and self.DoorsTree.Cab or self.DoorsTree.Hall[HallFloor :: number] + local ConfType = Type == DoorEnums.DoorLocation.Cab and self.DoorConfig.Cab or self.DoorConfig.Landing + + if ConfType.Type == DoorEnums.Door.SingleSpeed then + local P = (DoorsType[1] :: BasePart).Position + local Direction = Opening and -ConfType.Goal or ConfType.Goal return table.unpack({ P, - P+(Opening and -self.DoorConfig.Cab.Goal or self.DoorConfig.Cab.Goal) + P+Direction }) - elseif Type == DoorEnums.Door.DoubleSpeed then - local P = (FloorWithDoors[1] :: BasePart).Position - local P2 = (FloorWithDoors[2] :: BasePart).Position + elseif ConfType.Type == DoorEnums.Door.DoubleSpeed then + local P = (DoorsType[1] :: BasePart).Position + local P2 = (DoorsType[2] :: BasePart).Position + local Direction = Opening and -ConfType.Goal or ConfType.Goal 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 + P+Direction, + (P2+Direction)/2 }) - elseif Type == DoorEnums.Door.TripleSpeed then + elseif ConfType.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 + local P = (DoorsType[1] :: BasePart).Position + local P2 = (DoorsType[2] :: BasePart).Position + local P3 = (DoorsType[3] :: BasePart).Position + local Direction = Opening and -ConfType.Goal or ConfType.Goal 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, + P+Direction, + (P2+Direction)/1.5, + (P3+Direction)/2, }) end return nil end -function Doors:OpenCabAsync(ObjectSpaceDistance) - -- 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) - -end - --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) +local function ToggleDoors(self: ClassConstructor, Type: DoorEnums.DoorLocationValues, Opening: boolean, Floor: number?): boolean + local Config: ElevatorEnums.DoorsConfigProperties? = Type == DoorEnums.DoorLocation.Cab and self.DoorConfig.Cab or self.DoorConfig.Landing + if Config then + local P1, P2, P3, P4, P5, P6 = OpenVecTuple(self, Opening, Type, Floor) + if P1 then + if Type == DoorEnums.DoorLocation.Cab then + DoorAnimationRuntime(self, Config.Time, function(self, AnimationTime) + DoorAnimations.Cab[Config.Type](self, AnimationTime, P1, P2, P3, P4, P5, P6) + end) + else + DoorAnimationRuntime(self, Config.Time, function(self, AnimationTime) + DoorAnimations.Landing[Config.Type](self, Floor, AnimationTime, P1, P2, P3, P4, P5, P6) + end) + end + else + return false + end else - warn(`Could not open the door at floor: {Floor}, it does not exist in the landing doors tree.`) + warn("Could not open the elevator doors", debug.traceback()) + return false end + return true +end + +function Doors:OpenCabAsync() + ToggleDoors(self, DoorEnums.DoorLocation.Cab, true) +end + +function Doors:CloseCabAsync() + ToggleDoors(self, DoorEnums.DoorLocation.Cab, false) end function Doors:CloseAtFloorAsync(Floor) - ToggleFloorDoors(self, Floor, false) + ToggleDoors(self, DoorEnums.DoorLocation.Landing, false, Floor) end function Doors:OpenAtFloorAsync(Floor) - ToggleFloorDoors(self, Floor, true) + ToggleDoors(self, DoorEnums.DoorLocation.Landing, true, Floor) end - return Doors \ No newline at end of file diff --git a/src/server/main/Elevators/Map/Haughton/init.luau b/src/server/main/Elevators/Map/Haughton/init.luau index ca0dfcb..29451fe 100644 --- a/src/server/main/Elevators/Map/Haughton/init.luau +++ b/src/server/main/Elevators/Map/Haughton/init.luau @@ -17,7 +17,6 @@ local MovingObjects = require(script:WaitForChild("MovingObjects")) local TractionRopes = require(script:WaitForChild("TractionRopes")) local Doors = require(script:WaitForChild("Doors")) local TagsModule = require(MainDir:WaitForChild("Map"):WaitForChild("Load"):WaitForChild("Tags")) -local DoorEnums = require(MainDir:WaitForChild("Types"):WaitForChild("Enums"):WaitForChild("Doors")) return function(TagsConstructor: TagsModule.TagsConstructor, ButtonTags: TagsModule.ElevatorButtons, LanternTags: TagsModule.Lanterns, LandingDoorTags: TagsModule.LandingTags) local ElevatorModel = TagsConstructor:Request("Elevator_Haughton") :: Model @@ -25,16 +24,13 @@ return function(TagsConstructor: TagsModule.TagsConstructor, ButtonTags: TagsMod local PulleyRopesObject = TagsConstructor:Request("Haughton_Rope_Pulley") :: BasePart local ElevatorBoxModel = ElevatorModel:WaitForChild("Mover") :: BasePart - --TEMP - local CabDoorsTree = {} :: {BasePart} - local Elevator = InitElevator.constructor(ElevatorBoxModel, Config.Elevator, Leveling) local MovingObjectsConstructor = MovingObjects.constructor(TagsConstructor) local ButtonsConstructor = Buttons.constructor(Config.Elevator.Name, ButtonTags, Elevator.Attributes.CurrentFloor) ButtonsConstructor:InitForElevator(2, ButtonPromptsDistance) local TractionRopesConstructor = TractionRopes.constructor(CabRopesObject, PulleyRopesObject) - local DoorsConstructor = Doors.constructor(Config.Doors, ElevatorBoxModel, CabDoorsTree, LandingDoorTags) + local DoorsConstructor = Doors.constructor(Config.Doors, ElevatorBoxModel, LandingDoorTags) local EventsConstructor = Events.constructor( Elevator, Config.Elevator, @@ -47,5 +43,7 @@ return function(TagsConstructor: TagsModule.TagsConstructor, ButtonTags: TagsMod EventsConstructor:InitButtons() task.wait(2) - DoorsConstructor:CloseAtFloorAsync(1) + DoorsConstructor:OpenCabAsync() + task.wait(5) + DoorsConstructor:CloseCabAsync() end diff --git a/src/server/main/Map/Load/Tags/init.luau b/src/server/main/Map/Load/Tags/init.luau index 4857726..8695262 100644 --- a/src/server/main/Map/Load/Tags/init.luau +++ b/src/server/main/Map/Load/Tags/init.luau @@ -140,16 +140,22 @@ export type ExportedTags = { } export type LandingDoors = {Instance} +export type CabDoors = { + [number]: Instance +} export type LandingTags = { - [number]: LandingDoors + Cab: CabDoors, + Hall: { + [number]: LandingDoors + } } export type DoorTags = { [Enums.ElevatorValues]: LandingTags } -export type TagProduct = Instance | {Instance} +export type TagProduct = Instance | {Instance} export type TagsConstructor = ClassConstructor local Tags = {} :: Impl_Constructor @@ -290,7 +296,10 @@ function Tags:__ElevatorDoors() local Doors: DoorTags = {} for _, EnumValue in Enums.Elevator do - Doors[EnumValue :: Enums.ElevatorValues] = {} + Doors[EnumValue :: Enums.ElevatorValues] = { + Hall = {}, + Cab = {} + } for TagName: string, Inst: TagProduct in self.__dump do local Split = TagName:split('_') @@ -303,20 +312,18 @@ function Tags:__ElevatorDoors() if FloorHint:match('^Floor%d+$') then if DoorHint == "Door" then local FloorNumberMatch = FloorHint:match('%d+$') - local FloorNumber = FloorNumberMatch and tonumber(FloorNumberMatch) - + local FloorNumber = FloorNumberMatch and tonumber(FloorNumberMatch) if FloorNumber then local DoorNumberPlacement = tonumber(DoorNumber) - if DoorNumberPlacement then - if not Doors[ModelHint][FloorNumber] then - Doors[ModelHint][FloorNumber] = {} + if not Doors[ModelHint].Hall[FloorNumber] then + Doors[ModelHint].Hall[FloorNumber] = {} end - if typeof(Inst) ~= "Instance" then - Inst = Inst[1] - warn(`[{ModelHint}] Door {Inst} was not a single instance, duplicate doors detected Tag={TagName}`) + if typeof(Inst) == "Instance" then + table.insert(Doors[ModelHint].Hall[FloorNumber], DoorNumberPlacement, Inst) + else + warn(`[{ModelHint}] Door {Inst[1]} was not a single instance, duplicate doors detected Tag={TagName}`) end - table.insert(Doors[ModelHint][FloorNumber], DoorNumberPlacement, Inst :: Instance) else end @@ -326,6 +333,22 @@ function Tags:__ElevatorDoors() else warn(`TODO block hit. Inst={Inst},`, debug.traceback()) end + elseif FloorHint:match('^Cab$') then + if DoorHint == "Door" then + local DoorNumberMatch = DoorNumber:match('^%d+$') + local DoorIndex = DoorNumberMatch and tonumber(DoorNumberMatch) + if DoorIndex then + if not Doors[ModelHint].Cab[DoorIndex] then + if typeof(Inst) == "Instance" then + table.insert(Doors[ModelHint].Cab, DoorIndex, Inst) + else + warn(`[{ModelHint}] Door {Inst[1]} was not a single instance, duplicate doors detected Tag={TagName}`) + end + end + end + else + warn(`Invalid floor label {FloorHint} for door {TagName},`, debug.traceback()) + end end end end diff --git a/src/server/main/Types/Elevator.luau b/src/server/main/Types/Elevator.luau index 9dd9bc6..d079aa0 100644 --- a/src/server/main/Types/Elevator.luau +++ b/src/server/main/Types/Elevator.luau @@ -52,17 +52,15 @@ export type ElevatorConfigurationTable = { Colors: Colors, } +export type DoorsConfigProperties = { + Type: DoorEnums.DoorEnumValues, + Time: number, + Goal: Vector3 +} + export type DoorsConfig = { - Cab: { - Type: DoorEnums.DoorEnumValues, - Time: number, - Goal: Vector3 - }, - Landing: { - Type: DoorEnums.DoorEnumValues, - Time: number, - Goal: Vector3 - } + Cab: DoorsConfigProperties, + Landing: DoorsConfigProperties } return nil