Skip to content

Commit

Permalink
Move some of the new singularity code into shared
Browse files Browse the repository at this point in the history
Hopefully without explosions yay
  • Loading branch information
SaphireLattice committed Nov 20, 2024
1 parent 6e53cd9 commit 9c66645
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System.Diagnostics;
using Content.Server.ParticleAccelerator.Components;
using Content.Server.Popups;
using Content.Server.Singularity.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Popups;
using Content.Shared.Singularity.Components;
using Content.Shared.Singularity.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
Expand All @@ -13,23 +10,21 @@

namespace Content.Server.Singularity.EntitySystems;

public sealed class SingularityGeneratorSystem : EntitySystem
public sealed class SingularityGeneratorSystem : SharedSingularityGeneratorSystem
{
#region Dependencies
[Dependency] private readonly IViewVariablesManager _vvm = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly PhysicsSystem _physics = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly MetaDataSystem _metadata = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
#endregion Dependencies

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ParticleProjectileComponent, StartCollideEvent>(HandleParticleCollide);
SubscribeLocalEvent<SingularityGeneratorComponent, GotEmaggedEvent>(OnEmagged);

var vvHandle = _vvm.GetTypeHandler<SingularityGeneratorComponent>();
vvHandle.AddPath(nameof(SingularityGeneratorComponent.Power), (_, comp) => comp.Power, SetPower);
Expand Down Expand Up @@ -138,7 +133,7 @@ private void HandleParticleCollide(EntityUid uid, ParticleProjectileComponent co
if (!contained && !generatorComp.FailsafeDisabled)
{
generatorComp.NextFailsafe = _timing.CurTime + generatorComp.FailsafeCooldown;
_popupSystem.PopupEntity(Loc.GetString("comp-generator-failsafe", ("target", args.OtherEntity)), args.OtherEntity, PopupType.LargeCaution);
PopupSystem.PopupEntity(Loc.GetString("comp-generator-failsafe", ("target", args.OtherEntity)), args.OtherEntity, PopupType.LargeCaution);
}
else
{
Expand All @@ -159,13 +154,6 @@ private void HandleParticleCollide(EntityUid uid, ParticleProjectileComponent co

EntityManager.QueueDeleteEntity(uid);
}

private void OnEmagged(EntityUid uid, SingularityGeneratorComponent component, ref GotEmaggedEvent args)
{
_popupSystem.PopupEntity(Loc.GetString("comp-generator-failsafe-disabled", ("target", uid)), uid);
component.FailsafeDisabled = true;
args.Handled = true;
}
#endregion Event Handlers

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

using Content.Server.Singularity.EntitySystems;
using Content.Shared.Physics;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Singularity.Components;
namespace Content.Shared.Singularity.Components;

[RegisterComponent, AutoGenerateComponentPause]
[Access(typeof(SingularityGeneratorSystem))]
[RegisterComponent, AutoGenerateComponentPause, AutoGenerateComponentState]
public sealed partial class SingularityGeneratorComponent : Component
{
/// <summary>
Expand All @@ -28,7 +26,7 @@ public sealed partial class SingularityGeneratorComponent : Component
/// <summary>
/// Allows the generator to ignore all the failsafe stuff, e.g. when emagged
/// </summary>
[DataField]
[DataField, AutoNetworkedField]
public bool FailsafeDisabled = false;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Shared.Emag.Systems;
using Content.Shared.Popups;
using Content.Shared.Singularity.Components;

namespace Content.Shared.Singularity.EntitySystems;

/// <summary>
/// Shared part of SingularitySingularityGeneratorSystem
/// </summary>
public abstract class SharedSingularityGeneratorSystem : EntitySystem
{
#region Dependencies
[Dependency] protected readonly SharedPopupSystem PopupSystem = default!;
#endregion Dependencies

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SingularityGeneratorComponent, GotEmaggedEvent>(OnEmagged);
}

private void OnEmagged(EntityUid uid, SingularityGeneratorComponent component, ref GotEmaggedEvent args)
{
PopupSystem.PopupEntity(Loc.GetString("comp-generator-failsafe-disabled", ("target", uid)), uid);
component.FailsafeDisabled = true;
args.Handled = true;
}
}

0 comments on commit 9c66645

Please sign in to comment.