private void OnActivated(EntityUid uid, TwoWayLeverComponent component, ActivateInWorldEvent args) { if (args.Handled) { return; } component.State = component.State switch { TwoWayLeverState.Middle => component.NextSignalLeft ? TwoWayLeverState.Left : TwoWayLeverState.Right, TwoWayLeverState.Right => TwoWayLeverState.Middle, TwoWayLeverState.Left => TwoWayLeverState.Middle, _ => throw new ArgumentOutOfRangeException() }; if (component.State == TwoWayLeverState.Middle) { component.NextSignalLeft = !component.NextSignalLeft; } if (TryComp(uid, out AppearanceComponent? appearanceComponent)) { appearanceComponent.SetData(TwoWayLeverVisuals.State, component.State); } var port = component.State switch { TwoWayLeverState.Left => component.LeftPort, TwoWayLeverState.Right => component.RightPort, TwoWayLeverState.Middle => component.MiddlePort, _ => throw new ArgumentOutOfRangeException() }; _signalSystem.InvokePort(uid, port); args.Handled = true; } } }
private void OnInteractHand(EntityUid uid, TwoWayLeverComponent component, InteractHandEvent args) { component.State = component.State switch { TwoWayLeverSignal.Middle => component.NextSignalLeft ? TwoWayLeverSignal.Left : TwoWayLeverSignal.Right, TwoWayLeverSignal.Right => TwoWayLeverSignal.Middle, TwoWayLeverSignal.Left => TwoWayLeverSignal.Middle, _ => throw new ArgumentOutOfRangeException() }; if (component.State == TwoWayLeverSignal.Middle) { component.NextSignalLeft = !component.NextSignalLeft; } if (EntityManager.TryGetComponent <AppearanceComponent>(uid, out var appearanceComponent)) { appearanceComponent.SetData(TwoWayLeverVisuals.State, component.State); } RaiseLocalEvent(uid, new InvokePortEvent("state", component.State)); args.Handled = true; } }
private void OnInit(EntityUid uid, TwoWayLeverComponent component, ComponentInit args) { _signalSystem.EnsureTransmitterPorts(uid, component.LeftPort, component.RightPort, component.MiddlePort); }
private void OnSignalValueRequested(EntityUid uid, TwoWayLeverComponent component, SignalValueRequestedEvent args) { args.Signal = component.State; args.Handled = true; }