Floor algorithm needs big rework

This commit is contained in:
2024-05-20 01:42:01 -04:00
parent 1cc658c330
commit b67c70aad1
4 changed files with 121 additions and 90 deletions

View File

@@ -2,7 +2,39 @@
--!native
--!strict
local RelayAlgorithm = {}
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
Insert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
}
type Constructor_Fun = (BoxAlignPosition: AlignPosition, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes) -> ClassConstructor
type Constructor_Return_Props = {
BoxAlignPosition: AlignPosition,
ElevatorAttributes: ElevatorAttributes,
DoorAttributes: DoorAttributes,
__FloorQueue: Floors
}
type Floors = {number}
type ElevatorAttributes = {
CurrentFloor: IntValue,
GoingUp: BoolValue,
GoalFloor: IntValue
}
type DoorAttributes = {
DoorsOpen: BoolValue
}
export type RelayAlgorithmConstructor = ClassConstructor
local RelayAlgorithm = {} :: Impl_Constructor
RelayAlgorithm.__index = RelayAlgorithm
function RelayAlgorithm.constructor(BoxAlignPosition, ElevatorAttributes, DoorAttributes)
@@ -50,12 +82,7 @@ function RelayAlgorithm:Check(ElevatorGoingUp)
table.remove(self.__FloorQueue, 1)
end
if #self.__FloorQueue ~= 0 then
--local ElevatorGoingUp = ElevatorGoingUpDirection(self.Attributes.CurrentFloor.Value, self.__FloorQueue[1])
--self.Attributes.GoingUp.Value = ElevatorGoingUp
self:SortQueue(ElevatorGoingUp)
--self:__GoToFloor(Leveling[self.__FloorQueue[1]], ElevatorGoingUp)
self:Sort(ElevatorGoingUp)
return true
end
@@ -64,26 +91,7 @@ end
function RelayAlgorithm:Insert(ElevatorGoingUp, RequestedLevel)
table.insert(self.__FloorQueue, ElevatorGoingUp == self.ElevatorAttributes.GoingUp.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
self:SortQueue(ElevatorGoingUp)
self:Sort(ElevatorGoingUp)
end
function RelayAlgorithm:Proceed(ElevatorGoingUp, RequestedLevel)
self:Insert(RequestedLevel, ElevatorGoingUp)
return self.ElevatorAttributes.GoingUp.Value and not self.DoorAttributes.DoorsOpen.Value
end
--[==[
local function ToFloorQueue(self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number, GoalLevelVEC: number)
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
InsertFloorQueue(self, RequestedLevel, ElevatorGoingUp)
if ElevatorGoingUp == Attributes.GoingUp.Value and not Doors.Attributes.DoorsOpen.Value then
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, self.__FloorQueue[1], ElevatorBoxCurrentPos.Z)
end
end
]==]--
return RelayAlgorithm