mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
Physical relays
This commit is contained in:
@@ -123,7 +123,6 @@ function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback, Fallback)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function ButtonFunctions:SpecialButton(ButtonID, ButtonName, ButtonTree, Callback)
|
||||
--precomputing speed
|
||||
if ButtonID == Enums.SpecialButton.Stop then
|
||||
@@ -142,7 +141,7 @@ function ButtonFunctions:SpecialButton(ButtonID, ButtonName, ButtonTree, Callbac
|
||||
end
|
||||
|
||||
function ButtonFunctions:__DeactivateButton(Button, Glass)
|
||||
local Part = Glass and Glass or Button
|
||||
local Part = Glass or Button
|
||||
|
||||
Part.Material = Enum.Material.Glass
|
||||
Part.Color = self.ElevatorButtonColors.ButtonDeactivated
|
||||
@@ -150,7 +149,7 @@ function ButtonFunctions:__DeactivateButton(Button, Glass)
|
||||
end
|
||||
|
||||
function ButtonFunctions:__ActivateButton(Button, Glass)
|
||||
local Part = Glass and Glass or Button
|
||||
local Part = Glass or Button
|
||||
|
||||
Part.Material = Enum.Material.Neon
|
||||
Part.Color = self.ElevatorButtonColors.ButtonActivated
|
||||
@@ -159,7 +158,7 @@ end
|
||||
|
||||
function ButtonFunctions:AestheticActivateButton(Button)
|
||||
local Glass = Button:FindFirstChild("Glass") :: BasePart?
|
||||
local LookVec = (Glass and Glass or Button).CFrame.LookVector/50
|
||||
local LookVec = (Glass or Button).CFrame.LookVector/50
|
||||
if Glass then
|
||||
Glass.Position+=LookVec
|
||||
self:__ActivateButton(Button, Glass)
|
||||
|
||||
@@ -30,16 +30,16 @@ type Impl_Constructor = {
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
Volume: number,
|
||||
Volume: number,
|
||||
LightTweenTime: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (MainDisplay: UnionOperation, LanternsMap: Tags.Lanterns, ElevatorSounds: ElevatorSounds, Colors: ElevatorButtonColors) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
LanternsMap: Tags.Lanterns,
|
||||
LanternsMap: Tags.Lanterns,
|
||||
AudioChimeDirection: Sound,
|
||||
AudioChimeLanding: Sound,
|
||||
Colors: ElevatorButtonColors
|
||||
AudioChimeLanding: Sound,
|
||||
Colors: ElevatorButtonColors
|
||||
}
|
||||
|
||||
type ElevatorAttributes = {
|
||||
|
||||
107
src/server/main/Elevators/Otis1960/PhysicalRelay.lua
Normal file
107
src/server/main/Elevators/Otis1960/PhysicalRelay.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
--!optimize 2
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local Elevators = script.Parent
|
||||
local MainDir = Elevators.Parent.Parent
|
||||
local LoadDir = MainDir:WaitForChild("Load")
|
||||
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Tween = require(Storage:WaitForChild("Tween"))
|
||||
local Enums = require(Storage:WaitForChild("Enums"))
|
||||
local Tags = require(LoadDir:WaitForChild("Tags"))
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
SetState: (self: ClassConstructor, RelayName: string, State: boolean) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
ActivatedAngle: number,
|
||||
DeActivatedAngle: number,
|
||||
AnimationTime: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (ElevatorModel: Enums.ElevatorValues, RelayTagList: Tags.ButtonDictionary) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
ElevatorModel: Enums.ElevatorValues,
|
||||
RelayTagList: Tags.ButtonDictionary & {
|
||||
AudioActivated: Sound,
|
||||
AudoDeactivated: Sound
|
||||
}
|
||||
}
|
||||
|
||||
export type PhysicalRelayConstructor = ClassConstructor
|
||||
|
||||
local PhysicalRelay = {} :: Impl_Constructor
|
||||
PhysicalRelay.__index = PhysicalRelay
|
||||
|
||||
PhysicalRelay.ActivatedAngle = 13
|
||||
PhysicalRelay.DeActivatedAngle = -13
|
||||
PhysicalRelay.AnimationTime = .05
|
||||
|
||||
function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
|
||||
--Idk how to construct an ideal way to identify these,
|
||||
--Hard coding it is
|
||||
for RelayName, RelayProperties in RelayTagList do
|
||||
if RelayProperties.Inst then
|
||||
local RelayAudioActivated = Instance.new("Sound")
|
||||
local RelayAudioDeActivated = Instance.new("Sound")
|
||||
RelayAudioActivated.Volume = 1
|
||||
RelayAudioDeActivated.Volume = 1
|
||||
|
||||
if ElevatorModel == Enums.Elevator.Otis1960 then
|
||||
if RelayProperties.Name == "240 V" or
|
||||
RelayProperties.Name == "440 V" or
|
||||
RelayProperties.Name == "UP" or
|
||||
RelayProperties.Name == "DOWN"
|
||||
then
|
||||
RelayAudioActivated.SoundId = ""
|
||||
RelayAudioDeActivated.SoundId = ""
|
||||
else
|
||||
RelayAudioActivated.SoundId = ""
|
||||
RelayAudioDeActivated.SoundId = ""
|
||||
end
|
||||
|
||||
RelayAudioActivated.Parent = RelayProperties.Inst
|
||||
end
|
||||
else
|
||||
warn()
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable({
|
||||
ElevatorModel = ElevatorModel,
|
||||
RelayTagList = RelayTagList
|
||||
}, PhysicalRelay)
|
||||
end
|
||||
|
||||
local Animation = Tween.constructor(TweenInfo.new(PhysicalRelay.AnimationTime, Enum.EasingStyle.Linear))
|
||||
|
||||
local function OtimRelayAnimation(Relay: BasePart, State: boolean)
|
||||
local T = Animation:Start(Relay, {
|
||||
CFrame = Relay.CFrame*CFrame.Angles(math.rad(State and PhysicalRelay.ActivatedAngle or PhysicalRelay.DeActivatedAngle), 0, 0)
|
||||
})
|
||||
|
||||
T.Completed:Once(function()
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
function PhysicalRelay:SetState(RelayName, State)
|
||||
local Relay = self.RelayTagList[`RelayButton_{RelayName}`]
|
||||
|
||||
if Relay then
|
||||
if self.ElevatorModel == Enums.Elevator.Otis1960 then
|
||||
OtimRelayAnimation(Relay.Inst :: BasePart, State)
|
||||
end
|
||||
else
|
||||
warn(`Physical Relay "{RelayName}" does not exist! it will physically not work`)
|
||||
end
|
||||
end
|
||||
|
||||
return PhysicalRelay
|
||||
@@ -2,8 +2,11 @@
|
||||
--!native
|
||||
--!strict
|
||||
|
||||
local RelayAlgorithmModule = require(script.Parent:WaitForChild("RelayAlgorithm"))
|
||||
local DoorsModule = require(script.Parent:WaitForChild("Doors"))
|
||||
local ElevatorDir = script.Parent
|
||||
|
||||
local RelayAlgorithmModule = require(ElevatorDir:WaitForChild("RelayAlgorithm"))
|
||||
local DoorsModule = require(ElevatorDir:WaitForChild("Doors"))
|
||||
local PhysicalRelay = require(ElevatorDir:WaitForChild("PhysicalRelay"))
|
||||
|
||||
type Leveling = {
|
||||
Leveling: {number},
|
||||
@@ -25,9 +28,18 @@ type Impl_Constructor = {
|
||||
__GoalYLevel: (self: ClassConstructor) -> (),
|
||||
}
|
||||
|
||||
type Constructor_Fun = (RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes, Leveling: Leveling, BoxAlignPosition: BoxAlignPosition, ElevatorBox: ElevatorBox) -> ClassConstructor
|
||||
type Constructor_Fun = (
|
||||
PhysicalRelay: PhysicalRelay.PhysicalRelayConstructor,
|
||||
RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor,
|
||||
ElevatorAttributes: ElevatorAttributes,
|
||||
DoorAttributes: DoorAttributes,
|
||||
Leveling: Leveling,
|
||||
BoxAlignPosition: BoxAlignPosition,
|
||||
ElevatorBox: ElevatorBox
|
||||
) -> ClassConstructor
|
||||
|
||||
type Constructor_Return_Props = {
|
||||
PhysicalRelay: PhysicalRelay.PhysicalRelayConstructor,
|
||||
RelayAlgorthm: RelayAlgorithmModule.RelayAlgorithmConstructor,
|
||||
ElevatorAttributes: ElevatorAttributes,
|
||||
DoorAttributes: DoorAttributes,
|
||||
@@ -36,18 +48,18 @@ type Constructor_Return_Props = {
|
||||
ElevatorBox: ElevatorBox,
|
||||
|
||||
__Connections: {
|
||||
Ready: RBXScriptConnection?,
|
||||
Open: RBXScriptConnection?,
|
||||
GoalYLevel: RBXScriptConnection?,
|
||||
Goal: RBXScriptConnection?
|
||||
ReadyForMoving: RBXScriptConnection?,
|
||||
Open: RBXScriptConnection?,
|
||||
GoalYLevel: RBXScriptConnection?,
|
||||
Goal: RBXScriptConnection?
|
||||
}
|
||||
}
|
||||
|
||||
type ElevatorAttributes = {
|
||||
Relay: {
|
||||
Ready: BoolValue,
|
||||
GoalYLevel: NumberValue,
|
||||
Goal: IntValue
|
||||
ReadyForMoving: BoolValue,
|
||||
GoalYLevel: NumberValue,
|
||||
Goal: IntValue
|
||||
},
|
||||
|
||||
Stopped: BoolValue
|
||||
@@ -60,8 +72,9 @@ export type RelayConstructor = ClassConstructor
|
||||
local Relay = {} :: Impl_Constructor
|
||||
Relay.__index = Relay
|
||||
|
||||
function Relay.constructor(RelayAlgorthm, ElevatorAttributes, DoorAttributes, LevelingModule, BoxAlignPosition, ElevatorBox)
|
||||
function Relay.constructor(PhysicalRelay, RelayAlgorthm, ElevatorAttributes, DoorAttributes, LevelingModule, BoxAlignPosition, ElevatorBox)
|
||||
return setmetatable({
|
||||
PhysicalRelay = PhysicalRelay,
|
||||
RelayAlgorthm = RelayAlgorthm,
|
||||
ElevatorAttributes = ElevatorAttributes,
|
||||
DoorAttributes = DoorAttributes,
|
||||
@@ -69,22 +82,22 @@ function Relay.constructor(RelayAlgorthm, ElevatorAttributes, DoorAttributes, Le
|
||||
BoxAlignPosition = BoxAlignPosition,
|
||||
ElevatorBox = ElevatorBox,
|
||||
|
||||
__Connections = {}
|
||||
__Connections = {}
|
||||
}, Relay)
|
||||
end
|
||||
|
||||
function Relay:__Ready()
|
||||
if not self.ElevatorAttributes.Relay.Ready.Value then
|
||||
if not self.ElevatorAttributes.Relay.ReadyForMoving.Value then
|
||||
self:__GoalYLevel()
|
||||
end
|
||||
end
|
||||
|
||||
function Relay:__Open()
|
||||
self.ElevatorAttributes.Relay.Ready.Value = self.DoorAttributes.Relay.Open.Value
|
||||
self.ElevatorAttributes.Relay.ReadyForMoving.Value = not self.DoorAttributes.Relay.Open.Value
|
||||
end
|
||||
|
||||
function Relay:__GoalYLevel()
|
||||
if not self.ElevatorAttributes.Relay.Ready.Value then
|
||||
if self.ElevatorAttributes.Relay.ReadyForMoving.Value then
|
||||
self.BoxAlignPosition.Position = Vector3.new(
|
||||
self.ElevatorBox.Position.X,
|
||||
self.ElevatorAttributes.Relay.GoalYLevel.Value,
|
||||
@@ -100,29 +113,36 @@ function Relay:__Goal()
|
||||
end
|
||||
|
||||
function Relay:BulkConnect()
|
||||
self.__Connections.Ready = self.ElevatorAttributes.Relay.Ready:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
print("Relay=Ready","State=", self.ElevatorAttributes.Relay.Ready.Value)
|
||||
local ReadyForMovingRelay = self.ElevatorAttributes.Relay.ReadyForMoving
|
||||
local OpenRelay = self.DoorAttributes.Relay.Open
|
||||
|
||||
self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value)
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__Ready()
|
||||
end
|
||||
end)
|
||||
|
||||
self.__Connections.Open = self.DoorAttributes.Relay.Open:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
print("Relay=Open","State=", self.DoorAttributes.Relay.Open.Value)
|
||||
self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
self.PhysicalRelay:SetState("DO", OpenRelay.Value)
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__Open()
|
||||
end
|
||||
end)
|
||||
|
||||
self.__Connections.GoalYLevel = self.ElevatorAttributes.Relay.GoalYLevel:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
print("Relay=GoalYLevel","State=", self.ElevatorAttributes.Relay.GoalYLevel.Value)
|
||||
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__GoalYLevel()
|
||||
end
|
||||
end)
|
||||
|
||||
self.__Connections.Goal = self.ElevatorAttributes.Relay.Goal:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
print("Relay=Goal","State=", self.ElevatorAttributes.Relay.Goal.Value)
|
||||
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__Goal()
|
||||
end
|
||||
@@ -130,8 +150,8 @@ function Relay:BulkConnect()
|
||||
end
|
||||
|
||||
function Relay:BulkDisconnect()
|
||||
if self.__Connections.Ready and self.__Connections.Ready.Connected then
|
||||
self.__Connections.Ready:Disconnect()
|
||||
if self.__Connections.ReadyForMoving and self.__Connections.ReadyForMoving.Connected then
|
||||
self.__Connections.ReadyForMoving:Disconnect()
|
||||
end
|
||||
if self.__Connections.Open and self.__Connections.Open.Connected then
|
||||
self.__Connections.Open:Disconnect()
|
||||
|
||||
@@ -29,6 +29,12 @@ type ElevatorAttributes = {
|
||||
CurrentFloor: IntValue,
|
||||
GoingUp: BoolValue,
|
||||
Moving: BoolValue,
|
||||
|
||||
Relay: {
|
||||
Goal: IntValue,
|
||||
GoalYLevel: NumberValue,
|
||||
ReadyForMoving: BoolValue,
|
||||
}
|
||||
}
|
||||
|
||||
type DoorAttributes = {
|
||||
@@ -89,7 +95,7 @@ end
|
||||
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
return not self.ElevatorAttributes.Moving.Value and self.DoorAttributes.Relay.Open.Value
|
||||
return not self.ElevatorAttributes.Relay.ReadyForMoving.Value
|
||||
end
|
||||
|
||||
return RelayAlgorithm
|
||||
@@ -5,6 +5,7 @@
|
||||
--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")
|
||||
@@ -37,6 +38,7 @@ local Doors = require(script:WaitForChild("Doors"))
|
||||
local MovingObjects = require(script:WaitForChild("MovingObjects"))
|
||||
local RelayAlgorithm = require(script:WaitForChild("RelayAlgorithm"))
|
||||
local Relay = require(script:WaitForChild("Relay"))
|
||||
local PhysicalRelays = require(script:WaitForChild("PhysicalRelay"))
|
||||
|
||||
local HallDisplays = require(Elevators:WaitForChild("HallDisplays"))
|
||||
local ElevatorMover = require(Elevators:WaitForChild("Mover"))
|
||||
@@ -54,12 +56,8 @@ type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Leveled: (self: ClassConstructor, RequestedLevel: number) -> (),
|
||||
Leveling: (self: ClassConstructor, RequestedLevel: number) -> (),
|
||||
FloorPassingUp: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
|
||||
FloorPassingDown: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
|
||||
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
|
||||
__MoveTo: (self: ClassConstructor, GoingUp: boolean, RequestedLevel: number) -> (),
|
||||
RequestLevelAsync: (self: ClassConstructor, RequestedLevel: number) -> boolean,
|
||||
__MoveToAsync: (self: ClassConstructor, GoingUp: boolean, RequestedLevel: number) -> (),
|
||||
__MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean, RequestedLevel: number) -> (),
|
||||
} & Impl_Static_Props
|
||||
|
||||
@@ -89,9 +87,9 @@ type Impl_Static_Props = {
|
||||
Stopped: BoolValue,
|
||||
|
||||
Relay: {
|
||||
Goal: IntValue,
|
||||
GoalYLevel: NumberValue,
|
||||
Ready: BoolValue,
|
||||
Goal: IntValue,
|
||||
GoalYLevel: NumberValue,
|
||||
ReadyForMoving: BoolValue,
|
||||
}
|
||||
},
|
||||
Events: {
|
||||
@@ -99,7 +97,13 @@ type Impl_Static_Props = {
|
||||
}
|
||||
}
|
||||
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, ButtonsTags: Tags.ElevatorButtons, LanternsTags: Tags.Lanterns, LandingDoors: Tags.LandingTags) -> ClassConstructor
|
||||
type Constructor_Fun = (
|
||||
TagsConstructor: TagsConstructor,
|
||||
ButtonsTags: Tags.ElevatorButtons,
|
||||
LanternsTags: Tags.Lanterns,
|
||||
LandingDoors: Tags.LandingTags
|
||||
) -> ClassConstructor
|
||||
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
MOConstructor: MovingObjects.MovingObjectsConstructor,
|
||||
@@ -125,6 +129,7 @@ type Constructor_Return_Props = {
|
||||
ButtonsConstructor: Buttons.ButtonsConstructor,
|
||||
RelayAlgorithmConstructor: RelayAlgorithm.RelayAlgorithmConstructor,
|
||||
RelayConstructor: Relay.RelayConstructor,
|
||||
PhysicalRelays: PhysicalRelays.PhysicalRelayConstructor,
|
||||
|
||||
__Connections: {
|
||||
Moving: RBXScriptConnection?,
|
||||
@@ -162,9 +167,9 @@ Elevator.Attributes = {
|
||||
Stopped = Instance.new("BoolValue") :: BoolValue,
|
||||
|
||||
Relay = {
|
||||
Ready = Instance.new("BoolValue") :: BoolValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
|
||||
ReadyForMoving = Instance.new("BoolValue") :: BoolValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -176,21 +181,22 @@ Elevator.Attributes.CurrentFloor.Value = 1
|
||||
Elevator.Attributes.Moving.Value = false
|
||||
Elevator.Attributes.GoingUp.Value = false
|
||||
|
||||
Elevator.Attributes.Relay.Goal.Value = 1
|
||||
Elevator.Attributes.Relay.GoalYLevel.Value = LevelingModule.Leveling[Elevator.Attributes.CurrentFloor.Value]
|
||||
Elevator.Attributes.Relay.Ready.Value = false
|
||||
Elevator.Attributes.Relay.Goal.Value = 1
|
||||
Elevator.Attributes.Relay.GoalYLevel.Value = LevelingModule.Leveling[Elevator.Attributes.CurrentFloor.Value]
|
||||
Elevator.Attributes.Relay.ReadyForMoving.Value = false
|
||||
|
||||
local Attributes = Elevator.Attributes
|
||||
|
||||
--Math function for determining if the elevator goal is to move upwards or not
|
||||
local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean
|
||||
--(CurrentFloor-RequestedFloor)>0
|
||||
return -CurrentFloor+RequestedFloor>0
|
||||
-- -(CurrentFloor-RequestedFloor)>0
|
||||
-- -CurrentFloor+RequestedFloor>0
|
||||
return CurrentFloor<RequestedFloor
|
||||
end
|
||||
|
||||
local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number, ButtonTree: Tags.ButtonPropertiesSafe)
|
||||
ButtonTree.Prompt.Enabled = false
|
||||
local Some = self:RequestLevel(ButtonFloor)
|
||||
local Some = self:RequestLevelAsync(ButtonFloor)
|
||||
|
||||
if Some then
|
||||
local FloorTracker: RBXScriptConnection
|
||||
@@ -212,9 +218,9 @@ end
|
||||
--If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed,
|
||||
--then open the doors
|
||||
local function OpenElevatorDoorsSafe(self: ClassConstructor)
|
||||
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.Ready=",Attributes.Relay.Ready.Value)
|
||||
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.ReadyForMoving=",Attributes.Relay.ReadyForMoving.Value)
|
||||
|
||||
if not Doors.Attributes.Relay.Open.Value and not Attributes.Relay.Ready.Value then
|
||||
if not Attributes.Relay.ReadyForMoving.Value then
|
||||
task.spawn(function()
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
||||
end)
|
||||
@@ -257,7 +263,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
|
||||
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
|
||||
|
||||
self.LanternsConstructor:Reset()
|
||||
self:__MoveTo(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value))
|
||||
self:__MoveToAsync(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value))
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||
end
|
||||
end)
|
||||
@@ -273,7 +279,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
|
||||
end
|
||||
|
||||
local function IterateButtons(self: ClassConstructor, ButtonsTagsConstructor: ButtonTags.ButtonsTagsConstructor)
|
||||
for ButtonNameType, ButtonList in ButtonsTagsConstructor.Buttons do
|
||||
for ButtonNameType, ButtonList in ButtonsTagsConstructor.Buttons[Elevator.Name] do
|
||||
for ButtonID, ButtonTree in ButtonList do
|
||||
if ButtonTree.Prompt and ButtonTree.Inst and ButtonTree.Attachment then
|
||||
HookButtons(self, ButtonNameType :: Enums.ButtonTreeValues, ButtonID, ButtonTree :: Tags.ButtonPropertiesSafe)
|
||||
@@ -329,7 +335,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
--Init the lanterns
|
||||
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, LanternsTags, Elevator.Sounds, Elevator.Colors)
|
||||
|
||||
local ButtonsTagsConstructor = ButtonTags.constructor(TagsConstructor, ButtonsTags)
|
||||
local ButtonsTagsConstructor = ButtonTags.constructor(TagsConstructor, ButtonsTags, Elevator.Name)
|
||||
local Otis1960_Buttons = ButtonsTagsConstructor:CreatePromptButtons()
|
||||
|
||||
self.ButtonsConstructor = Buttons.constructor(Elevator.Attributes, Elevator.Events, Elevator.Colors)
|
||||
@@ -345,8 +351,11 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
Elevator.MaxVelocity
|
||||
)
|
||||
|
||||
--Relays
|
||||
self.PhysicalRelays = PhysicalRelays.constructor(Elevator.Name, ButtonsTagsConstructor.Buttons[Elevator.Name].Relays)
|
||||
self.RelayAlgorithmConstructor = RelayAlgorithm.constructor(self.BoxAlignPosition, Attributes, Doors.Attributes)
|
||||
self.RelayConstructor = Relay.constructor(
|
||||
self.PhysicalRelays,
|
||||
self.RelayAlgorithmConstructor,
|
||||
Attributes,
|
||||
Doors.Attributes,
|
||||
@@ -372,7 +381,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
return ClassConstructor
|
||||
end
|
||||
|
||||
function Elevator:Leveled(RequestedLevel)
|
||||
local function Leveled(self: ClassConstructor, RequestedLevel: number)
|
||||
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
||||
Attributes.Moving.Value = false
|
||||
Attributes.CurrentFloor.Value = RequestedLevel
|
||||
@@ -385,19 +394,19 @@ function Elevator:Leveled(RequestedLevel)
|
||||
|
||||
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then
|
||||
--More floors in the queue
|
||||
self:__MoveTo(ElevatorGoingUp, RequestedLevel)
|
||||
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel)
|
||||
else
|
||||
--The elevator is at a full park now
|
||||
Attributes.Relay.Ready.Value = false
|
||||
Attributes.Relay.ReadyForMoving.Value = false
|
||||
end
|
||||
end
|
||||
|
||||
function Elevator:Leveling(RequestedLevel)
|
||||
local function Leveling(self: ClassConstructor, RequestedLevel: number)
|
||||
self.BoxAlignPosition.MaxVelocity = 1
|
||||
self.LanternsConstructor:Toggle(true, RequestedLevel)
|
||||
end
|
||||
|
||||
function Elevator:FloorPassingUp(ElevatorPositionY, RequestedLevel)
|
||||
local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
|
||||
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value+1]
|
||||
|
||||
if NextLevelBetweenFloors and ElevatorPositionY>=NextLevelBetweenFloors then
|
||||
@@ -408,7 +417,7 @@ function Elevator:FloorPassingUp(ElevatorPositionY, RequestedLevel)
|
||||
end
|
||||
end
|
||||
|
||||
function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
|
||||
local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
|
||||
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value-1]
|
||||
|
||||
if NextLevelBetweenFloors and ElevatorPositionY<=NextLevelBetweenFloors then
|
||||
@@ -420,10 +429,6 @@ function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
|
||||
end
|
||||
|
||||
function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
Attributes.GoingUp.Value = GoingUp
|
||||
Attributes.Relay.Goal.Value = RequestedLevel
|
||||
Attributes.Moving.Value = true
|
||||
|
||||
if self.__Connections.Moving and self.__Connections.Moving.Connected then
|
||||
self.__Connections.Moving:Disconnect()
|
||||
end
|
||||
@@ -431,6 +436,10 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
local Delta = 0
|
||||
local DoorsOpeningDebounce = false
|
||||
|
||||
Attributes.GoingUp.Value = GoingUp
|
||||
Attributes.Relay.Goal.Value = RequestedLevel
|
||||
Attributes.Moving.Value = true
|
||||
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
|
||||
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
|
||||
@@ -446,10 +455,10 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
|
||||
--Kill the connection
|
||||
if Attributes.GoingUp.Value then
|
||||
self:FloorPassingUp(ElevatorPositionY, Attributes.Relay.Goal.Value)
|
||||
FloorPassingUp(self, ElevatorPositionY, Attributes.Relay.Goal.Value)
|
||||
|
||||
if ElevatorPositionY>=BoxAlignY-Elevator.FloorLevelingDistance then
|
||||
self:Leveling(Attributes.Relay.Goal.Value)
|
||||
Leveling(self, Attributes.Relay.Goal.Value)
|
||||
|
||||
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
||||
DoorsOpeningDebounce = true
|
||||
@@ -458,13 +467,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
end
|
||||
|
||||
if ElevatorPositionY>=BoxAlignY-Elevator.LeveledDistance then
|
||||
self:Leveled(Attributes.Relay.Goal.Value)
|
||||
Leveled(self, Attributes.Relay.Goal.Value)
|
||||
end
|
||||
else
|
||||
self:FloorPassingDown(ElevatorPositionY, Attributes.Relay.Goal.Value)
|
||||
FloorPassingDown(self, ElevatorPositionY, Attributes.Relay.Goal.Value)
|
||||
|
||||
if ElevatorPositionY<=BoxAlignY+Elevator.FloorLevelingDistance then
|
||||
self:Leveling(Attributes.Relay.Goal.Value)
|
||||
Leveling(self, Attributes.Relay.Goal.Value)
|
||||
|
||||
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
||||
DoorsOpeningDebounce = true
|
||||
@@ -473,13 +482,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
end
|
||||
|
||||
if ElevatorPositionY<=BoxAlignY+Elevator.LeveledDistance then
|
||||
self:Leveled(Attributes.Relay.Goal.Value)
|
||||
Leveled(self, Attributes.Relay.Goal.Value)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Elevator:__MoveTo(GoingUp, RequestedLevel)
|
||||
function Elevator:__MoveToAsync(GoingUp, RequestedLevel)
|
||||
if Doors.Attributes.Relay.Open.Value then
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
|
||||
end
|
||||
@@ -492,7 +501,7 @@ function Elevator:__MoveTo(GoingUp, RequestedLevel)
|
||||
self:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
end
|
||||
|
||||
function Elevator:RequestLevel(RequestedLevel)
|
||||
function Elevator:RequestLevelAsync(RequestedLevel)
|
||||
local FloorExist: number? = LevelingModule.Leveling[RequestedLevel]
|
||||
|
||||
if FloorExist and RequestedLevel ~= Attributes.CurrentFloor.Value then
|
||||
@@ -500,7 +509,7 @@ function Elevator:RequestLevel(RequestedLevel)
|
||||
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
if Proceeding then
|
||||
self:__MoveTo(ElevatorGoingUp, RequestedLevel)
|
||||
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel)
|
||||
end
|
||||
return true
|
||||
else
|
||||
|
||||
@@ -9,6 +9,10 @@ export type Otis1960Sounds = typeof(SoundEnums.Otis1960)
|
||||
export type Otis1960LanternChimeDirection = "rbxassetid://16990287228"
|
||||
export type Otis1960LanternChimeLanding = "rbxassetid://16990290265"
|
||||
export type Otis1960DoorClosingClick = "rbxassetid://16357740945"
|
||||
export type Otis1960RelayActivated = ""
|
||||
export type Otis1960RelayDeActivated = ""
|
||||
export type Otis1960BigRelayActivated = ""
|
||||
export type Otis1960BigRelayDeActivated = ""
|
||||
|
||||
export type Otis1960SoundValues = Otis1960LanternChimeDirection |
|
||||
Otis1960LanternChimeLanding |
|
||||
@@ -17,7 +21,11 @@ export type Otis1960SoundValues = Otis1960LanternChimeDirection |
|
||||
SoundEnums.Otis1960 = {
|
||||
LanternChimeDirection = "rbxassetid://16990287228" :: Otis1960LanternChimeDirection,
|
||||
LanternChimeLanding = "rbxassetid://16990290265" :: Otis1960LanternChimeLanding,
|
||||
DoorClosingClick = "rbxassetid://16357740945" :: Otis1960DoorClosingClick
|
||||
DoorClosingClick = "rbxassetid://16357740945" :: Otis1960DoorClosingClick,
|
||||
RelayActivated = "" :: Otis1960RelayActivated,
|
||||
RelayDeActivated = "" :: Otis1960RelayDeActivated,
|
||||
BigRelayActivated = "" :: Otis1960BigRelayActivated,
|
||||
BigRealyDeActivated = "" :: Otis1960BigRelayDeActivated,
|
||||
}
|
||||
|
||||
return SoundEnums
|
||||
@@ -26,14 +26,15 @@ type Impl_Constructor = {
|
||||
|
||||
type Impl_Static_Props = {
|
||||
DefaultMaxActivationDistance: number,
|
||||
DefaultHoldDuration: number
|
||||
DefaultHoldDuration: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, ModelButtons: Tags.ElevatorButtons) -> ClassConstructor
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, ModelButtons: Tags.ElevatorButtons, ElevatorModel: Enums.ElevatorValues) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: TagsConstructor,
|
||||
ModelButtons: Tags.ElevatorButtons,
|
||||
Buttons: Tags.ButtonsTree
|
||||
Tags: TagsConstructor,
|
||||
ModelButtons: Tags.ElevatorButtons,
|
||||
ElevatorModel: Enums.ElevatorValues,
|
||||
Buttons: Tags.ButtonsTree
|
||||
}
|
||||
|
||||
export type ButtonsTagsConstructor = ClassConstructor
|
||||
@@ -44,15 +45,19 @@ ButtonsModule.__index = ButtonsModule
|
||||
ButtonsModule.DefaultMaxActivationDistance = 3
|
||||
ButtonsModule.DefaultHoldDuration = .30
|
||||
|
||||
function ButtonsModule.constructor(TagsConstructor, ModelButtons)
|
||||
function ButtonsModule.constructor(TagsConstructor, ModelButtons, ElevatorModel)
|
||||
return setmetatable({
|
||||
Tags = TagsConstructor,
|
||||
ModelButtons = ModelButtons,
|
||||
Tags = TagsConstructor,
|
||||
ModelButtons = ModelButtons,
|
||||
ElevatorModel = ElevatorModel,
|
||||
|
||||
Buttons = {
|
||||
Landing = {},
|
||||
Car = {},
|
||||
Special = {},
|
||||
Relays = {}
|
||||
[ElevatorModel] = {
|
||||
Landing = {},
|
||||
Car = {},
|
||||
Special = {},
|
||||
Relays = {}
|
||||
}
|
||||
}
|
||||
}, ButtonsModule)
|
||||
end
|
||||
@@ -91,7 +96,7 @@ function ButtonsModule:CreatePromptButtons()
|
||||
Prompt.ActionText = tostring(Split[3])
|
||||
Prompt.ObjectText = "Floor"
|
||||
|
||||
self.Buttons.Car[`{Split[2]}_{Split[3]}`] = {
|
||||
self.Buttons[self.ElevatorModel].Car[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment
|
||||
@@ -103,7 +108,7 @@ function ButtonsModule:CreatePromptButtons()
|
||||
Prompt.ActionText = `Send Elevator {Name}`
|
||||
Prompt.ObjectText = `Floor {tostring(Split[4])}`
|
||||
|
||||
self.Buttons.Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
|
||||
self.Buttons[self.ElevatorModel].Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment,
|
||||
@@ -116,7 +121,7 @@ function ButtonsModule:CreatePromptButtons()
|
||||
Prompt.ActionText = Name
|
||||
Prompt.ObjectText = "Elevator"
|
||||
|
||||
self.Buttons.Special[`{Split[2]}_{Split[3]}`] = {
|
||||
self.Buttons[self.ElevatorModel].Special[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment,
|
||||
@@ -129,7 +134,7 @@ function ButtonsModule:CreatePromptButtons()
|
||||
Prompt.ActionText = "Activate"
|
||||
Prompt.ObjectText = "Relay"
|
||||
|
||||
self.Buttons.Relays[`{Split[2]}_{Split[3]}`] = {
|
||||
self.Buttons[self.ElevatorModel].Relays[`{Split[2]}_{Split[3]}`] = {
|
||||
Inst = Inst,
|
||||
Prompt = Prompt,
|
||||
Attachment = Attachment,
|
||||
|
||||
@@ -25,7 +25,7 @@ type Impl_Constructor = {
|
||||
|
||||
type Impl_Static_Props = {
|
||||
Decoders: {
|
||||
CarTag: (FloorTag: string) -> number?,
|
||||
CarTag: (FloorTag: string) -> number?,
|
||||
HallTag: (FloorTag: string) -> number?
|
||||
}
|
||||
}
|
||||
@@ -61,29 +61,29 @@ export type LanternsTree = {
|
||||
}
|
||||
|
||||
export type LightSwitchProperties = {
|
||||
Switch: Instance?,
|
||||
Lights: {Instance}?,
|
||||
LightSources: {Instance}?,
|
||||
Prompt: ProximityPrompt?,
|
||||
ClickSound: Sound?,
|
||||
ColorActivated: Color3?,
|
||||
ColorDeactivated: Color3?,
|
||||
ActivatedMaterial: string?,
|
||||
Switch: Instance?,
|
||||
Lights: {Instance}?,
|
||||
LightSources: {Instance}?,
|
||||
Prompt: ProximityPrompt?,
|
||||
ClickSound: Sound?,
|
||||
ColorActivated: Color3?,
|
||||
ColorDeactivated: Color3?,
|
||||
ActivatedMaterial: string?,
|
||||
DeactivatedMaterial: string?,
|
||||
Enabled: boolean?
|
||||
Enabled: boolean?
|
||||
}
|
||||
|
||||
export type LightSwitchPropertiesSafe = {
|
||||
Switch: Instance,
|
||||
Lights: {Instance},
|
||||
LightSources: {Instance},
|
||||
Prompt: ProximityPrompt,
|
||||
ClickSound: Sound,
|
||||
ColorActivated: Color3,
|
||||
ColorDeactivated: Color3,
|
||||
ActivatedMaterial: string,
|
||||
Switch: Instance,
|
||||
Lights: {Instance},
|
||||
LightSources: {Instance},
|
||||
Prompt: ProximityPrompt,
|
||||
ClickSound: Sound,
|
||||
ColorActivated: Color3,
|
||||
ColorDeactivated: Color3,
|
||||
ActivatedMaterial: string,
|
||||
DeactivatedMaterial: string,
|
||||
Enabled: boolean
|
||||
Enabled: boolean
|
||||
}
|
||||
|
||||
export type LightSwitchTree = {
|
||||
@@ -94,11 +94,17 @@ export type InteractablesTree = {
|
||||
LightSwitches: LightSwitchTree
|
||||
}
|
||||
|
||||
export type ButtonDictionary = {
|
||||
[string]: ButtonProperties
|
||||
}
|
||||
|
||||
export type ButtonsTree = {
|
||||
Car: ButtonProperties,
|
||||
Landing: ButtonProperties,
|
||||
Special: ButtonProperties,
|
||||
Relays: ButtonProperties
|
||||
[Enums.ElevatorValues]: {
|
||||
Car: ButtonDictionary,
|
||||
Landing: ButtonDictionary,
|
||||
Special: ButtonDictionary,
|
||||
Relays: ButtonDictionary
|
||||
}
|
||||
}
|
||||
|
||||
export type ButtonProperties = {
|
||||
|
||||
@@ -125,7 +125,8 @@ function Lights:Init()
|
||||
LightProperties.Lights and
|
||||
LightProperties.LightSources and
|
||||
LightProperties.ActivatedMaterial and
|
||||
LightProperties.DeactivatedMaterial then
|
||||
LightProperties.DeactivatedMaterial
|
||||
then
|
||||
if LightProperties.Enabled then
|
||||
EnabledState = true
|
||||
LightProperties.Prompt.ActionText = "Toggle Off"
|
||||
|
||||
Reference in New Issue
Block a user