mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 21:51:55 +00:00
Physical working relays!
This commit is contained in:
@@ -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`)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user