Replaces PowerReceiver's C# event with a ComponentMessage (#2888)
Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -7,7 +7,6 @@ using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.Arcade;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects.Components.UserInterface;
|
||||
@@ -16,6 +15,7 @@ using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.ComponentDependencies;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -42,6 +42,17 @@ namespace Content.Server.GameObjects.Components.Arcade
|
||||
private IPlayerSession? _player;
|
||||
private readonly List<IPlayerSession> _spectators = new();
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnPowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if(!eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
||||
@@ -109,15 +120,10 @@ namespace Content.Server.GameObjects.Components.Arcade
|
||||
{
|
||||
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
||||
}
|
||||
|
||||
if (_powerReceiverComponent != null)
|
||||
{
|
||||
_powerReceiverComponent.OnPowerStateChanged += OnPowerStateChanged;
|
||||
}
|
||||
_game = new BlockGame(this);
|
||||
}
|
||||
|
||||
private void OnPowerStateChanged(object? sender, PowerStateEventArgs e)
|
||||
private void OnPowerStateChanged(PowerChangedMessage e)
|
||||
{
|
||||
if (e.Powered) return;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.GameObjects.Components.VendingMachines;
|
||||
@@ -100,14 +100,20 @@ namespace Content.Server.GameObjects.Components.Arcade
|
||||
{
|
||||
UserInterface.OnReceiveMessage += UserInterfaceOnOnReceiveMessage;
|
||||
}
|
||||
}
|
||||
|
||||
if (_powerReceiverComponent != null)
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
_powerReceiverComponent.OnPowerStateChanged += OnOnPowerStateChanged;
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnOnPowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOnPowerStateChanged(object? sender, PowerStateEventArgs e)
|
||||
private void OnOnPowerStateChanged(PowerChangedMessage e)
|
||||
{
|
||||
if(e.Powered) return;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -81,25 +82,21 @@ namespace Content.Server.GameObjects.Components.BarSign
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += PowerOnOnPowerStateChanged;
|
||||
}
|
||||
|
||||
UpdateSignInfo();
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged -= PowerOnOnPowerStateChanged;
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerOnOnPowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void PowerOnOnPowerStateChanged(object? sender, PowerStateEventArgs e)
|
||||
private void PowerOnOnPowerStateChanged(PowerChangedMessage e)
|
||||
{
|
||||
UpdateSignInfo();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Timers;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Cargo
|
||||
@@ -25,22 +26,15 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
private List<CargoProductPrototype> _teleportQueue = new List<CargoProductPrototype>();
|
||||
private CargoTelepadState _currentState = CargoTelepadState.Unpowered;
|
||||
|
||||
|
||||
public override void OnAdd()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.OnAdd();
|
||||
|
||||
var receiver = Owner.EnsureComponent<PowerReceiverComponent>();
|
||||
receiver.OnPowerStateChanged += PowerUpdate;
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged -= PowerUpdate;
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerUpdate(powerChanged);
|
||||
break;
|
||||
}
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
public void QueueTeleport(CargoProductPrototype product)
|
||||
@@ -49,7 +43,7 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
TeleportLoop();
|
||||
}
|
||||
|
||||
private void PowerUpdate(object? sender, PowerStateEventArgs args)
|
||||
private void PowerUpdate(PowerChangedMessage args)
|
||||
{
|
||||
if (args.Powered && _currentState == CargoTelepadState.Unpowered) {
|
||||
_currentState = CargoTelepadState.Idle;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -80,11 +80,6 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
_beakerContainer =
|
||||
ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-reagentContainerContainer", Owner);
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += OnPowerChanged;
|
||||
}
|
||||
|
||||
//BufferSolution = Owner.BufferSolution
|
||||
BufferSolution.Solution = new Solution();
|
||||
BufferSolution.MaxVolume = ReagentUnit.New(1000);
|
||||
@@ -92,7 +87,18 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
private void OnPowerChanged(object? sender, PowerStateEventArgs e)
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnPowerChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPowerChanged(PowerChangedMessage e)
|
||||
{
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -83,15 +83,21 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
_beakerContainer =
|
||||
ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-reagentContainerContainer", Owner);
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += OnPowerChanged;
|
||||
}
|
||||
|
||||
InitializeFromPrototype();
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnPowerChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the <c>pack</c> defined in this components yaml prototype
|
||||
/// exists. If so, it fills the reagent inventory list.
|
||||
@@ -111,7 +117,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPowerChanged(object? sender, PowerStateEventArgs e)
|
||||
private void OnPowerChanged(PowerChangedMessage e)
|
||||
{
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -29,8 +30,6 @@ namespace Content.Server.GameObjects.Components
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent powerReceiver))
|
||||
{
|
||||
powerReceiver.OnPowerStateChanged += PowerReceiverOnOnPowerStateChanged;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(ComputerVisuals.Powered, powerReceiver.Powered);
|
||||
@@ -45,17 +44,18 @@ namespace Content.Server.GameObjects.Components
|
||||
CreateComputerBoard();
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent powerReceiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
powerReceiver.OnPowerStateChanged -= PowerReceiverOnOnPowerStateChanged;
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerReceiverOnOnPowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void PowerReceiverOnOnPowerStateChanged(object sender, PowerStateEventArgs e)
|
||||
private void PowerReceiverOnOnPowerStateChanged(PowerChangedMessage e)
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
|
||||
@@ -57,25 +57,18 @@ namespace Content.Server.GameObjects.Components.Conveyor
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnAdd()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.OnAdd();
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged += OnPowerChanged;
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnPowerChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged -= OnPowerChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPowerChanged(object? sender, PowerStateEventArgs e)
|
||||
private void OnPowerChanged(PowerChangedMessage e)
|
||||
{
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -547,7 +547,7 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
UpdateInterface();
|
||||
}
|
||||
|
||||
private void PowerStateChanged(object? sender, PowerStateEventArgs args)
|
||||
private void PowerStateChanged(PowerChangedMessage args)
|
||||
{
|
||||
if (!args.Powered)
|
||||
{
|
||||
@@ -619,11 +619,6 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
physics.AnchoredChanged += UpdateVisualState;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += PowerStateChanged;
|
||||
}
|
||||
|
||||
UpdateTargetList();
|
||||
UpdateVisualState();
|
||||
}
|
||||
@@ -635,11 +630,6 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
physics.AnchoredChanged -= UpdateVisualState;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged -= PowerStateChanged;
|
||||
}
|
||||
|
||||
if (_container != null)
|
||||
{
|
||||
foreach (var entity in _container.ContainedEntities.ToArray())
|
||||
@@ -680,6 +670,10 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
_lastExitAttempt = _gameTiming.CurTime;
|
||||
Remove(msg.Entity);
|
||||
break;
|
||||
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -504,7 +504,7 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
UpdateInterface();
|
||||
}
|
||||
|
||||
private void PowerStateChanged(object? sender, PowerStateEventArgs args)
|
||||
private void PowerStateChanged(PowerChangedMessage args)
|
||||
{
|
||||
if (!args.Powered)
|
||||
{
|
||||
@@ -574,11 +574,6 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
physics.AnchoredChanged += UpdateVisualState;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += PowerStateChanged;
|
||||
}
|
||||
|
||||
UpdateVisualState();
|
||||
}
|
||||
|
||||
@@ -589,11 +584,6 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
physics.AnchoredChanged -= UpdateVisualState;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged -= PowerStateChanged;
|
||||
}
|
||||
|
||||
foreach (var entity in _container.ContainedEntities.ToArray())
|
||||
{
|
||||
_container.ForceRemove(entity);
|
||||
@@ -626,6 +616,10 @@ namespace Content.Server.GameObjects.Components.Disposal
|
||||
_lastExitAttempt = _gameTiming.CurTime;
|
||||
Remove(msg.Entity);
|
||||
break;
|
||||
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -15,6 +15,7 @@ using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components.Timers;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -191,8 +192,6 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += PowerDeviceOnOnPowerStateChanged;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
|
||||
@@ -201,17 +200,18 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged -= PowerDeviceOnOnPowerStateChanged;
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerDeviceOnOnPowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void PowerDeviceOnOnPowerStateChanged(object? sender, PowerStateEventArgs e)
|
||||
private void PowerDeviceOnOnPowerStateChanged(PowerChangedMessage e)
|
||||
{
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -95,14 +95,20 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += OnPowerStateChanged;
|
||||
}
|
||||
|
||||
_audioSystem = EntitySystem.Get<AudioSystem>();
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnPowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
@@ -110,11 +116,6 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
UserInterface.OnReceiveMessage -= UserInterfaceOnReceiveMessage;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged -= OnPowerStateChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message)
|
||||
@@ -166,7 +167,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPowerStateChanged(object? sender, PowerStateEventArgs e)
|
||||
private void OnPowerStateChanged(PowerChangedMessage e)
|
||||
{
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -16,6 +16,7 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.UserInterface;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -119,11 +120,20 @@ namespace Content.Server.GameObjects.Components.PA
|
||||
Logger.Error("ParticleAcceleratorControlBox was created without PowerReceiverComponent");
|
||||
return;
|
||||
}
|
||||
|
||||
_powerReceiverComponent.OnPowerStateChanged += OnPowerStateChanged;
|
||||
_powerReceiverComponent.Load = 250;
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnPowerStateChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
@@ -133,7 +143,7 @@ namespace Content.Server.GameObjects.Components.PA
|
||||
|
||||
// This is the power state for the PA control box itself.
|
||||
// Keep in mind that the PA itself can keep firing as long as the HV cable under the power box has... power.
|
||||
private void OnPowerStateChanged(object? sender, PowerStateEventArgs e)
|
||||
private void OnPowerStateChanged(PowerChangedMessage e)
|
||||
{
|
||||
UpdateAppearance();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
@@ -59,11 +59,6 @@ namespace Content.Server.GameObjects.Components.Power.AME
|
||||
|
||||
Owner.TryGetComponent(out _appearance);
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += OnPowerChanged;
|
||||
}
|
||||
|
||||
Owner.TryGetComponent(out _powerSupplier);
|
||||
|
||||
_injecting = false;
|
||||
@@ -71,6 +66,17 @@ namespace Content.Server.GameObjects.Components.Power.AME
|
||||
_jarSlot = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-fuelJarContainer", Owner);
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
case PowerChangedMessage powerChanged:
|
||||
OnPowerChanged(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnUpdate(float frameTime)
|
||||
{
|
||||
if(!_injecting)
|
||||
@@ -127,7 +133,7 @@ namespace Content.Server.GameObjects.Components.Power.AME
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPowerChanged(object? sender, PowerStateEventArgs e)
|
||||
private void OnPowerChanged(PowerChangedMessage e)
|
||||
{
|
||||
UpdateUserInterface();
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
|
||||
public override string Name => "PowerReceiver";
|
||||
|
||||
public event EventHandler<PowerStateEventArgs>? OnPowerStateChanged;
|
||||
|
||||
[ViewVariables]
|
||||
public bool Powered => (HasApcPower || !NeedsPower) && !PowerDisabled;
|
||||
|
||||
@@ -209,7 +207,8 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
|
||||
private void OnNewPowerState()
|
||||
{
|
||||
OnPowerStateChanged?.Invoke(this, new PowerStateEventArgs(Powered));
|
||||
SendMessage(new PowerChangedMessage(Powered));
|
||||
|
||||
if (Owner.TryGetComponent<AppearanceComponent>(out var appearance))
|
||||
{
|
||||
appearance.SetData(PowerDeviceVisuals.Powered, Powered);
|
||||
@@ -240,11 +239,11 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents
|
||||
}
|
||||
}
|
||||
|
||||
public class PowerStateEventArgs : EventArgs
|
||||
public class PowerChangedMessage : ComponentMessage
|
||||
{
|
||||
public readonly bool Powered;
|
||||
|
||||
public PowerStateEventArgs(bool powered)
|
||||
public PowerChangedMessage(bool powered)
|
||||
{
|
||||
Powered = powered;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
@@ -53,19 +53,21 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
Owner.EnsureComponent<PowerReceiverComponent>();
|
||||
_container = ContainerManagerComponent.Ensure<ContainerSlot>($"{Name}-powerCellContainer", Owner);
|
||||
// Default state in the visualizer is OFF, so when this gets powered on during initialization it will generally show empty
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged += PowerUpdate;
|
||||
case PowerChangedMessage powerChanged:
|
||||
PowerUpdate(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged -= PowerUpdate;
|
||||
}
|
||||
|
||||
_heldBattery = null;
|
||||
|
||||
base.OnRemove();
|
||||
@@ -114,7 +116,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
private void PowerUpdate(object? sender, PowerStateEventArgs eventArgs)
|
||||
private void PowerUpdate(PowerChangedMessage eventArgs)
|
||||
{
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -52,7 +53,7 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
/// <summary>
|
||||
/// For attaching UpdateState() to events.
|
||||
/// </summary>
|
||||
public void UpdateState(object sender, EventArgs e)
|
||||
public void UpdateState(PowerChangedMessage e)
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
@@ -136,30 +137,17 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
public override void OnAdd()
|
||||
{
|
||||
base.OnAdd();
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent receiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged += UpdateState;
|
||||
case PowerChangedMessage powerChanged:
|
||||
UpdateState(powerChanged);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged -= UpdateState;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString($"The battery indicator displays: {BatteryStateText[State]}."));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
@@ -209,19 +209,18 @@ namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerRece
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponent<PowerReceiverComponent>().OnPowerStateChanged += UpdateLight;
|
||||
|
||||
_lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner);
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent component)
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent receiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged -= UpdateLight;
|
||||
case PowerChangedMessage:
|
||||
UpdateLight();
|
||||
break;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
void IMapInit.MapInit()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -119,24 +119,24 @@ namespace Content.Server.GameObjects.Components.VendingMachines
|
||||
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
{
|
||||
receiver.OnPowerStateChanged += UpdatePower;
|
||||
TrySetVisualState(receiver.Powered ? VendingMachineVisualState.Normal : VendingMachineVisualState.Off);
|
||||
}
|
||||
|
||||
InitializeFromPrototype();
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
if (Owner.TryGetComponent(out PowerReceiverComponent? receiver))
|
||||
base.HandleMessage(message, component);
|
||||
switch (message)
|
||||
{
|
||||
receiver.OnPowerStateChanged -= UpdatePower;
|
||||
case PowerChangedMessage powerChanged:
|
||||
UpdatePower(powerChanged);
|
||||
break;
|
||||
}
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
private void UpdatePower(object? sender, PowerStateEventArgs args)
|
||||
private void UpdatePower(PowerChangedMessage args)
|
||||
{
|
||||
var state = args.Powered ? VendingMachineVisualState.Normal : VendingMachineVisualState.Off;
|
||||
TrySetVisualState(state);
|
||||
|
||||
Reference in New Issue
Block a user