From 5018a8ef3b6d1856a6c1f3859951791dbf375b13 Mon Sep 17 00:00:00 2001 From: unittensor Date: Mon, 13 May 2024 01:31:10 -0400 Subject: [PATCH] fix relay offset for prompts --- src/server/main/Elevators/Otis1960/init.lua | 80 +++++++++++++-------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/src/server/main/Elevators/Otis1960/init.lua b/src/server/main/Elevators/Otis1960/init.lua index 6c50234..2ddf3f6 100644 --- a/src/server/main/Elevators/Otis1960/init.lua +++ b/src/server/main/Elevators/Otis1960/init.lua @@ -2,6 +2,22 @@ --!native --!strict +--Set relay tags through studio command line +--[[ +local s = game.Selection:Get()[1] +for i,v in s:GetChildren() do + if v:IsA("Model") then + local main = v:FindFirstChild("main") + if main then + local label = v:FindFirstChildWhichIsA("TextLabel", true) + if label then + main:AddTag(`Otis1960_RelayButton_{label.Text}`) + end + end + end +end +]] + local Elevators = script.Parent local MainDir = Elevators.Parent local EnumsDir = MainDir:WaitForChild("Enums") @@ -99,6 +115,7 @@ type Constructor_Return_Props = { export type Otis1960Constructor = ClassConstructor +--TODO: Rename Otis1960 to Elevator local Otis1960 = {} :: Impl_Constructor Otis1960.__index = Otis1960 @@ -173,7 +190,10 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT elseif ButtonNameType == Enums.ButtonTree.Special then elseif ButtonNameType == Enums.ButtonTree.Relays then - + --Special case-y + if Otis1960.Name == Enums.Elevator.Otis1960 then + + end elseif ButtonNameType == Enums.ButtonTree.Unknown then else @@ -258,9 +278,10 @@ local FloorQueue: {number} = {} local function CheckQueue(self: ClassConstructor) table.remove(FloorQueue, 1) - if #FloorQueue>0 then + if #FloorQueue ~= 0 then --table.sort - self:__GoToFloor(Leveling[FloorQueue[1]], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, FloorQueue[1])) + Attributes.GoingUp.Value = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, FloorQueue[1]) + self:__GoToFloor(Leveling[FloorQueue[1]], Attributes.GoingUp.Value) end end @@ -372,41 +393,40 @@ function Otis1960:__GoToFloor(GoalLevelVEC, GoingUp) self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z) end +--This is a little wonky i can improve later +local function ToFloorQueue(self: ClassConstructor, InHeadingPath: boolean, RequestedLevel: number, GoalLevelVEC: number) + local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position + + if InHeadingPath then + table.insert(FloorQueue, 1, RequestedLevel) + + if not Doors.Attributes.DoorsOpen.Value then + self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z) + end + else + table.insert(FloorQueue, RequestedLevel) + end +end + function Otis1960:RequestLevelAsync(RequestedLevel) - local GoalLevelVEC: number = Leveling[RequestedLevel] + local GoalLevelVEC: number? = Leveling[RequestedLevel] if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then - local GoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel) + local InHeadingPath = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel) if Attributes.Moving.Value then - local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position - - if Attributes.GoingUp.Value then - if GoingUp then - table.insert(FloorQueue, 1, RequestedLevel) - - if not Doors.Attributes.DoorsOpen.Value then - self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z) - end - else - table.insert(FloorQueue, RequestedLevel) - end - else - if not GoingUp then - table.insert(FloorQueue, 1, RequestedLevel) - - if not Doors.Attributes.DoorsOpen.Value then - self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z) - end - else - table.insert(FloorQueue, RequestedLevel) - end - end + ToFloorQueue(self, InHeadingPath, RequestedLevel, GoalLevelVEC) else - Attributes.GoingUp.Value = GoingUp + if Doors.Attributes.DoorsOpen and #FloorQueue ~= 0 then + --Activated a call while the doors are closing? we need to wait until that is completed to move + repeat + Doors.Attributes.DoorsOpen:GetPropertyChangedSignal("Value"):Wait() + until not Doors.Attributes.DoorsOpen + end + Attributes.GoingUp.Value = InHeadingPath table.insert(FloorQueue, 1, RequestedLevel) - self:__GoToFloor(GoalLevelVEC, GoingUp) + self:__GoToFloor(GoalLevelVEC, InHeadingPath) end else warn(`[{Otis1960.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)