Physical Relays

This commit is contained in:
2024-06-03 01:42:05 -04:00
parent b58febf7ec
commit 9fe7fa1621
6 changed files with 75 additions and 40 deletions

View File

@@ -0,0 +1,3 @@
--!optimize 2
--!native
--!strict

View File

@@ -35,10 +35,9 @@ type Impl_Static_Props = {
AestheticDeactivateTime: number
}
type Constructor_Fun = (ElevatorAttributes: ElevatorAttributes, ElevatorEvents: ElevatorEvents, ElevatorButtonColors: ElevatorButtonColors) -> ClassConstructor
type Constructor_Fun = (ElevatorAttributes: ElevatorAttributes, ElevatorButtonColors: ElevatorButtonColors) -> ClassConstructor
type Constructor_Return_Props = {
ElevatorAttributes: ElevatorAttributes,
ElevatorEvents: ElevatorEvents,
ElevatorButtonColors: ElevatorButtonColors
}
@@ -69,10 +68,9 @@ ButtonFunctions.ButtonHoldDuration = .30
ButtonFunctions.AestheticDeactivateTime = .30
--ButtonTags.ButtonsConstructor
function ButtonFunctions.constructor(ElevatorAttributes, ElevatorEvents, ElevatorButtonColors)
function ButtonFunctions.constructor(ElevatorAttributes, ElevatorButtonColors)
return setmetatable({
ElevatorAttributes = ElevatorAttributes,
ElevatorEvents = ElevatorEvents,
ElevatorButtonColors = ElevatorButtonColors
}, ButtonFunctions)
end
@@ -84,7 +82,6 @@ function ButtonFunctions:CarButton(ButtonID, ButtonTree, Callback, Fallback)
local Prompt = PromptModule.constructor(ButtonTree.Prompt :: ProximityPrompt, ButtonTree.Inst :: Instance)
Prompt:Triggered(function(Player: Player, _, __)
self.ElevatorEvents.ButtonActivated:Fire(Enums.Button.Car, ButtonID, self, ButtonTree)
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
if DecodedCarFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
@@ -107,7 +104,6 @@ function ButtonFunctions:LandingButton(ButtonID, ButtonTree, Callback, Fallback)
local Prompt = PromptModule.constructor(ButtonTree.Prompt :: ProximityPrompt, ButtonTree.Inst :: Instance)
Prompt:Triggered(function(Player: Player, _, __)
self.ElevatorEvents.ButtonActivated:Fire(Enums.Button.Landing, ButtonID, self, ButtonTree)
self:AestheticActivateButton(ButtonTree.Inst :: BasePart)
if DecodedHallFloorTag == self.ElevatorAttributes.CurrentFloor.Value then
@@ -130,13 +126,12 @@ function ButtonFunctions:SpecialButton(ButtonID, ButtonName, ButtonTree, Callbac
local Toggled = false
Prompt:Triggered(function(Player: Player, _, __)
self.ElevatorEvents.ButtonActivated:Fire(Enums.SpecialButton.Stop, ButtonID, self, ButtonTree)
Toggled = not Toggled
Callback(Toggled)
end)
else
warn()
warn(``)
end
end

View File

@@ -15,18 +15,18 @@ local SoundEnums = require(Main:WaitForChild("Enums"):WaitForChild("Sounds"))
type DoorSensors = {
[string]: BasePart
}
type CustomTween = Tween.TweenClass
type CustomTween<T,U> = Tween.TweenClass<T,U>
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
__DetectSensorHit: (self: ClassConstructor, DoorTween1: Tween, DoorTween2: Tween) -> RBXScriptConnection,
ToggleElevatorDoorsAsync: (self: ClassConstructor, opening: boolean, floor: number) -> ()
__DetectSensorHit: <T,U>(self: ClassConstructor<T,U>, DoorTween1: Tween, DoorTween2: Tween) -> RBXScriptConnection,
ToggleElevatorDoorsAsync: <T,U>(self: ClassConstructor<T,U>, opening: boolean, floor: number) -> ()
} & Impl_Static_Props
type Constructor_Fun = (FloorDoorsTags: Tags.LandingTags, ElevatorBox: BasePart, ElevatorDoor1: BasePart, ElevatorDoor2: BasePart, ElevatorDoorSensor: Folder) -> ClassConstructor
type Constructor_Fun = <T,U>(FloorDoorsTags: Tags.LandingTags, ElevatorBox: BasePart, ElevatorDoor1: BasePart, ElevatorDoor2: BasePart, ElevatorDoorSensor: Folder) -> ClassConstructor<T,U>
type Impl_Static_Props = {
Sensors: boolean,
Door1Stopped_X: Vector3,
@@ -37,10 +37,11 @@ type Impl_Static_Props = {
Attributes: {} & RelayAttributes
}
type Constructor_Return_Props = {
type Constructor_Return_Props<T,U> = {
FloorDoorsTags: Tags.LandingTags,
DoorTween1: CustomTween,
DoorTween2: CustomTween,
DoorTween1: CustomTween<T,U>,
DoorTween2: CustomTween<T,U>,
DoorSensor: DoorSensors,
ElevatorBox: BasePart,
ElevatorDoor1: BasePart,
@@ -59,7 +60,7 @@ export type RelayAttributes = {
}
}
export type DoorConstructor = ClassConstructor
export type DoorConstructor<T,U> = ClassConstructor<T,U>
local Doors = {} :: Impl_Constructor
Doors.__index = Doors
@@ -172,7 +173,7 @@ local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, openi
return Door1Tween_Floor, Door2Tween_Floor
end
local function ElevatorDoorsAnimationAsync(self: ClassConstructor, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
--Roblox physics will freak out
self.ElevatorDoor1.CanCollide = false
self.ElevatorDoor2.CanCollide = false
@@ -254,7 +255,7 @@ for n: number = 1, #workspace_items do
end
end
function Doors:__DetectSensorHit(DoorTween1, DoorTween2)
function Doors:__DetectSensorHit<T,U>(DoorTween1, DoorTween2)
local Step = nil
if Doors.Sensors and Attributes.Relay.Open.Value then
@@ -276,7 +277,7 @@ function Doors:__DetectSensorHit(DoorTween1, DoorTween2)
return Step
end
function Doors:ToggleElevatorDoorsAsync(opening, floor)
function Doors:ToggleElevatorDoorsAsync<T,U>(opening, floor)
--short circuiting central
if opening then
if Attributes.Relay.Open.Value then

View File

@@ -10,6 +10,7 @@ local LoadDir = MainDir:WaitForChild("Load")
local SoundEnums = require(EnumsDir:WaitForChild("Sounds"))
local Storage = game:GetService("ReplicatedStorage")
local SS = game:GetService("SoundService")
local Tween = require(Storage:WaitForChild("Tween"))
local Enums = require(Storage:WaitForChild("Enums"))
@@ -29,12 +30,43 @@ type Constructor_Return_Props = {
RelayTagList: Tags.RelayDictionary
}
type SoundEffects = {
SoundGroup: SoundGroup,
}
type OtimSoundEffects = SoundEffects & {
EqualizerSoundEffect: EqualizerSoundEffect
}
export type PhysicalRelayConstructor = ClassConstructor
local PhysicalRelay = {} :: Impl_Constructor
PhysicalRelay.__index = PhysicalRelay
local function OtimLowPassSoundEffect(Model: Enums.ElevatorValues): OtimSoundEffects
local SoundGroup = Instance.new("SoundGroup") :: SoundGroup
SoundGroup.Volume = .5
local EqualizerSoundEffect = Instance.new("EqualizerSoundEffect") :: EqualizerSoundEffect
EqualizerSoundEffect.HighGain = -20
EqualizerSoundEffect.LowGain = 10
EqualizerSoundEffect.MidGain = -10
EqualizerSoundEffect.Parent = SoundGroup
SoundGroup.Parent = SS
return {
SoundGroup = SoundGroup,
EqualizerSoundEffect = EqualizerSoundEffect
}
end
function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
local SoundEffects: OtimSoundEffects?
if ElevatorModel == Enums.Elevator.Otis1960 then
SoundEffects = OtimLowPassSoundEffect(Elevators)
end
--Idk how to construct an ideal way to identify these,
--Hard coding it is
for RelayName, RelayProperties in RelayTagList do
@@ -43,18 +75,22 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
local RelayAudioActivated = Instance.new("Sound") :: Sound
local RelayAudioDeActivated = Instance.new("Sound") :: Sound
RelayAudioActivated.Volume = .5
RelayAudioDeActivated.Volume = .5
if ElevatorModel == Enums.Elevator.Otis1960 then
RelayAudioActivated.SoundGroup = (SoundEffects :: OtimSoundEffects).SoundGroup
RelayAudioDeActivated.SoundGroup = (SoundEffects :: OtimSoundEffects).SoundGroup
if RelayProperties.Name == "240 V" or
RelayProperties.Name == "440 V" or
RelayProperties.Name == "UP" or
RelayProperties.Name == "DOWN"
RelayProperties.Name == "DOWN"
then
--Bigger relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.BigRelayActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.BigRelayDeActivated
RelayAudioActivated.Volume = .5
RelayAudioDeActivated.Volume = .5
RelayProperties.Unique = true
else
--High placed relays for better spatial sound
@@ -71,13 +107,19 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
then
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayHighActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
if RelayProperties.Prompt then
RelayProperties.Prompt.MaxActivationDistance = 4
end
else
--Low placed relays
--Low placed relays
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayLowActivated
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
end
end
RelayAudioActivated.RollOffMaxDistance = 130
RelayAudioActivated.RollOffMinDistance = 5
RelayAudioActivated.Parent = RelayProperties.Inst
RelayAudioDeActivated.Parent = RelayProperties.Inst
end
@@ -98,8 +140,6 @@ end
local OtimAnimation = Tween.constructor(TweenInfo.new(.02, Enum.EasingStyle.Linear))
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
@@ -125,8 +165,10 @@ function PhysicalRelay:SetState(RelayName, State, ActivateImmediately)
if Relay then
if Relay.Inst then
if self.ElevatorModel == Enums.Elevator.Otis1960 then
if State ~= Relay.ActiveState then
if State ~= Relay.ActiveState then
if self.ElevatorModel == Enums.Elevator.Otis1960 then
Relay.ActiveState = State
if ActivateImmediately then
OtimRelayAnimation(Relay, State)
else

View File

@@ -91,9 +91,6 @@ type Impl_Static_Props = {
GoalYLevel: NumberValue,
ReadyForMoving: BoolValue,
}
},
Events: {
ButtonActivated: BindableEvent
}
}
@@ -173,10 +170,6 @@ Elevator.Attributes = {
},
}
Elevator.Events = {
ButtonActivated = Instance.new("BindableEvent") :: BindableEvent
}
Elevator.Attributes.CurrentFloor.Value = 1
Elevator.Attributes.Moving.Value = false
Elevator.Attributes.GoingUp.Value = false
@@ -343,7 +336,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
local ButtonsTagsConstructor = ButtonTags.constructor(TagsConstructor, ButtonsTags, Elevator.Name)
local Otis1960_Buttons = ButtonsTagsConstructor:CreatePromptButtons()
self.ButtonsConstructor = Buttons.constructor(Elevator.Attributes, Elevator.Events, Elevator.Colors)
self.ButtonsConstructor = Buttons.constructor(Elevator.Attributes, Elevator.Colors)
self.HallDisplaysConstructor:BindHallDisplays()
@@ -393,8 +386,8 @@ 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("UP", false, false)
self.PhysicalRelays:SetState("DOWN", false, false)
self.PhysicalRelays:SetState("440 V", false, false)
self.PhysicalRelays:SetState("240 V", false, false)
@@ -413,6 +406,7 @@ 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
@@ -451,7 +445,7 @@ 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(GoingUp and "UP" or "DOWN", true, false)
self.PhysicalRelays:SetState("240 V", true, false)
self.PhysicalRelays:SetState("440 V", true, false)
self.MOConstructor:UpdateCFrame()

View File

@@ -55,7 +55,7 @@ Enums.Elevator = {
Enums.InteractType = {
LightSwitch = "LightSwitch" :: "LightSwitch",
Light = "Light" :: "Light",
Light = "Light" :: "Light",
LightSource = "LightSource" :: "LightSource"
}