Physical working relays!

This commit is contained in:
2024-06-02 01:13:00 -04:00
parent 2f753474b1
commit b58febf7ec
7 changed files with 148 additions and 73 deletions

View File

@@ -1,4 +1,4 @@
## Lights # Lights
#### Properties #### Properties
- Activated #Color3 - Activated #Color3
- The color that is shown on the <a>Light Props</a> once - The color that is shown on the <a>Light Props</a> once
@@ -11,7 +11,4 @@
* `Interact` - *Interact Initializer* [`Not Changable`] * `Interact` - *Interact Initializer* [`Not Changable`]
* `LightSwitch` - *Interaction Type* [`Not Changable`] * `LightSwitch` - *Interaction Type* [`Not Changable`]
* `*AreaName*` - *Area name, must be unique and cannot use the same names* [`Changable`] * `*AreaName*` - *Area name, must be unique and cannot use the same names* [`Changable`]
#### Light Objects
## Elevator

View File

@@ -4,8 +4,11 @@
local Elevators = script.Parent local Elevators = script.Parent
local MainDir = Elevators.Parent.Parent local MainDir = Elevators.Parent.Parent
local EnumsDir = MainDir:WaitForChild("Enums")
local LoadDir = MainDir:WaitForChild("Load") local LoadDir = MainDir:WaitForChild("Load")
local SoundEnums = require(EnumsDir:WaitForChild("Sounds"))
local Storage = game:GetService("ReplicatedStorage") local Storage = game:GetService("ReplicatedStorage")
local Tween = require(Storage:WaitForChild("Tween")) local Tween = require(Storage:WaitForChild("Tween"))
@@ -17,22 +20,13 @@ type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
SetState: (self: ClassConstructor, RelayName: string, State: boolean) -> () SetState: (self: ClassConstructor, RelayName: string, State: boolean, ActivateImmediately: 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_Fun = (ElevatorModel: Enums.ElevatorValues, RelayTagList: Tags.RelayDictionary) -> ClassConstructor
type Constructor_Return_Props = { type Constructor_Return_Props = {
ElevatorModel: Enums.ElevatorValues, ElevatorModel: Enums.ElevatorValues,
RelayTagList: Tags.ButtonDictionary & { RelayTagList: Tags.RelayDictionary
AudioActivated: Sound,
AudoDeactivated: Sound
}
} }
export type PhysicalRelayConstructor = ClassConstructor export type PhysicalRelayConstructor = ClassConstructor
@@ -40,19 +34,17 @@ export type PhysicalRelayConstructor = ClassConstructor
local PhysicalRelay = {} :: Impl_Constructor local PhysicalRelay = {} :: Impl_Constructor
PhysicalRelay.__index = PhysicalRelay PhysicalRelay.__index = PhysicalRelay
PhysicalRelay.ActivatedAngle = 13
PhysicalRelay.DeActivatedAngle = -13
PhysicalRelay.AnimationTime = .05
function PhysicalRelay.constructor(ElevatorModel, RelayTagList) function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
--Idk how to construct an ideal way to identify these, --Idk how to construct an ideal way to identify these,
--Hard coding it is --Hard coding it is
for RelayName, RelayProperties in RelayTagList do for RelayName, RelayProperties in RelayTagList do
if RelayProperties.Inst then if RelayProperties.Inst then
local RelayAudioActivated = Instance.new("Sound") --Audio
local RelayAudioDeActivated = Instance.new("Sound")
RelayAudioActivated.Volume = 1 local RelayAudioActivated = Instance.new("Sound") :: Sound
RelayAudioDeActivated.Volume = 1 local RelayAudioDeActivated = Instance.new("Sound") :: Sound
RelayAudioActivated.Volume = .5
RelayAudioDeActivated.Volume = .5
if ElevatorModel == Enums.Elevator.Otis1960 then if ElevatorModel == Enums.Elevator.Otis1960 then
if RelayProperties.Name == "240 V" or if RelayProperties.Name == "240 V" or
@@ -60,17 +52,40 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
RelayProperties.Name == "UP" or RelayProperties.Name == "UP" or
RelayProperties.Name == "DOWN" RelayProperties.Name == "DOWN"
then then
RelayAudioActivated.SoundId = "" --Bigger relays
RelayAudioDeActivated.SoundId = "" RelayAudioActivated.SoundId = SoundEnums.Otis1960.BigRelayActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.BigRelayDeActivated
RelayProperties.Unique = true
else else
RelayAudioActivated.SoundId = "" --High placed relays for better spatial sound
RelayAudioDeActivated.SoundId = "" if RelayProperties.Name == "F1C" or
RelayProperties.Name == "F2C" or
RelayProperties.Name == "F3C" or
RelayProperties.Name == "F4C" or
RelayProperties.Name == "F5C" or
RelayProperties.Name == "F6C" or
RelayProperties.Name == "F7C" or
RelayProperties.Name == "F8C" or
RelayProperties.Name == "F9C" or
RelayProperties.Name == "F10C"
then
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayHighActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
else
--Low placed relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayLowActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
end
end end
RelayAudioActivated.Parent = RelayProperties.Inst RelayAudioActivated.Parent = RelayProperties.Inst
RelayAudioDeActivated.Parent = RelayProperties.Inst
end end
RelayProperties.PhysicalSound.Activated = RelayAudioActivated
RelayProperties.PhysicalSound.DeActivated = RelayAudioDeActivated
else else
warn() warn(`Physical Relay: Inst was not present! the relay will physically not work. Inst={RelayProperties.Inst}`)
end end
end end
@@ -80,24 +95,49 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
}, PhysicalRelay) }, PhysicalRelay)
end end
local Animation = Tween.constructor(TweenInfo.new(PhysicalRelay.AnimationTime, Enum.EasingStyle.Linear)) local OtimAnimation = Tween.constructor(TweenInfo.new(.02, Enum.EasingStyle.Linear))
local function OtimRelayAnimation(Relay: BasePart, State: boolean) local function OtimRelayAnimation(Relay: Tags.RelayProperties, State: boolean)
local T = Animation:Start(Relay, { Relay.ActiveState = State
CFrame = Relay.CFrame*CFrame.Angles(math.rad(State and PhysicalRelay.ActivatedAngle or PhysicalRelay.DeActivatedAngle), 0, 0)
local RelayAnimation = OtimAnimation:Start(Relay.Inst :: BasePart, {
CFrame = (
Relay.Unique and CFrame.new((Relay.Inst :: BasePart).Position) or (Relay.Inst :: BasePart).CFrame
)*CFrame.Angles(
math.rad(State and (Relay.Unique and 1.5 or 13) or (Relay.Unique and -15 or -13)),
0,
Relay.Unique and math.rad(-90) or 0
)
}) })
T.Completed:Once(function() if State then
--If .Inst is present then it is safe to be calling these
(Relay.PhysicalSound.Activated :: Sound):Play() --Theres a small start delay to the sound... oops, im not a pro at audio editing
else
RelayAnimation.Completed:Once(function()
(Relay.PhysicalSound.DeActivated :: Sound):Play()
end) end)
end end
end
function PhysicalRelay:SetState(RelayName, State) function PhysicalRelay:SetState(RelayName, State, ActivateImmediately)
local Relay = self.RelayTagList[`RelayButton_{RelayName}`] local Relay = self.RelayTagList[`RelayButton_{RelayName}`]
if Relay then if Relay then
if Relay.Inst then
if self.ElevatorModel == Enums.Elevator.Otis1960 then if self.ElevatorModel == Enums.Elevator.Otis1960 then
OtimRelayAnimation(Relay.Inst :: BasePart, State) if State ~= Relay.ActiveState then
if ActivateImmediately then
OtimRelayAnimation(Relay, State)
else
task.delay(Random.new():NextNumber(.1,.8), function()
OtimRelayAnimation(Relay, State)
end)
end
end
end
else
warn(`Physical Relay "{RelayName}" has no Inst! Inst={Relay.Inst}`)
end end
else else
warn(`Physical Relay "{RelayName}" does not exist! it will physically not work`) warn(`Physical Relay "{RelayName}" does not exist! it will physically not work`)

View File

@@ -206,6 +206,7 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
FloorTracker:Disconnect() FloorTracker:Disconnect()
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?) self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
self.PhysicalRelays:SetState(`F{ButtonFloor}C`, false, true)
ButtonTree.Prompt.Enabled = true ButtonTree.Prompt.Enabled = true
end end
end) end)
@@ -326,12 +327,16 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
local LanternDisplay = TagsConstructor:Request("Otis1960_LanternDisplayMain") :: UnionOperation local LanternDisplay = TagsConstructor:Request("Otis1960_LanternDisplayMain") :: UnionOperation
self.MOConstructor = MovingObjects.constructor({MachineRoom = self.MachineRoom} :: MovingObjects.InstanceTree) self.MOConstructor = MovingObjects.constructor({MachineRoom = self.MachineRoom} :: MovingObjects.InstanceTree)
--Start the hall displays --Start the hall displays
self.HallDisplaysConstructor = HallDisplays.constructor(Attributes.CurrentFloor, self.HallDisplays) self.HallDisplaysConstructor = HallDisplays.constructor(Attributes.CurrentFloor, self.HallDisplays)
--Init the doors --Init the doors
self.ElevatorDoorsConstructor = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor) self.ElevatorDoorsConstructor = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
--Init the ropes --Init the ropes
self.TractionRopesConstructor = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, LevelingModule.Leveling) self.TractionRopesConstructor = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, LevelingModule.Leveling)
--Init the lanterns --Init the lanterns
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, LanternsTags, Elevator.Sounds, Elevator.Colors) self.LanternsConstructor = Lanterns.constructor(LanternDisplay, LanternsTags, Elevator.Sounds, Elevator.Colors)
@@ -388,6 +393,11 @@ local function Leveled(self: ClassConstructor, RequestedLevel: number)
--self.BoxAlignPosition.MaxVelocity = 0 --self.BoxAlignPosition.MaxVelocity = 0
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value) self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
self.PhysicalRelays:SetState("UP", false, false)
self.PhysicalRelays:SetState("DOWN", false, false)
self.PhysicalRelays:SetState("440 V", false, false)
self.PhysicalRelays:SetState("240 V", false, false)
task.wait(Elevator.QueueWaitTime) task.wait(Elevator.QueueWaitTime)
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel) local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
@@ -402,6 +412,7 @@ local function Leveled(self: ClassConstructor, RequestedLevel: number)
end end
local function Leveling(self: ClassConstructor, RequestedLevel: number) local function Leveling(self: ClassConstructor, RequestedLevel: number)
self.PhysicalRelays:SetState("440 V", false, false)
self.BoxAlignPosition.MaxVelocity = 1 self.BoxAlignPosition.MaxVelocity = 1
self.LanternsConstructor:Toggle(true, RequestedLevel) self.LanternsConstructor:Toggle(true, RequestedLevel)
end end
@@ -440,6 +451,9 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
Attributes.Relay.Goal.Value = RequestedLevel Attributes.Relay.Goal.Value = RequestedLevel
Attributes.Moving.Value = true Attributes.Moving.Value = true
self.PhysicalRelays:SetState(GoingUp and "UP" or "DOWN", true, false) --Maybe i should move GoingUp to a Relay attribute
self.PhysicalRelays:SetState("240 V", true, false)
self.PhysicalRelays:SetState("440 V", true, false)
self.MOConstructor:UpdateCFrame() self.MOConstructor:UpdateCFrame()
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt) self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
@@ -508,7 +522,11 @@ function Elevator:RequestLevelAsync(RequestedLevel)
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel) local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel) local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
--Mmm... temporary, cant distinguish here if this will be a cab or hall call
self.PhysicalRelays:SetState(`F{RequestedLevel}C`, true, true)
if Proceeding then if Proceeding then
self.PhysicalRelays:SetState("RUN", true, false) --This needs to be on a timer for the generator after 60 seconds
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel) self:__MoveToAsync(ElevatorGoingUp, RequestedLevel)
end end
return true return true

View File

@@ -9,10 +9,11 @@ export type Otis1960Sounds = typeof(SoundEnums.Otis1960)
export type Otis1960LanternChimeDirection = "rbxassetid://16990287228" export type Otis1960LanternChimeDirection = "rbxassetid://16990287228"
export type Otis1960LanternChimeLanding = "rbxassetid://16990290265" export type Otis1960LanternChimeLanding = "rbxassetid://16990290265"
export type Otis1960DoorClosingClick = "rbxassetid://16357740945" export type Otis1960DoorClosingClick = "rbxassetid://16357740945"
export type Otis1960RelayActivated = "" export type Otis1960RelayHighActivated = "rbxassetid://17701794271"
export type Otis1960RelayDeActivated = "" export type Otis1960RelayLowActivated = "rbxassetid://17701796245"
export type Otis1960BigRelayActivated = "" export type Otis1960RelayDeActivated = "rbxassetid://17702004158"
export type Otis1960BigRelayDeActivated = "" export type Otis1960BigRelayActivated = "rbxassetid://17701707630"
export type Otis1960BigRelayDeActivated = "rbxassetid://17701712012"
export type Otis1960SoundValues = Otis1960LanternChimeDirection | export type Otis1960SoundValues = Otis1960LanternChimeDirection |
Otis1960LanternChimeLanding | Otis1960LanternChimeLanding |
@@ -22,10 +23,11 @@ SoundEnums.Otis1960 = {
LanternChimeDirection = "rbxassetid://16990287228" :: Otis1960LanternChimeDirection, LanternChimeDirection = "rbxassetid://16990287228" :: Otis1960LanternChimeDirection,
LanternChimeLanding = "rbxassetid://16990290265" :: Otis1960LanternChimeLanding, LanternChimeLanding = "rbxassetid://16990290265" :: Otis1960LanternChimeLanding,
DoorClosingClick = "rbxassetid://16357740945" :: Otis1960DoorClosingClick, DoorClosingClick = "rbxassetid://16357740945" :: Otis1960DoorClosingClick,
RelayActivated = "" :: Otis1960RelayActivated, RelayHighActivated = "rbxassetid://17701794271" :: Otis1960RelayHighActivated,
RelayDeActivated = "" :: Otis1960RelayDeActivated, RelayLowActivated = "rbxassetid://17701796245" :: Otis1960RelayLowActivated,
BigRelayActivated = "" :: Otis1960BigRelayActivated, RelayDeActivated = "rbxassetid://17702004158" :: Otis1960RelayDeActivated,
BigRealyDeActivated = "" :: Otis1960BigRelayDeActivated, BigRelayActivated = "rbxassetid://17701707630" :: Otis1960BigRelayActivated,
BigRelayDeActivated = "rbxassetid://17701712012" :: Otis1960BigRelayDeActivated,
} }
return SoundEnums return SoundEnums

View File

@@ -138,7 +138,10 @@ function ButtonsModule:CreatePromptButtons()
Inst = Inst, Inst = Inst,
Prompt = Prompt, Prompt = Prompt,
Attachment = Attachment, Attachment = Attachment,
Name = Name Name = Name,
Unique = false,
ActiveState = false,
PhysicalSound = {}
} }
else else
Attachment:Destroy() Attachment:Destroy()

View File

@@ -98,12 +98,25 @@ export type ButtonDictionary = {
[string]: ButtonProperties [string]: ButtonProperties
} }
export type RelayProperties = ButtonProperties & {
Unique: boolean,
ActiveState: boolean,
PhysicalSound: {
Activated: Sound?,
DeActivated: Sound?
}
}
export type RelayDictionary = {
[string]: RelayProperties
}
export type ButtonsTree = { export type ButtonsTree = {
[Enums.ElevatorValues]: { [Enums.ElevatorValues]: {
Car: ButtonDictionary, Car: ButtonDictionary,
Landing: ButtonDictionary, Landing: ButtonDictionary,
Special: ButtonDictionary, Special: ButtonDictionary,
Relays: ButtonDictionary Relays: RelayDictionary
} }
} }

View File

@@ -2,26 +2,28 @@
--!native --!native
--!strict --!strict
type TweenAnimation = { --Weird type hack for allowing more than 1 property to be defined inside a tween
[string]: any --Couldnt get type packs working
type TweenAnimation<T,U> = {
[string]: T | U --I hate "any"
} }
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type ClassConstructor<T,U> = typeof(setmetatable({} :: Constructor_Return_Props<T,U>, {} :: Impl_Constructor))
type Impl_Constructor = { type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
Start: (self: ClassConstructor, PostInstance: Instance?, PostProperties: TweenAnimation?, PostTweenSettings: TweenInfo?) -> Tween, Start: <T,U>(self: ClassConstructor<T,U>, PostInstance: Instance?, PostProperties: TweenAnimation<T,U>?, PostTweenSettings: TweenInfo?) -> Tween,
} }
type Constructor_Fun = (TweenSettings: TweenInfo?, Object: Instance?, PreProperties: TweenAnimation?) -> ClassConstructor type Constructor_Fun = <T,U>(TweenSettings: TweenInfo?, Object: Instance?, PreProperties: TweenAnimation<T,U>?) -> ClassConstructor<T,U>
type Constructor_Return_Props = { type Constructor_Return_Props<T,U> = {
TweenInfo: TweenInfo?, TweenInfo: TweenInfo?,
Instance: Instance?, Instance: Instance?,
PreProperties: TweenAnimation?, PreProperties: TweenAnimation<T,U>?,
} }
export type TweenClass = ClassConstructor export type TweenClass<T,U> = ClassConstructor<T,U>
export type TweenConstructor = Impl_Constructor export type TweenConstructor = Impl_Constructor
local Tween = {} :: Impl_Constructor local Tween = {} :: Impl_Constructor
@@ -37,7 +39,7 @@ function Tween.constructor(TweenSettings, Object, PreProperties)
}, Tween) }, Tween)
end end
function Tween:Start(PostInstance, PostProperties, PostTweenSettings) function Tween:Start<T,U>(PostInstance, PostProperties, PostTweenSettings)
local Props = self.PreProperties local Props = self.PreProperties
local Object = self.Instance local Object = self.Instance
local TweenSettings = self.TweenInfo local TweenSettings = self.TweenInfo
@@ -45,7 +47,7 @@ function Tween:Start(PostInstance, PostProperties, PostTweenSettings)
if PostProperties then if PostProperties then
if self.PreProperties then if self.PreProperties then
if Props then if Props then
print("Tween library: Combining PostProperties and PreProperties together", debug.traceback()) warn("Tween library: Combining PostProperties and PreProperties together", debug.traceback())
for tween_prop, tween_value in PostProperties do for tween_prop, tween_value in PostProperties do
Props[tween_prop] = tween_value Props[tween_prop] = tween_value
end end
@@ -56,13 +58,13 @@ function Tween:Start(PostInstance, PostProperties, PostTweenSettings)
end end
if PostInstance then if PostInstance then
if Object then if Object then
print("Tween library: Overwriting an already defined animating object old=", Object, "new=", PostInstance, debug.traceback()) warn("Tween library: Overwriting an already defined animating object old=", Object, "new=", PostInstance, debug.traceback())
end end
Object = PostInstance Object = PostInstance
end end
if PostTweenSettings then if PostTweenSettings then
if TweenSettings then if TweenSettings then
print("Tween library: Overwriting already defined Tween settings", debug.traceback()) warn("Tween library: Overwriting already defined Tween settings", debug.traceback())
end end
TweenSettings = PostTweenSettings TweenSettings = PostTweenSettings
end end