work on doors and think of algorithm more

This commit is contained in:
2024-05-11 18:26:02 -04:00
parent 4043195793
commit 438abcca56
3 changed files with 94 additions and 58 deletions

View File

@@ -61,7 +61,8 @@ type Impl_Static_Props = {
Attributes: {
PassingFloor: IntValue,
CurrentFloor: IntValue,
Moving: BoolValue
Moving: BoolValue,
GoingUp: BoolValue
},
Events: {
ButtonActivated: BindableEvent
@@ -70,28 +71,28 @@ type Impl_Static_Props = {
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,
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?,
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,
ElevatorDoorsConstructor: Doors.DoorConstructor,
Ropes: {Instance},
TractionRopesConstructor: TractionRopes.TractionRopesConstructor,
Pulley: UnionOperation,
Pulley2: UnionOperation,
Governor: UnionOperation,
GovernorFlyballs: Part,
PieplatePulley: UnionOperation,
MachineRoom: MovingObjects.MachineRoom,
HallDisplays: {Instance},
__MovingConnection: RBXScriptConnection?,
}
export type Otis1960Constructor = ClassConstructor
@@ -121,7 +122,8 @@ Otis1960.Colors = {
Otis1960.Attributes = {
PassingFloor = Instance.new("IntValue") :: IntValue,
CurrentFloor = Instance.new("IntValue") :: IntValue,
Moving = Instance.new("BoolValue") :: BoolValue
Moving = Instance.new("BoolValue") :: BoolValue,
GoingUp = Instance.new("BoolValue") :: BoolValue
}
Otis1960.Events = {
@@ -131,9 +133,15 @@ Otis1960.Events = {
Otis1960.Attributes.PassingFloor.Value = 1
Otis1960.Attributes.CurrentFloor.Value = 1
Otis1960.Attributes.Moving.Value = false
Otis1960.Attributes.GoingUp.Value = false
local Attributes = Otis1960.Attributes
--My clever math function for determining if the elevator goal is to move upwards or not
local function ElevatorGoingUpDirection(Floor: number, RequestedFloor: number): boolean
return -(Floor-RequestedFloor)>0
end
local ButtonsConstructor = Buttons.constructor(Otis1960.Attributes, Otis1960.Events, Otis1960.Colors)
local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonTreeValues, ButtonName: string, ButtonTree)
@@ -197,9 +205,9 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
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.HallDisplaysConstructor = HallDisplays.constructor(Attributes.CurrentFloor, self.HallDisplays)
self.ElevatorDoorsConstructor = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
self.TractionRopesConstructor = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, Leveling)
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, LanternsTags, Otis1960.Sounds, Otis1960.Colors)
@@ -219,13 +227,19 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
task.spawn(function()
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
self.HallDisplaysConstructor:SetHallDisplays(Attributes.CurrentFloor.Value)
self.ElevatorDoors:ToggleElevatorDoors(true, Attributes.CurrentFloor.Value)
self.ElevatorDoorsConstructor:ToggleElevatorDoors(true, Attributes.CurrentFloor.Value)
end)
print(`🔝 {Otis1960.Name} initialized and ready`)
return ClassConstructor
end
local FloorQueue = {}
local function CheckQueue()
end
local function FloorLeveling(self: ClassConstructor, RequestedLevel: number)
self.BoxAlignPosition.MaxVelocity = 1
self.LanternsConstructor:Toggle(true, RequestedLevel)
@@ -239,10 +253,14 @@ local function FloorLeveled(self: ClassConstructor, RequestedLevel: number)
self.BoxAlignPosition.MaxVelocity = Otis1960.MaxVelocity
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
end
local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
if ElevatorPositionY>=Leveling[Attributes.CurrentFloor.Value+1] then
local CF = Attributes.CurrentFloor.Value
if ElevatorPositionY>=Leveling[CF+1] then
Attributes.CurrentFloor.Value+=1
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
@@ -259,10 +277,8 @@ local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: numbe
end
end
local FloorQueue = {}
function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
self.ElevatorDoors:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
self.ElevatorDoorsConstructor:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
if self.__MovingConnection and self.__MovingConnection.Connected then
self.__MovingConnection:Disconnect()
@@ -289,7 +305,7 @@ function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
local BoxAlignY: number = self.BoxAlignPosition.Position.Y
local ElevatorVelocityY: number = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
self.TractionRopes:Move(27, self.ElevatorBox_1960.Position)
self.TractionRopesConstructor:Move(27, self.ElevatorBox_1960.Position)
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
--Kill the connection
@@ -301,7 +317,7 @@ function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance then
DoorsOpeningEvent = true
self.ElevatorDoors:ToggleElevatorDoors(true, RequestedLevel)
self.ElevatorDoorsConstructor:ToggleElevatorDoors(true, RequestedLevel)
end
end
@@ -316,7 +332,7 @@ function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance then
DoorsOpeningEvent = true
self.ElevatorDoors:ToggleElevatorDoors(true, RequestedLevel)
self.ElevatorDoorsConstructor:ToggleElevatorDoors(true, RequestedLevel)
end
end
@@ -329,19 +345,17 @@ function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z)
end
--My clever math function for determining if the elevator goal is to move upwards or not
local function ElevatorDirectionGoingUp(Floor: number, RequestedFloor: number): boolean
return -(Floor-RequestedFloor)>0
end
function Otis1960:RequestLevel(RequestedLevel)
local GoalLevelVEC: number = Leveling[RequestedLevel]
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then
local GoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
if Attributes.Moving.Value then
else
self:__RequestFloor(GoalLevelVEC, RequestedLevel, ElevatorDirectionGoingUp(Attributes.CurrentFloor.Value, RequestedLevel))
Attributes.GoingUp.Value = GoingUp
self:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
end
else
warn(`[{Otis1960.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)