mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
Introduce Ready attribute for moving
This commit is contained in:
@@ -72,10 +72,6 @@ Doors.Attributes = {
|
||||
|
||||
Doors.Attributes.Open.Value = false
|
||||
|
||||
Doors.Attributes.Open:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
print("Open=",Doors.Attributes.Open.Value)
|
||||
end)
|
||||
|
||||
local Attributes = Doors.Attributes
|
||||
|
||||
function Doors.constructor(FloorDoorsTags, ElevatorBox, ElevatorDoor1, ElevatorDoor2, ElevatorDoorSensor)
|
||||
@@ -198,8 +194,6 @@ local function ElevatorDoorsAnimation(self: ClassConstructor, opening: boolean?,
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
Attributes.Open.Value = true
|
||||
else
|
||||
local Door1Tween = self.DoorTween1:Start(nil, {
|
||||
Position = ElevatorDoor1_P+Doors.Door1Stopped_X
|
||||
@@ -274,16 +268,12 @@ end
|
||||
function Doors:ToggleElevatorDoorsAsync(opening, floor)
|
||||
--short circuiting central
|
||||
if opening then
|
||||
if not Attributes.Open.Value then
|
||||
Attributes.Open.Value = not Attributes.Open.Value
|
||||
else
|
||||
if Attributes.Open.Value then
|
||||
warn("Doors are already closed, doing nothing")
|
||||
return
|
||||
end
|
||||
else
|
||||
if Attributes.Open.Value then
|
||||
Attributes.Open.Value = not Attributes.Open.Value
|
||||
else
|
||||
if not Attributes.Open.Value then
|
||||
warn("Doors are already open, doing nothing")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -58,8 +58,8 @@ type Impl_Constructor = {
|
||||
FloorPassingUp: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
|
||||
FloorPassingDown: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
|
||||
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
|
||||
__Move: (self: ClassConstructor, Level: number, GoingUp: boolean) -> (),
|
||||
__MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean) -> (),
|
||||
__MoveTo: (self: ClassConstructor, GoingUp: boolean, GoalFloor_Y: number) -> (),
|
||||
__MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean, GoalFloor_Y: number) -> (),
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
@@ -84,6 +84,8 @@ type Impl_Static_Props = {
|
||||
Attributes: {
|
||||
CurrentFloor: IntValue,
|
||||
Goal: IntValue,
|
||||
GoalYLevel: NumberValue,
|
||||
Ready: BoolValue,
|
||||
Moving: BoolValue,
|
||||
GoingUp: BoolValue,
|
||||
Stopped: BoolValue
|
||||
@@ -147,6 +149,8 @@ Elevator.Colors = {
|
||||
Elevator.Attributes = {
|
||||
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
|
||||
Ready = Instance.new("BoolValue") :: BoolValue,
|
||||
Moving = Instance.new("BoolValue") :: BoolValue,
|
||||
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
||||
Stopped = Instance.new("BoolValue") :: BoolValue
|
||||
@@ -158,6 +162,7 @@ Elevator.Events = {
|
||||
|
||||
Elevator.Attributes.CurrentFloor.Value = 1
|
||||
Elevator.Attributes.Goal.Value = 1
|
||||
Elevator.Attributes.Ready.Value = false
|
||||
Elevator.Attributes.Moving.Value = false
|
||||
Elevator.Attributes.GoingUp.Value = false
|
||||
|
||||
@@ -221,7 +226,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
|
||||
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
|
||||
|
||||
self.LanternsConstructor:Reset()
|
||||
self:__GoToFloor(Leveling[Attributes.CurrentFloor.Value], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Goal.Value))
|
||||
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Goal.Value), Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||
end
|
||||
end)
|
||||
@@ -310,6 +315,17 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
||||
end)
|
||||
|
||||
--This is how the elevator logic works with the elevator itself
|
||||
Attributes.Ready:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
if Attributes.Ready.Value then
|
||||
self.BoxAlignPosition.Position = Vector3.new(self.ElevatorBox_1960.Position.X, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], self.ElevatorBox_1960.Position.Z)
|
||||
end
|
||||
end)
|
||||
Doors.Attributes.Open:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
print(Doors.Attributes.Open.Value)
|
||||
Attributes.Ready.Value = not Doors.Attributes.Open.Value
|
||||
end)
|
||||
|
||||
print(`🔝 {Elevator.Name} initialized and ready`)
|
||||
return ClassConstructor
|
||||
end
|
||||
@@ -327,7 +343,7 @@ function Elevator:Leveled(RequestedLevel)
|
||||
|
||||
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then
|
||||
--More floors in the queue
|
||||
self:__Move(Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorGoingUp)
|
||||
self:__MoveTo(ElevatorGoingUp, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -354,12 +370,13 @@ function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
|
||||
end
|
||||
end
|
||||
|
||||
function Elevator:__MovingHeartbeat(GoingUp)
|
||||
function Elevator:__MovingHeartbeat(GoingUp, GoalFloor_Y)
|
||||
Attributes.GoingUp.Value = GoingUp
|
||||
|
||||
if self.__MovingConnection and self.__MovingConnection.Connected then
|
||||
self.__MovingConnection:Disconnect()
|
||||
end
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
|
||||
local Delta = 0
|
||||
local DoorsOpeningEvent = false
|
||||
@@ -414,7 +431,7 @@ function Elevator:__MovingHeartbeat(GoingUp)
|
||||
end)
|
||||
end
|
||||
|
||||
function Elevator:__Move(GoalLevelVEC, GoingUp)
|
||||
function Elevator:__MoveTo(GoingUp, GoalFloor_Y)
|
||||
if Doors.Attributes.Open.Value then
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
|
||||
end
|
||||
@@ -424,28 +441,18 @@ function Elevator:__Move(GoalLevelVEC, GoingUp)
|
||||
self.LanternsConstructor:DirectionDown(true)
|
||||
end
|
||||
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
self:__MovingHeartbeat(GoingUp)
|
||||
|
||||
local ElevatorPositionInit = self.ElevatorBox_1960.Position
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, GoalLevelVEC, ElevatorPositionInit.Z)
|
||||
self:__MovingHeartbeat(GoingUp, GoalFloor_Y)
|
||||
end
|
||||
|
||||
function Elevator:RequestLevel(RequestedLevel)
|
||||
local GoalLevelVEC: number? = Leveling[RequestedLevel]
|
||||
local GoalFloor_Y: number? = Leveling[RequestedLevel]
|
||||
|
||||
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then
|
||||
if GoalFloor_Y and RequestedLevel ~= Attributes.CurrentFloor.Value then
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
if Proceeding then
|
||||
self:__Move(GoalLevelVEC, ElevatorGoingUp)
|
||||
else
|
||||
if not Doors.Attributes.Open.Value then
|
||||
local ElevatorPositionInit = self.ElevatorBox_1960.Position
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorPositionInit.Z)
|
||||
print(Doors.Attributes.Open.Value)
|
||||
end
|
||||
if Doors.Attributes.Open.Value then
|
||||
self:__MoveTo(ElevatorGoingUp, GoalFloor_Y)
|
||||
end
|
||||
else
|
||||
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
||||
|
||||
Reference in New Issue
Block a user