more component ref removal + combining server/client comps (#13178)

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
Nemanja
2022-12-24 23:28:21 -05:00
committed by GitHub
parent fddcc0cece
commit faca40b8d5
78 changed files with 504 additions and 643 deletions

View File

@@ -1,32 +0,0 @@
using Robust.Shared.GameStates;
using Content.Shared.Singularity.EntitySystems;
namespace Content.Shared.Singularity.Components;
/// <summary>
/// A component that makes the associated entity accumulate energy when an associated event horizon consumes things.
/// Energy management is server-side.
/// </summary>
[NetworkedComponent]
public abstract class SharedSingularityComponent : Component
{
/// <summary>
/// The current level of the singularity.
/// Used as a scaling factor for things like visual size, event horizon radius, gravity well radius, radiation output, etc.
/// If you want to set this use <see cref="SharedSingularitySystem.SetLevel"/>().
/// </summary>
[DataField("level")]
[Access(friends:typeof(SharedSingularitySystem), Other=AccessPermissions.Read, Self=AccessPermissions.Read)]
public byte Level = 1;
/// <summary>
/// The amount of radiation this singularity emits per its level.
/// Has to be on shared in case someone attaches a RadiationPulseComponent to the singularity.
/// If you want to set this use <see cref="SharedSingularitySystem.SetRadsPerLevel"/>().
/// </summary>
[DataField("radsPerLevel")]
[Access(friends:typeof(SharedSingularitySystem), Other=AccessPermissions.Read, Self=AccessPermissions.Read)]
[ViewVariables(VVAccess.ReadWrite)]
public float RadsPerLevel = 2f;
}

View File

@@ -0,0 +1,105 @@
using Robust.Shared.GameStates;
using Content.Shared.Singularity.EntitySystems;
using Robust.Shared.Audio;
namespace Content.Shared.Singularity.Components;
/// <summary>
/// A component that makes the associated entity accumulate energy when an associated event horizon consumes things.
/// Energy management is server-side.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed class SingularityComponent : Component
{
/// <summary>
/// The current level of the singularity.
/// Used as a scaling factor for things like visual size, event horizon radius, gravity well radius, radiation output, etc.
/// If you want to set this use <see cref="SharedSingularitySystem.SetLevel"/>().
/// </summary>
[DataField("level")]
[Access(friends:typeof(SharedSingularitySystem), Other=AccessPermissions.Read, Self=AccessPermissions.Read)]
public byte Level = 1;
/// <summary>
/// The amount of radiation this singularity emits per its level.
/// Has to be on shared in case someone attaches a RadiationPulseComponent to the singularity.
/// If you want to set this use <see cref="SharedSingularitySystem.SetRadsPerLevel"/>().
/// </summary>
[DataField("radsPerLevel")]
[Access(friends:typeof(SharedSingularitySystem), Other=AccessPermissions.Read, Self=AccessPermissions.Read)]
[ViewVariables(VVAccess.ReadWrite)]
public float RadsPerLevel = 2f;
/// <summary>
/// The amount of energy this singularity contains.
/// </summary>
[DataField("energy")]
public float Energy = 180f;
/// <summary>
/// The rate at which this singularity loses energy over time.
/// </summary>
[DataField("energyLoss")]
[ViewVariables(VVAccess.ReadWrite)]
public float EnergyDrain;
#region Audio
/// <summary>
/// The sound that this singularity produces by existing.
/// </summary>
[DataField("ambientSound")]
[ViewVariables(VVAccess.ReadOnly)]
public SoundSpecifier? AmbientSound = new SoundPathSpecifier(
"/Audio/Effects/singularity_form.ogg",
AudioParams.Default.WithVolume(5).WithLoop(true).WithMaxDistance(20f)
);
/// <summary>
/// The audio stream that plays the sound specified by <see cref="AmbientSound"/> on loop.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public IPlayingAudioStream? AmbientSoundStream = null;
/// <summary>
/// The sound that the singularity produces when it forms.
/// </summary>
[DataField("formationSound")]
[ViewVariables(VVAccess.ReadOnly)]
public SoundSpecifier? FormationSound = null;
/// <summary>
/// The sound that the singularity produces when it dissipates.
/// </summary>
[DataField("dissipationSound")]
[ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier? DissipationSound = new SoundPathSpecifier(
"/Audio/Effects/singularity_collapse.ogg",
AudioParams.Default
);
#endregion Audio
#region Update Timing
/// <summary>
/// The amount of time that should elapse between automated updates to this singularity.
/// </summary>
[DataField("updatePeriod")]
[ViewVariables(VVAccess.ReadOnly)]
public TimeSpan TargetUpdatePeriod = TimeSpan.FromSeconds(1.0);
/// <summary>
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public TimeSpan NextUpdateTime = default!;
/// <summary>
/// The last time this singularity was updated.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public TimeSpan LastUpdateTime = default!;
#endregion Update Timing
}

View File

@@ -10,7 +10,7 @@ using Content.Shared.Singularity.Events;
namespace Content.Shared.Singularity.EntitySystems;
/// <summary>
/// The entity system primarily responsible for managing <see cref="SharedSingularityComponent"/>s.
/// The entity system primarily responsible for managing <see cref="SingularityComponent"/>s.
/// </summary>
public abstract class SharedSingularitySystem : EntitySystem
{
@@ -44,7 +44,7 @@ public abstract class SharedSingularitySystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<SharedSingularityComponent, ComponentStartup>(OnSingularityStartup);
SubscribeLocalEvent<SingularityComponent, ComponentStartup>(OnSingularityStartup);
SubscribeLocalEvent<AppearanceComponent, SingularityLevelChangedEvent>(UpdateAppearance);
SubscribeLocalEvent<RadiationSourceComponent, SingularityLevelChangedEvent>(UpdateRadiation);
SubscribeLocalEvent<PhysicsComponent, SingularityLevelChangedEvent>(UpdateBody);
@@ -53,16 +53,16 @@ public abstract class SharedSingularitySystem : EntitySystem
SubscribeLocalEvent<SingularityDistortionComponent, EntGotInsertedIntoContainerMessage>(UpdateDistortion);
SubscribeLocalEvent<SingularityDistortionComponent, EntGotRemovedFromContainerMessage>(UpdateDistortion);
var vvHandle = Vvm.GetTypeHandler<SharedSingularityComponent>();
vvHandle.AddPath(nameof(SharedSingularityComponent.Level), (_, comp) => comp.Level, SetLevel);
vvHandle.AddPath(nameof(SharedSingularityComponent.RadsPerLevel), (_, comp) => comp.RadsPerLevel, SetRadsPerLevel);
var vvHandle = Vvm.GetTypeHandler<SingularityComponent>();
vvHandle.AddPath(nameof(SingularityComponent.Level), (_, comp) => comp.Level, SetLevel);
vvHandle.AddPath(nameof(SingularityComponent.RadsPerLevel), (_, comp) => comp.RadsPerLevel, SetRadsPerLevel);
}
public override void Shutdown()
{
var vvHandle = Vvm.GetTypeHandler<SharedSingularityComponent>();
vvHandle.RemovePath(nameof(SharedSingularityComponent.Level));
vvHandle.RemovePath(nameof(SharedSingularityComponent.RadsPerLevel));
var vvHandle = Vvm.GetTypeHandler<SingularityComponent>();
vvHandle.RemovePath(nameof(SingularityComponent.Level));
vvHandle.RemovePath(nameof(SingularityComponent.RadsPerLevel));
base.Shutdown();
}
@@ -70,13 +70,13 @@ public abstract class SharedSingularitySystem : EntitySystem
#region Getters/Setters
/// <summary>
/// Setter for <see cref="SharedSingularityComponent.Level"/>
/// Setter for <see cref="SingularityComponent.Level"/>
/// Also sends out an event alerting that the singularities level has changed.
/// </summary>
/// <param name="uid">The uid of the singularity to change the level of.</param>
/// <param name="value">The new level the singularity should have.</param>
/// <param name="singularity">The state of the singularity to change the level of.</param>
public void SetLevel(EntityUid uid, byte value, SharedSingularityComponent? singularity = null)
public void SetLevel(EntityUid uid, byte value, SingularityComponent? singularity = null)
{
if(!Resolve(uid, ref singularity))
return;
@@ -93,13 +93,13 @@ public abstract class SharedSingularitySystem : EntitySystem
}
/// <summary>
/// Setter for <see cref="SharedSingularityComponent.RadsPerLevel"/>
/// Setter for <see cref="SingularityComponent.RadsPerLevel"/>
/// Also updates the radiation output of the singularity according to the new values.
/// </summary>
/// <param name="uid">The uid of the singularity to change the radioactivity of.</param>
/// <param name="value">The new radioactivity the singularity should have.</param>
/// <param name="singularity">The state of the singularity to change the radioactivity of.</param>
public void SetRadsPerLevel(EntityUid uid, float value, SharedSingularityComponent? singularity = null)
public void SetRadsPerLevel(EntityUid uid, float value, SingularityComponent? singularity = null)
{
if(!Resolve(uid, ref singularity))
return;
@@ -117,9 +117,9 @@ public abstract class SharedSingularitySystem : EntitySystem
/// Usually follows a SharedSingularitySystem.SetLevel call, but is also used on component startup to sync everything.
/// </summary>
/// <param name="uid">The uid of the singularity which's level has changed.</param>
/// <param name="oldValue">The old level of the singularity. May be equal to <see cref="SharedSingularityComponent.Level"/> if the component is starting.</param>
/// <param name="oldValue">The old level of the singularity. May be equal to <see cref="SingularityComponent.Level"/> if the component is starting.</param>
/// <param name="singularity">The state of the singularity which's level has changed.</param>
public void UpdateSingularityLevel(EntityUid uid, byte oldValue, SharedSingularityComponent? singularity = null)
public void UpdateSingularityLevel(EntityUid uid, byte oldValue, SingularityComponent? singularity = null)
{
if(!Resolve(uid, ref singularity))
return;
@@ -135,7 +135,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// </summary>
/// <param name="uid">The uid of the singularity.</param>
/// <param name="singularity">The state of the singularity.</param>
public void UpdateSingularityLevel(EntityUid uid, SharedSingularityComponent? singularity = null)
public void UpdateSingularityLevel(EntityUid uid, SingularityComponent? singularity = null)
{
if (Resolve(uid, ref singularity))
UpdateSingularityLevel(uid, singularity.Level, singularity);
@@ -147,7 +147,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// <param name="uid">The uid of the singularity to update the radiation of.</param>
/// <param name="singularity">The state of the singularity to update the radiation of.</param>
/// <param name="rads">The state of the radioactivity of the singularity to update.</param>
private void UpdateRadiation(EntityUid uid, SharedSingularityComponent? singularity = null, RadiationSourceComponent? rads = null)
private void UpdateRadiation(EntityUid uid, SingularityComponent? singularity = null, RadiationSourceComponent? rads = null)
{
if(!Resolve(uid, ref singularity, ref rads, logMissing: false))
return;
@@ -177,7 +177,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// </summary>
/// <param name="singulo">A singularity.</param>
/// <returns>The gravity well radius the singularity should have given its state.</returns>
public float GravPulseRange(SharedSingularityComponent singulo)
public float GravPulseRange(SingularityComponent singulo)
=> BaseGravityWellRadius * (singulo.Level + 1);
/// <summary>
@@ -185,7 +185,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// </summary>
/// <param name="singulo">A singularity.</param>
/// <returns>The base gravitational acceleration the singularity should have given its state.</returns>
public (float, float) GravPulseAcceleration(SharedSingularityComponent singulo)
public (float, float) GravPulseAcceleration(SingularityComponent singulo)
=> (BaseGravityWellAcceleration * singulo.Level, 0f);
/// <summary>
@@ -193,7 +193,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// </summary>
/// <param name="singulo">A singularity.</param>
/// <returns>The event horizon radius the singularity should have given its state.</returns>
public float EventHorizonRadius(SharedSingularityComponent singulo)
public float EventHorizonRadius(SingularityComponent singulo)
=> (float) singulo.Level - 0.5f;
/// <summary>
@@ -201,7 +201,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// </summary>
/// <param name="singulo">A singularity.</param>
/// <returns>Whether the singularity should be able to breach containment.</returns>
public bool CanBreachContainment(SharedSingularityComponent singulo)
public bool CanBreachContainment(SingularityComponent singulo)
=> singulo.Level >= SingularityBreachThreshold;
/// <summary>
@@ -255,7 +255,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// </summary>
public readonly byte Level;
public SingularityComponentState(SharedSingularityComponent singulo)
public SingularityComponentState(SingularityComponent singulo)
{
Level = singulo.Level;
}
@@ -269,7 +269,7 @@ public abstract class SharedSingularitySystem : EntitySystem
/// <param name="uid">The entity that is becoming a singularity.</param>
/// <param name="comp">The singularity component that is being added to the entity.</param>
/// <param name="args">The event arguments.</param>
protected virtual void OnSingularityStartup(EntityUid uid, SharedSingularityComponent comp, ComponentStartup args)
protected virtual void OnSingularityStartup(EntityUid uid, SingularityComponent comp, ComponentStartup args)
{
UpdateSingularityLevel(uid, comp);
}

View File

@@ -20,9 +20,9 @@ public sealed class SingularityLevelChangedEvent : EntityEventArgs
/// <summary>
/// The singularity that just changed level.
/// </summary>
public readonly SharedSingularityComponent Singularity;
public readonly SingularityComponent Singularity;
public SingularityLevelChangedEvent(byte newValue, byte oldValue, SharedSingularityComponent singularity)
public SingularityLevelChangedEvent(byte newValue, byte oldValue, SingularityComponent singularity)
{
NewValue = newValue;
OldValue = oldValue;