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

View File

@@ -0,0 +1,107 @@
--!optimize 2
--!strict
local ParentDir = script.Parent
local MapDir = ParentDir.Parent
local ElevatorDir = MapDir.Parent
local MainDir = ElevatorDir.Parent
local TagsModule = MainDir:WaitForChild("Map"):WaitForChild("Load"):WaitForChild("Tags")
local StorageService = game:GetService("ReplicatedStorage")
local Enums = require(StorageService:WaitForChild("Enums"))
local ButtonTags = require(TagsModule:WaitForChild("Buttons"))
local Tags = require(TagsModule)
local ButtonManager = require(ElevatorDir:WaitForChild("ButtonManager"))
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
InitForElevator: (self: ClassConstructor, MaxActivationDistance: number?, AddedOffset: Vector3?) -> (),
Get: (self: ClassConstructor, ButtonType: Enums.ButtonTreeValues, ButtonID: number) -> Tags.ButtonProperties?
}
type Constructor_Fun = (
ElevatorModel: Enums.ElevatorValues,
ButtonTags: Tags.ElevatorButtons,
CurrentFloor: IntValue
) -> ClassConstructor
type Constructor_Return_Props = {
ElevatorModel: Enums.ElevatorValues,
ButtonTags: Tags.ElevatorButtons,
CurrentFloor: IntValue,
Events: Events,
__PromptButtons__: Tags.ButtonsTree?
}
export type Events = {
FloorButtonActivated: RBXScriptSignal<boolean, number, Tags.ButtonProperties>,
__eventInstances__: {
FloorButtonActivated: BindableEvent
}
}
export type constructor = ClassConstructor
local Buttons = {} :: Impl_Constructor
Buttons.__index = Buttons
function Buttons.constructor(ElevatorModel, ButtonTags, CurrentFloor)
local ButtonActivated = Instance.new("BindableEvent") :: BindableEvent
return setmetatable({
ElevatorModel = ElevatorModel,
ButtonTags = ButtonTags,
CurrentFloor = CurrentFloor,
Events = {
FloorButtonActivated = ButtonActivated.Event,
__eventInstances__ = {
FloorButtonActivated = ButtonActivated
}
}
}, Buttons)
end
function Buttons:InitForElevator(MaxActivationDistance, AddedOffset)
MaxActivationDistance = MaxActivationDistance or ButtonTags.DefaultMaxActivationDistance
AddedOffset = AddedOffset or Vector3.zero
local ButtonManagerConstructor = ButtonManager.constructor(self.CurrentFloor)
local ButtonTagsConstructor = ButtonTags.constructor(self.ButtonTags, self.ElevatorModel)
self.__PromptButtons__ = ButtonTagsConstructor:CreatePromptButtons()
local CarButtonPrompts = (self.__PromptButtons__ :: Tags.ButtonsTree)[self.ElevatorModel].Car
for PromptType, PromptProperties in CarButtonPrompts do
PromptProperties.Prompt.MaxActivationDistance = MaxActivationDistance :: number
PromptProperties.Attachment.Position+=AddedOffset :: Vector3
ButtonManagerConstructor:CarButton(PromptType, PromptProperties, function(ButtonFloor: number)
self.Events.__eventInstances__.FloorButtonActivated:Fire(true, ButtonFloor, PromptProperties)
end, function(ButtonFloor: number)
self.Events.__eventInstances__.FloorButtonActivated:Fire(false, ButtonFloor, PromptProperties)
end)
end
end
function Buttons:Get(ButtonType, ButtonName)
assert(self.__PromptButtons__, `Initialize the elevator buttons first before using :Get, self.__PromptButtons__={self.__PromptButtons__}`)
local Button = self.__PromptButtons__[self.ElevatorModel][ButtonType] :: Tags.ButtonDictionary?
if Button then
--mega cringe
for ButtonFullName: string, ButtonProps: Tags.ButtonProperties in Button do
if ButtonProps.ID == ButtonName then
return ButtonProps
end
end
end
return nil
end
return Buttons