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
- Activated #Color3
- The color that is shown on the <a>Light Props</a> once
@@ -11,7 +11,4 @@
* `Interact` - *Interact Initializer* [`Not Changable`]
* `LightSwitch` - *Interaction Type* [`Not 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 MainDir = Elevators.Parent.Parent
local EnumsDir = MainDir:WaitForChild("Enums")
local LoadDir = MainDir:WaitForChild("Load")
local SoundEnums = require(EnumsDir:WaitForChild("Sounds"))
local Storage = game:GetService("ReplicatedStorage")
local Tween = require(Storage:WaitForChild("Tween"))
@@ -17,22 +20,13 @@ 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
SetState: (self: ClassConstructor, RelayName: string, State: boolean, ActivateImmediately: boolean) -> ()
}
type Constructor_Fun = (ElevatorModel: Enums.ElevatorValues, RelayTagList: Tags.ButtonDictionary) -> ClassConstructor
type Constructor_Fun = (ElevatorModel: Enums.ElevatorValues, RelayTagList: Tags.RelayDictionary) -> ClassConstructor
type Constructor_Return_Props = {
ElevatorModel: Enums.ElevatorValues,
RelayTagList: Tags.ButtonDictionary & {
AudioActivated: Sound,
AudoDeactivated: Sound
}
RelayTagList: Tags.RelayDictionary
}
export type PhysicalRelayConstructor = ClassConstructor
@@ -40,19 +34,17 @@ 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
--Audio
local RelayAudioActivated = Instance.new("Sound") :: Sound
local RelayAudioDeActivated = Instance.new("Sound") :: Sound
RelayAudioActivated.Volume = .5
RelayAudioDeActivated.Volume = .5
if ElevatorModel == Enums.Elevator.Otis1960 then
if RelayProperties.Name == "240 V" or
@@ -60,17 +52,40 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
RelayProperties.Name == "UP" or
RelayProperties.Name == "DOWN"
then
RelayAudioActivated.SoundId = ""
RelayAudioDeActivated.SoundId = ""
--Bigger relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.BigRelayActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.BigRelayDeActivated
RelayProperties.Unique = true
else
RelayAudioActivated.SoundId = ""
RelayAudioDeActivated.SoundId = ""
--High placed relays for better spatial sound
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
RelayAudioActivated.Parent = RelayProperties.Inst
RelayAudioActivated.Parent = RelayProperties.Inst
RelayAudioDeActivated.Parent = RelayProperties.Inst
end
RelayProperties.PhysicalSound.Activated = RelayAudioActivated
RelayProperties.PhysicalSound.DeActivated = RelayAudioDeActivated
else
warn()
warn(`Physical Relay: Inst was not present! the relay will physically not work. Inst={RelayProperties.Inst}`)
end
end
@@ -80,24 +95,49 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
}, PhysicalRelay)
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 T = Animation:Start(Relay, {
CFrame = Relay.CFrame*CFrame.Angles(math.rad(State and PhysicalRelay.ActivatedAngle or PhysicalRelay.DeActivatedAngle), 0, 0)
local function OtimRelayAnimation(Relay: Tags.RelayProperties, State: boolean)
Relay.ActiveState = State
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()
end)
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
function PhysicalRelay:SetState(RelayName, State)
function PhysicalRelay:SetState(RelayName, State, ActivateImmediately)
local Relay = self.RelayTagList[`RelayButton_{RelayName}`]
if Relay then
if self.ElevatorModel == Enums.Elevator.Otis1960 then
OtimRelayAnimation(Relay.Inst :: BasePart, State)
if Relay.Inst then
if self.ElevatorModel == Enums.Elevator.Otis1960 then
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
else
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()
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
self.PhysicalRelays:SetState(`F{ButtonFloor}C`, false, true)
ButtonTree.Prompt.Enabled = true
end
end)
@@ -326,12 +327,16 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
local LanternDisplay = TagsConstructor:Request("Otis1960_LanternDisplayMain") :: UnionOperation
self.MOConstructor = MovingObjects.constructor({MachineRoom = self.MachineRoom} :: MovingObjects.InstanceTree)
--Start the hall displays
self.HallDisplaysConstructor = HallDisplays.constructor(Attributes.CurrentFloor, self.HallDisplays)
--Init the doors
self.ElevatorDoorsConstructor = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
--Init the ropes
self.TractionRopesConstructor = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, LevelingModule.Leveling)
--Init the lanterns
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.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)
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
@@ -402,6 +412,7 @@ local function Leveled(self: ClassConstructor, RequestedLevel: number)
end
local function Leveling(self: ClassConstructor, RequestedLevel: number)
self.PhysicalRelays:SetState("440 V", false, false)
self.BoxAlignPosition.MaxVelocity = 1
self.LanternsConstructor:Toggle(true, RequestedLevel)
end
@@ -440,6 +451,9 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
Attributes.Relay.Goal.Value = RequestedLevel
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.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
@@ -508,7 +522,11 @@ function Elevator:RequestLevelAsync(RequestedLevel)
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, 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
self.PhysicalRelays:SetState("RUN", true, false) --This needs to be on a timer for the generator after 60 seconds
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel)
end
return true

View File

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

View File

@@ -97,8 +97,8 @@ function ButtonsModule:CreatePromptButtons()
Prompt.ObjectText = "Floor"
self.Buttons[self.ElevatorModel].Car[`{Split[2]}_{Split[3]}`] = {
Inst = Inst,
Prompt = Prompt,
Inst = Inst,
Prompt = Prompt,
Attachment = Attachment
}
elseif ButtonType == Enums.Button.Landing then
@@ -109,10 +109,10 @@ function ButtonsModule:CreatePromptButtons()
Prompt.ObjectText = `Floor {tostring(Split[4])}`
self.Buttons[self.ElevatorModel].Landing[`{Split[2]}_{Split[3]}_{Split[4]}_{Split[5]}`] = {
Inst = Inst,
Prompt = Prompt,
Inst = Inst,
Prompt = Prompt,
Attachment = Attachment,
Name = Name
Name = Name
}
elseif ButtonType == Enums.Button.Special then
--ElevatorButton_Open
@@ -122,10 +122,10 @@ function ButtonsModule:CreatePromptButtons()
Prompt.ObjectText = "Elevator"
self.Buttons[self.ElevatorModel].Special[`{Split[2]}_{Split[3]}`] = {
Inst = Inst,
Prompt = Prompt,
Inst = Inst,
Prompt = Prompt,
Attachment = Attachment,
Name = Name
Name = Name
}
elseif ButtonType == Enums.Button.Relay then
local Name = tostring(Split[3])
@@ -135,10 +135,13 @@ function ButtonsModule:CreatePromptButtons()
Prompt.ObjectText = "Relay"
self.Buttons[self.ElevatorModel].Relays[`{Split[2]}_{Split[3]}`] = {
Inst = Inst,
Prompt = Prompt,
Attachment = Attachment,
Name = Name
Inst = Inst,
Prompt = Prompt,
Attachment = Attachment,
Name = Name,
Unique = false,
ActiveState = false,
PhysicalSound = {}
}
else
Attachment:Destroy()

View File

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

View File

@@ -2,26 +2,28 @@
--!native
--!strict
type TweenAnimation = {
[string]: any
--Weird type hack for allowing more than 1 property to be defined inside a tween
--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 = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--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_Return_Props = {
type Constructor_Fun = <T,U>(TweenSettings: TweenInfo?, Object: Instance?, PreProperties: TweenAnimation<T,U>?) -> ClassConstructor<T,U>
type Constructor_Return_Props<T,U> = {
TweenInfo: TweenInfo?,
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
local Tween = {} :: Impl_Constructor
@@ -37,7 +39,7 @@ function Tween.constructor(TweenSettings, Object, PreProperties)
}, Tween)
end
function Tween:Start(PostInstance, PostProperties, PostTweenSettings)
function Tween:Start<T,U>(PostInstance, PostProperties, PostTweenSettings)
local Props = self.PreProperties
local Object = self.Instance
local TweenSettings = self.TweenInfo
@@ -45,7 +47,7 @@ function Tween:Start(PostInstance, PostProperties, PostTweenSettings)
if PostProperties then
if self.PreProperties 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
Props[tween_prop] = tween_value
end
@@ -56,13 +58,13 @@ function Tween:Start(PostInstance, PostProperties, PostTweenSettings)
end
if PostInstance 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
Object = PostInstance
end
if PostTweenSettings 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
TweenSettings = PostTweenSettings
end