buttons need big refactored and working hall floor displays

This commit is contained in:
2024-05-10 01:00:02 -04:00
parent 1aac88b3b4
commit 17193ac908
10 changed files with 314 additions and 267 deletions

View File

@@ -1,12 +0,0 @@
--!optimize 2
--!native
--!strict
local ButtonFunctions = {}
ButtonFunctions.__index = ButtonFunctions
return ButtonFunctions

View File

@@ -11,7 +11,7 @@ type Impl_Constructor = {
--Class functions
BindHallDisplays: (self: ClassConstructor) -> (),
UnBindHallDisplays: (self: ClassConstructor) -> (),
SetHallDisplays: (self: ClassConstructor, floor: string) -> ()
SetHallDisplays: (self: ClassConstructor, floor: string | number) -> ()
}
type Constructor_Fun = (CurrentFloorAttribute: IntValue, HallDisplayTags: HallDisplays) -> ClassConstructor
@@ -34,15 +34,17 @@ function HallDisplays.constructor(CurrentFloorAttribute, HallDisplayTags)
end
function HallDisplays:SetHallDisplays(floor)
local FloorString = tostring(floor)
for i = 1, #self.HallDisplayTags do
(self.HallDisplayTags[i] :: TextLabel).Text = floor
(self.HallDisplayTags[i] :: TextLabel).Text = FloorString
end
end
function HallDisplays:BindHallDisplays()
self:UnBindHallDisplays()
self.__CurrentFloorConnection = self.CurrentFloorAttribute:GetPropertyChangedSignal("Value"):Connect(function()
self:SetHallDisplays(tostring(self.CurrentFloorAttribute.Value))
self:SetHallDisplays(self.CurrentFloorAttribute.Value)
end)
end

View File

@@ -44,12 +44,9 @@ export type MovingObjectsConstructor = ClassConstructor
local MovingObjects = {} :: Impl_Constructor
MovingObjects.__index = MovingObjects
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tween = require(Storage:WaitForChild("Tween"))
local Easing = require(Storage:WaitForChild("Algebra"))
function MovingObjects.constructor(InstanceTree)
local self = InstanceTree :: Constructor_Return_Props
self.MachineRoom._CFrame.PulleyCFrame = InstanceTree.MachineRoom.Pulley.CFrame
self.MachineRoom._CFrame.Pulley2CFrame = InstanceTree.MachineRoom.Pulley2.CFrame
self.MachineRoom._CFrame.GovernorCFrame = InstanceTree.MachineRoom.Governor.CFrame

View File

@@ -6,8 +6,8 @@ local Elevators = script.Parent
local MainDir = Elevators.Parent
local LoadDir = MainDir:WaitForChild("Load")
local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
local RS: RunService = game:GetService("RunService")
local Storage = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")
local Enums = require(Storage:WaitForChild("Enums"))
@@ -21,8 +21,7 @@ local ButtonTags = require(Elevators:WaitForChild("Buttons"))
local TractionRopes = require(Elevators:WaitForChild("TractionRopes"))
local Lanterns = require(Elevators:WaitForChild("Lanterns"))
local PromptModule = require(MainDir:WaitForChild("Map"):WaitForChild("Prompts"))
local Tags = require(LoadDir:WaitForChild("Tags"))
local Tags = require(LoadDir:WaitForChild("Tags"))
type rbxassetid = string
@@ -39,6 +38,7 @@ type Impl_Constructor = {
} & Impl_Static_Props
type Impl_Static_Props = {
Name: Enums.ElevatorValues,
Responsiveness: number,
MaxVelocity: number,
ButtonActivatedColor: Color3,
@@ -50,46 +50,49 @@ type Impl_Static_Props = {
FloorLevelingDistance: number,
DoorOpeningDistance: number,
LeveledDistance: number,
Attributes: {
PassingFloor: IntValue,
Moving: BoolValue,
CurrentFloor: IntValue
},
Events: {
ButtonActivated: BindableEvent
}
}
type Constructor_Fun = (TagsConstructor: TagsConstructor, ButtonsTags: Tags.ElevatorButtons, LanternsTags: Tags.Lanterns, LandingDoors: Tags.LandingTags) -> ClassConstructor
type Constructor_Return_Props = {
Tags: Tags,
MOConstructor: MovingObjects.MovingObjectsConstructor,
LanternsConstructor: Lanterns.LanternsConstructor,
ElevatorBox_1960: UnionOperation,
ElevatorDoor1: BasePart,
ElevatorDoor2: BasePart,
ElevatorDoorSensor: Folder,
BoxAttachment: Attachment,
BoxAlignPosition: AlignPosition,
BoxAlignOrientation: AlignOrientation,
ElevatorDoors: Doors.DoorConstructor,
Ropes: {Instance},
TractionRopes: TractionRopes.TractionRopesConstructor,
Pulley: UnionOperation,
Pulley2: UnionOperation,
Governor: UnionOperation,
GovernorFlyballs: Part,
PieplatePulley: UnionOperation,
MachineRoom: MovingObjects.MachineRoom,
HallDisplays: {Instance},
__MovingConnection: RBXScriptConnection?,
Tags: Tags,
MOConstructor: MovingObjects.MovingObjectsConstructor,
LanternsConstructor: Lanterns.LanternsConstructor,
HallDisplaysConstructor: HallDisplays.HallDisplaysConstructor,
ElevatorBox_1960: UnionOperation,
ElevatorDoor1: BasePart,
ElevatorDoor2: BasePart,
ElevatorDoorSensor: Folder,
BoxAttachment: Attachment,
BoxAlignPosition: AlignPosition,
BoxAlignOrientation: AlignOrientation,
ElevatorDoors: Doors.DoorConstructor,
Ropes: {Instance},
TractionRopes: TractionRopes.TractionRopesConstructor,
Pulley: UnionOperation,
Pulley2: UnionOperation,
Governor: UnionOperation,
GovernorFlyballs: Part,
PieplatePulley: UnionOperation,
MachineRoom: MovingObjects.MachineRoom,
HallDisplays: {Instance},
__MovingConnection: RBXScriptConnection?,
}
type ButtonFunction = (self: ClassConstructor, ButtonName: string, ButtonsConstructor: ButtonTags.ButtonsConstructor, ButtonTree: Tags.ButtonProperties) -> ()
type ButtonFunctions = {
[Enums.ButtonTreeValues]: ButtonFunction
}
export type Otis1960Constructor = ClassConstructor
local Otis1960 = {} :: Impl_Constructor
Otis1960.__index = Otis1960
Otis1960.Name = Enums.Elevator.Otis1960
Otis1960.FloorLevelingDistance = 2.5
Otis1960.DoorOpeningDistance = Otis1960.FloorLevelingDistance/2.8
Otis1960.LeveledDistance = 0.5
@@ -108,54 +111,25 @@ Otis1960.Attributes = {
CurrentFloor = Instance.new("IntValue") :: IntValue
}
Otis1960.Events = {
ButtonActivated = Instance.new("BindableEvent") :: BindableEvent
}
Otis1960.Attributes.PassingFloor.Value = 1
Otis1960.Attributes.Moving.Value = false
Otis1960.Attributes.CurrentFloor.Value = 1
local Attributes = Otis1960.Attributes
local ButtonFunctions: ButtonFunctions = {
[Enums.ButtonTree.Landing] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
end,
[Enums.ButtonTree.Car] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
local DecodedFloor = Tags.Decoders.CarTag(ButtonName)
if DecodedFloor then
local Prompt = PromptModule.constructor(ButtonTree.Prompt :: ProximityPrompt, ButtonTree.Inst :: Instance)
Prompt:AddHookTriggered(function(Player: Player)
if DecodedFloor then
task.spawn(function()
ButtonsConstructor:AestheticActivateButton(ButtonTree.Inst :: BasePart, Otis1960.ButtonActivatedColor)
if DecodedFloor == Attributes.CurrentFloor.Value then
ButtonsConstructor:DeactivateButton(ButtonTree.Inst :: BasePart, Otis1960.ButtonDeactivatedColor)
end
end)
if DecodedFloor ~= Attributes.CurrentFloor.Value then
self:GoToLevel(DecodedFloor)
end
end
end)
else
warn(`Otis1960: Failed to decode car button, ButtonName={ButtonName}`)
end
end,
[Enums.ButtonTree.Special] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
end
}
local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTags.ButtonsConstructor, ButtonType: Enums.EnumValue)
local ButtonFunctions = require(script:WaitForChild("ButtonFunctions"))
for ButtonNameType, ButtonList in ButtonsConstructor.Buttons do
for ButtonName, ButtonTree in ButtonList do
if ButtonTree.Prompt then
if ButtonTree.Inst then
local Button = ButtonFunctions[ButtonNameType :: Enums.ButtonTreeValues]
if Button then
Button(self, ButtonName, ButtonsConstructor, ButtonTree)
end
@@ -171,6 +145,9 @@ end
function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
local self = {} :: Constructor_Return_Props
self.MachineRoom = {_CFrame = {}} :: MovingObjects.MachineRoom
self.ElevatorBox_1960 = TagsConstructor:Request("ElevatorMover_1960") :: UnionOperation
self.ElevatorDoor1 = TagsConstructor:Request("ElevatorDoor_1960_1") :: BasePart
self.ElevatorDoor2 = TagsConstructor:Request("ElevatorDoor_1960_2") :: BasePart
@@ -178,8 +155,6 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.Ropes = TagsConstructor:Request("1960_ElevatorPulleyRope") :: {Instance}
self.HallDisplays = TagsConstructor:Request("Otis1960_LandingFloorDisplay") :: {Instance}
--Rotation objects
self.MachineRoom = {_CFrame = {}} :: MovingObjects.MachineRoom
self.MachineRoom.Pulley = TagsConstructor:Request("Otis1960_Pulley") :: UnionOperation
self.MachineRoom.Pulley2 = TagsConstructor:Request("Otis1960_Pulley2") :: UnionOperation
self.MachineRoom.Governor = TagsConstructor:Request("Otis1960_Governor") :: UnionOperation
@@ -187,38 +162,41 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
self.MachineRoom.PiePlatePulley = TagsConstructor:Request("Otis1960_PieplatePulley") :: UnionOperation
self.MachineRoom.PiePlatePlates = TagsConstructor:Request("Otis1960_PiePlatePlates") :: UnionOperation
self.MachineRoom.PiePlateSelector = TagsConstructor:Request("Otis1960_PiePlateSelector") :: UnionOperation
self.MOConstructor = MovingObjects.constructor({MachineRoom = self.MachineRoom} :: MovingObjects.InstanceTree)
--Audio
local LanternDisplay = TagsConstructor:Request("Otis1960_LanternDisplayMain") :: UnionOperation
self.MOConstructor = MovingObjects.constructor({
MachineRoom = self.MachineRoom
} :: MovingObjects.InstanceTree)
self.HallDisplaysConstructor = HallDisplays.constructor(Attributes.CurrentFloor, self.HallDisplays)
self.ElevatorDoors = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
self.TractionRopes = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, Leveling)
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, Otis1960.LanternChimeDirection, Otis1960.LanternChimeLanding, LanternsTags, {
Active = Otis1960.LanternDisplayColorOn,
Off = Otis1960.LanternDisplayColorOff
} :: Lanterns.Colors)
local ButtonsConstructor = ButtonTags.constructor(TagsConstructor, ButtonsTags)
local Otis1960_Buttons = ButtonsConstructor:CreatePromptButtons()
self.HallDisplaysConstructor:BindHallDisplays()
self.BoxAttachment,
self.BoxAlignPosition,
self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position, Otis1960.Responsiveness, Otis1960.MaxVelocity)
self.ElevatorDoors = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
self.TractionRopes = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, Leveling)
--Buttons
local ButtonsConstructor = ButtonTags.constructor(TagsConstructor, ButtonsTags)
local Otis1960_Buttons = ButtonsConstructor:CreatePromptButtons()
local ClassConstructor = setmetatable(self, Otis1960)
HookButtons(ClassConstructor, ButtonsConstructor, Enums.ButtonTree.Car)
--Open the elevator doors on server start
task.spawn(function()
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
self.HallDisplaysConstructor:SetHallDisplays(Attributes.CurrentFloor.Value)
self.ElevatorDoors:ToggleElevatorDoors(true, Attributes.CurrentFloor.Value)
end)
print("🔝 Otis1960 initialized and ready")
print(`🔝 {Otis1960.Name} initialized and ready`)
return ClassConstructor
end
@@ -331,7 +309,7 @@ function Otis1960:GoToLevel(RequestedLevel)
self:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
else
warn(`[{Enums.Elevator.Otis1960}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
warn(`[{Otis1960.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
end
end