Nuke PowerChangedMessage (#7231)

This commit is contained in:
metalgearsloth
2022-03-29 03:58:51 +11:00
committed by GitHub
parent 2d610ebb52
commit 49163f1dec
18 changed files with 134 additions and 140 deletions

View File

@@ -1,6 +1,6 @@
using Content.Server.AME.Components; using Content.Server.AME.Components;
using Content.Server.Power.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.AME namespace Content.Server.AME
{ {
@@ -9,19 +9,33 @@ namespace Content.Server.AME
{ {
private float _accumulatedFrameTime; private float _accumulatedFrameTime;
private const float UpdateCooldown = 10f;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AMEControllerComponent, PowerChangedEvent>(OnAMEPowerChange);
}
public override void Update(float frameTime) public override void Update(float frameTime)
{ {
base.Update(frameTime); base.Update(frameTime);
// TODO: Won't exactly work with replays I guess?
_accumulatedFrameTime += frameTime; _accumulatedFrameTime += frameTime;
if (_accumulatedFrameTime >= 10) if (_accumulatedFrameTime >= UpdateCooldown)
{ {
foreach (var comp in EntityManager.EntityQuery<AMEControllerComponent>()) foreach (var comp in EntityManager.EntityQuery<AMEControllerComponent>())
{ {
comp.OnUpdate(frameTime); comp.OnUpdate(frameTime);
} }
_accumulatedFrameTime -= 10; _accumulatedFrameTime -= UpdateCooldown;
} }
}
private static void OnAMEPowerChange(EntityUid uid, AMEControllerComponent component, PowerChangedEvent args)
{
component.UpdateUserInterface();
} }
} }
} }

View File

@@ -62,20 +62,6 @@ namespace Content.Server.AME.Components
_jarSlot = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-fuelJarContainer"); _jarSlot = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-fuelJarContainer");
} }
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
#pragma warning disable 618
base.HandleMessage(message, component);
#pragma warning restore 618
switch (message)
{
case PowerChangedMessage powerChanged:
OnPowerChanged(powerChanged);
break;
}
}
internal void OnUpdate(float frameTime) internal void OnUpdate(float frameTime)
{ {
if (!_injecting) if (!_injecting)
@@ -111,11 +97,6 @@ namespace Content.Server.AME.Components
} }
private void OnPowerChanged(PowerChangedMessage e)
{
UpdateUserInterface();
}
// Used to update core count // Used to update core count
public void OnAMENodeGroupUpdate() public void OnAMENodeGroupUpdate()
{ {
@@ -151,7 +132,7 @@ namespace Content.Server.AME.Components
return true; return true;
} }
private void UpdateUserInterface() public void UpdateUserInterface()
{ {
var state = GetUserInterfaceState(); var state = GetUserInterfaceState();
UserInterface?.SetState(state); UserInterface?.SetState(state);

View File

@@ -0,0 +1,17 @@
using Content.Server.Arcade.Components;
using Content.Server.Power.Components;
namespace Content.Server.Arcade;
public sealed partial class ArcadeSystem
{
private void InitializeBlockGame()
{
SubscribeLocalEvent<BlockGameArcadeComponent, PowerChangedEvent>(OnBlockPowerChanged);
}
private static void OnBlockPowerChanged(EntityUid uid, BlockGameArcadeComponent component, PowerChangedEvent args)
{
component.OnPowerStateChanged(args);
}
}

View File

@@ -0,0 +1,17 @@
using Content.Server.Arcade.Components;
using Content.Server.Power.Components;
namespace Content.Server.Arcade;
public sealed partial class ArcadeSystem
{
private void InitializeSpaceVillain()
{
SubscribeLocalEvent<SpaceVillainArcadeComponent, PowerChangedEvent>(OnSVillainPower);
}
private void OnSVillainPower(EntityUid uid, SpaceVillainArcadeComponent component, PowerChangedEvent args)
{
component.OnPowerStateChanged(args);
}
}

View File

@@ -9,7 +9,7 @@ using Robust.Server.GameObjects;
namespace Content.Server.Arcade namespace Content.Server.Arcade
{ {
// ReSharper disable once ClassNeverInstantiated.Global // ReSharper disable once ClassNeverInstantiated.Global
public sealed class ArcadeSystem : EntitySystem public sealed partial class ArcadeSystem : EntitySystem
{ {
private readonly List<BlockGameMessages.HighScoreEntry> _roundHighscores = new(); private readonly List<BlockGameMessages.HighScoreEntry> _roundHighscores = new();
private readonly List<BlockGameMessages.HighScoreEntry> _globalHighscores = new(); private readonly List<BlockGameMessages.HighScoreEntry> _globalHighscores = new();
@@ -19,6 +19,8 @@ namespace Content.Server.Arcade
base.Initialize(); base.Initialize();
SubscribeLocalEvent<BlockGameArcadeComponent, AfterActivatableUIOpenEvent>(OnAfterUIOpen); SubscribeLocalEvent<BlockGameArcadeComponent, AfterActivatableUIOpenEvent>(OnAfterUIOpen);
SubscribeLocalEvent<SpaceVillainArcadeComponent, AfterActivatableUIOpenEvent>(OnAfterUIOpenSV); SubscribeLocalEvent<SpaceVillainArcadeComponent, AfterActivatableUIOpenEvent>(OnAfterUIOpenSV);
InitializeBlockGame();
InitializeSpaceVillain();
} }
private void OnAfterUIOpen(EntityUid uid, BlockGameArcadeComponent component, AfterActivatableUIOpenEvent args) private void OnAfterUIOpen(EntityUid uid, BlockGameArcadeComponent component, AfterActivatableUIOpenEvent args)

View File

@@ -23,20 +23,6 @@ namespace Content.Server.Arcade.Components
private IPlayerSession? _player; private IPlayerSession? _player;
private readonly List<IPlayerSession> _spectators = new(); private readonly List<IPlayerSession> _spectators = new();
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
#pragma warning disable 618
base.HandleMessage(message, component);
#pragma warning restore 618
switch (message)
{
case PowerChangedMessage powerChanged:
OnPowerStateChanged(powerChanged);
break;
}
}
public void RegisterPlayerSession(IPlayerSession session) public void RegisterPlayerSession(IPlayerSession session)
{ {
if (_player == null) _player = session; if (_player == null) _player = session;
@@ -92,7 +78,7 @@ namespace Content.Server.Arcade.Components
_game = new BlockGame(this); _game = new BlockGame(this);
} }
private void OnPowerStateChanged(PowerChangedMessage e) public void OnPowerStateChanged(PowerChangedEvent e)
{ {
if (e.Powered) return; if (e.Powered) return;

View File

@@ -73,28 +73,13 @@ namespace Content.Server.Arcade.Components
} }
} }
[Obsolete("Component Messages are deprecated, use Entity Events instead.")] public void OnPowerStateChanged(PowerChangedEvent e)
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
#pragma warning disable 618
base.HandleMessage(message, component);
#pragma warning restore 618
switch (message)
{
case PowerChangedMessage powerChanged:
OnOnPowerStateChanged(powerChanged);
break;
}
}
private void OnOnPowerStateChanged(PowerChangedMessage e)
{ {
if (e.Powered) return; if (e.Powered) return;
UserInterface?.CloseAll(); UserInterface?.CloseAll();
} }
private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg) private void UserInterfaceOnOnReceiveMessage(ServerBoundUserInterfaceMessage serverMsg)
{ {
if (!Powered) if (!Powered)

View File

@@ -68,25 +68,6 @@ namespace Content.Server.Chemistry.Components
_bufferSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, SolutionName); _bufferSolution = EntitySystem.Get<SolutionContainerSystem>().EnsureSolution(Owner, SolutionName);
} }
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
#pragma warning disable 618
base.HandleMessage(message, component);
#pragma warning restore 618
switch (message)
{
case PowerChangedMessage:
OnPowerChanged();
break;
}
}
private void OnPowerChanged()
{
UpdateUserInterface();
}
/// <summary> /// <summary>
/// Handles ui messages from the client. For things such as button presses /// Handles ui messages from the client. For things such as button presses
/// which interact with the world and require server action. /// which interact with the world and require server action.

View File

@@ -74,20 +74,6 @@ namespace Content.Server.Chemistry.Components
InitializeFromPrototype(); InitializeFromPrototype();
} }
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
#pragma warning disable 618
base.HandleMessage(message, component);
#pragma warning restore 618
switch (message)
{
case PowerChangedMessage powerChanged:
OnPowerChanged(powerChanged);
break;
}
}
/// <summary> /// <summary>
/// Checks to see if the <c>pack</c> defined in this components yaml prototype /// Checks to see if the <c>pack</c> defined in this components yaml prototype
/// exists. If so, it fills the reagent inventory list. /// exists. If so, it fills the reagent inventory list.
@@ -127,7 +113,7 @@ namespace Content.Server.Chemistry.Components
} }
private void OnPowerChanged(PowerChangedMessage e) public void OnPowerChanged()
{ {
UpdateUserInterface(); UpdateUserInterface();
} }

View File

@@ -0,0 +1,17 @@
using Content.Server.Chemistry.Components;
using Content.Server.Power.Components;
namespace Content.Server.Chemistry.EntitySystems;
public sealed partial class ChemistrySystem
{
private void InitializeChemMaster()
{
SubscribeLocalEvent<ChemMasterComponent, PowerChangedEvent>(OnChemMasterPowerChange);
}
private static void OnChemMasterPowerChange(EntityUid uid, ChemMasterComponent component, PowerChangedEvent args)
{
component.UpdateUserInterface();
}
}

View File

@@ -0,0 +1,17 @@
using Content.Server.Chemistry.Components;
using Content.Server.Power.Components;
namespace Content.Server.Chemistry.EntitySystems;
public sealed partial class ChemistrySystem
{
private void InitializeReagentDispenser()
{
SubscribeLocalEvent<ReagentDispenserComponent, PowerChangedEvent>(OnReagentDispenserPower);
}
private static void OnReagentDispenserPower(EntityUid uid, ReagentDispenserComponent component, PowerChangedEvent args)
{
component.OnPowerChanged();
}
}

View File

@@ -18,7 +18,10 @@ public sealed partial class ChemistrySystem : EntitySystem
public override void Initialize() public override void Initialize()
{ {
// Why ChemMaster duplicates reagentdispenser nobody knows.
InitializeChemMaster();
InitializeHypospray(); InitializeHypospray();
InitializeInjector(); InitializeInjector();
InitializeReagentDispenser();
} }
} }

View File

@@ -99,20 +99,6 @@ namespace Content.Server.ParticleAccelerator.Components
_apcPowerReceiverComponent!.Load = 250; _apcPowerReceiverComponent!.Load = 250;
} }
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
#pragma warning disable 618
base.HandleMessage(message, component);
#pragma warning restore 618
switch (message)
{
case PowerChangedMessage powerChanged:
OnPowerStateChanged(powerChanged);
break;
}
}
protected override void Startup() protected override void Startup()
{ {
base.Startup(); base.Startup();
@@ -122,7 +108,7 @@ namespace Content.Server.ParticleAccelerator.Components
// This is the power state for the PA control box itself. // 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. // 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(PowerChangedMessage e) public void OnPowerStateChanged(PowerChangedEvent e)
{ {
UpdateAppearance(); UpdateAppearance();

View File

@@ -0,0 +1,17 @@
using Content.Server.ParticleAccelerator.Components;
using Content.Server.Power.Components;
namespace Content.Server.ParticleAccelerator.EntitySystems;
public sealed partial class ParticleAcceleratorSystem
{
private void InitializeControlBoxSystem()
{
SubscribeLocalEvent<ParticleAcceleratorControlBoxComponent, PowerChangedEvent>(OnControlBoxPowerChange);
}
private static void OnControlBoxPowerChange(EntityUid uid, ParticleAcceleratorControlBoxComponent component, PowerChangedEvent args)
{
component.OnPowerStateChanged(args);
}
}

View File

@@ -1,18 +1,14 @@
using Content.Server.ParticleAccelerator.Components; using Content.Server.ParticleAccelerator.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.ParticleAccelerator.EntitySystems namespace Content.Server.ParticleAccelerator.EntitySystems
{ {
[UsedImplicitly] [UsedImplicitly]
public sealed class ParticleAcceleratorPartSystem : EntitySystem public sealed partial class ParticleAcceleratorSystem
{ {
public override void Initialize() private void InitializePartSystem()
{ {
base.Initialize(); SubscribeLocalEvent<ParticleAcceleratorPartComponent, RotateEvent>(OnRotateEvent);
EntityManager.EventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, RotateEvent);
SubscribeLocalEvent<ParticleAcceleratorPartComponent, PhysicsBodyTypeChangedEvent>(BodyTypeChanged); SubscribeLocalEvent<ParticleAcceleratorPartComponent, PhysicsBodyTypeChangedEvent>(BodyTypeChanged);
} }
@@ -24,12 +20,9 @@ namespace Content.Server.ParticleAccelerator.EntitySystems
component.OnAnchorChanged(); component.OnAnchorChanged();
} }
private void RotateEvent(ref RotateEvent ev) private static void OnRotateEvent(EntityUid uid, ParticleAcceleratorPartComponent component, ref RotateEvent args)
{ {
if (EntityManager.TryGetComponent(ev.Sender, out ParticleAcceleratorPartComponent? part)) component.Rotated();
{
part.Rotated();
}
} }
} }
} }

View File

@@ -5,15 +5,11 @@ using Robust.Shared.GameObjects;
namespace Content.Server.ParticleAccelerator.EntitySystems namespace Content.Server.ParticleAccelerator.EntitySystems
{ {
[UsedImplicitly] public sealed partial class ParticleAcceleratorSystem
public sealed class ParticleAcceleratorPowerBoxSystem : EntitySystem
{ {
public override void Initialize() private void InitializePowerBoxSystem()
{ {
base.Initialize(); SubscribeLocalEvent<ParticleAcceleratorPowerBoxComponent, PowerConsumerReceivedChanged>(PowerBoxReceivedChanged);
SubscribeLocalEvent<ParticleAcceleratorPowerBoxComponent, PowerConsumerReceivedChanged>(
PowerBoxReceivedChanged);
} }
private static void PowerBoxReceivedChanged( private static void PowerBoxReceivedChanged(
@@ -21,8 +17,7 @@ namespace Content.Server.ParticleAccelerator.EntitySystems
ParticleAcceleratorPowerBoxComponent component, ParticleAcceleratorPowerBoxComponent component,
PowerConsumerReceivedChanged args) PowerConsumerReceivedChanged args)
{ {
if (component.Master != null) component.Master?.PowerBoxReceivedChanged(args);
component.Master.PowerBoxReceivedChanged(args);
} }
} }
} }

View File

@@ -0,0 +1,12 @@
namespace Content.Server.ParticleAccelerator.EntitySystems;
public sealed partial class ParticleAcceleratorSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
InitializeControlBoxSystem();
InitializePartSystem();
InitializePowerBoxSystem();
}
}

View File

@@ -82,9 +82,6 @@ namespace Content.Server.Power.Components
public void ApcPowerChanged() public void ApcPowerChanged()
{ {
#pragma warning disable 618
SendMessage(new PowerChangedMessage(Powered));
#pragma warning restore 618
_entMan.EventBus.RaiseLocalEvent(Owner, new PowerChangedEvent(Powered, NetworkLoad.ReceivingPower)); _entMan.EventBus.RaiseLocalEvent(Owner, new PowerChangedEvent(Powered, NetworkLoad.ReceivingPower));
if (_entMan.TryGetComponent<AppearanceComponent?>(Owner, out var appearance)) if (_entMan.TryGetComponent<AppearanceComponent?>(Owner, out var appearance))
@@ -104,18 +101,6 @@ namespace Content.Server.Power.Components
} }
} }
#pragma warning disable 618
public sealed class PowerChangedMessage : ComponentMessage
#pragma warning restore 618
{
public readonly bool Powered;
public PowerChangedMessage(bool powered)
{
Powered = powered;
}
}
/// <summary> /// <summary>
/// Raised whenever an ApcPowerReceiver becomes powered / unpowered. /// Raised whenever an ApcPowerReceiver becomes powered / unpowered.
/// </summary> /// </summary>