the new structure

This commit is contained in:
2024-09-13 17:35:45 -04:00
parent 991da97c9f
commit fe2dfca727
5 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,105 @@
--!optimize 2
--!strict
local ParentDir = script.Parent
local ElevatorDir = ParentDir.Parent
local ElevatorsDir = ElevatorDir.Parent.Parent
local MainDir = ElevatorsDir.Parent
local StorageService = game:GetService("ReplicatedStorage")
local Enums = require(StorageService:WaitForChild("Enums"))
local InitElevator = require(ElevatorsDir:WaitForChild("System"))
local Buttons = require(ElevatorDir:WaitForChild("Buttons"))
local Doors = require(ElevatorDir:WaitForChild("Doors"))
local TagsModule = require(MainDir:WaitForChild("Map"):WaitForChild("Load"):WaitForChild("Tags"))
local ElevatorTypes = require(MainDir:WaitForChild("Types"):WaitForChild("Elevator"))
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
Events: (self: ClassConstructor) -> ()
}
type Constructor_Fun = (
ElevatorConfig: ElevatorTypes.ElevatorConfigurationTable,
ElevatorConstructor: InitElevator.constructor,
DoorsConstructor: Doors.constructor,
ButtonsConstructor: Buttons.constructor
) -> ClassConstructor
type Constructor_Return_Props = {
ElevatorConfig: ElevatorTypes.ElevatorConfigurationTable,
ElevatorConstructor: InitElevator.constructor,
DoorsConstructor: Doors.constructor,
ButtonsConstructor: Buttons.constructor
}
local ButtonEvents = {} :: Impl_Constructor
ButtonEvents.__index = ButtonEvents
function ButtonEvents.constructor(ElevatorConfig, ElevatorConstructor, DoorsConstructor, ButtonsConstructor)
return setmetatable({
ElevatorConfig = ElevatorConfig,
ElevatorConstructor = ElevatorConstructor,
DoorsConstructor = DoorsConstructor,
ButtonsConstructor = ButtonsConstructor
}, ButtonEvents)
end
local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean
return CurrentFloor<RequestedFloor
end
local function DeactivateButton(self: ClassConstructor, Properties: TagsModule.ButtonProperties)
(Properties.Inst :: BasePart).Color = self.ElevatorConfig.Colors.ButtonDeactivated.Color;
(Properties.Inst :: BasePart).Material = self.ElevatorConfig.Colors.ButtonDeactivated.Material
Properties.Prompt.Enabled = true
end
local function ActivateButton(self: ClassConstructor, Properties: TagsModule.ButtonProperties)
Properties.Prompt.Enabled = false
(Properties.Inst :: BasePart).Color = self.ElevatorConfig.Colors.ButtonActivated.Color;
(Properties.Inst :: BasePart).Material = self.ElevatorConfig.Colors.ButtonActivated.Material
end
local function ButtonAttributes(self: ClassConstructor)
local Attributes = self.ElevatorConstructor.Attributes
Attributes.CurrentFloor:GetPropertyChangedSignal("Value"):Connect(function()
if Attributes.CurrentFloor.Value == Attributes.Goal.Value then
local FloorButton = self.ButtonsConstructor:Get(Enums.ButtonTree.Car, Attributes.CurrentFloor.Value)
if FloorButton then
DeactivateButton(self, FloorButton)
end
end
end)
end
function ButtonEvents:Events()
self.ElevatorConstructor.RelayAlgorithm.Events.Added:Connect(function(_Direction: Enums.ElevatorCallDirectionValues, AddedFloor: number)
local FloorButton = self.ButtonsConstructor:Get(Enums.ButtonTree.Car, AddedFloor)
if FloorButton then
ActivateButton(self, FloorButton)
end
end)
self.ButtonsConstructor.Events.FloorButtonActivated:Connect(function(Success: boolean, Floor: number, Properties: TagsModule.ButtonProperties)
if Success then
if self.DoorsConstructor:CloseAtFloor(self.ElevatorConstructor.Attributes.CurrentFloor.Value) then
self.DoorsConstructor:CloseCabAsync()
end
local Direction = ElevatorGoingUpDirection(self.ElevatorConstructor.Attributes.CurrentFloor.Value, Floor) and Enums.ElevatorCallDirection.Up or Enums.ElevatorCallDirection.Down
self.ElevatorConstructor:RequestLevelAsync(Floor, Direction :: Enums.ElevatorCallDirectionValues)
else
ActivateButton(self, Properties)
task.wait(.45)
DeactivateButton(self, Properties)
end
end)
ButtonAttributes(self)
end
return ButtonEvents