autogen parallax state (#15384)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-04-22 12:02:23 +00:00
committed by GitHub
parent a66127b901
commit f72baa6a49
3 changed files with 7 additions and 28 deletions

View File

@@ -2,7 +2,6 @@ using Content.Client.Parallax.Data;
using Content.Client.Parallax.Managers; using Content.Client.Parallax.Managers;
using Content.Shared.Parallax; using Content.Shared.Parallax;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Shared.GameStates;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -22,8 +21,9 @@ public sealed class ParallaxSystem : SharedParallaxSystem
{ {
base.Initialize(); base.Initialize();
_overlay.AddOverlay(new ParallaxOverlay()); _overlay.AddOverlay(new ParallaxOverlay());
SubscribeLocalEvent<ParallaxComponent, ComponentHandleState>(OnParallaxHandleState);
_protoManager.PrototypesReloaded += OnReload; _protoManager.PrototypesReloaded += OnReload;
SubscribeLocalEvent<ParallaxComponent, AfterAutoHandleStateEvent>(OnAfterAutoHandleState);
} }
private void OnReload(PrototypesReloadedEventArgs obj) private void OnReload(PrototypesReloadedEventArgs obj)
@@ -48,11 +48,8 @@ public sealed class ParallaxSystem : SharedParallaxSystem
_protoManager.PrototypesReloaded -= OnReload; _protoManager.PrototypesReloaded -= OnReload;
} }
private void OnParallaxHandleState(EntityUid uid, ParallaxComponent component, ref ComponentHandleState args) private void OnAfterAutoHandleState(EntityUid uid, ParallaxComponent component, ref AfterAutoHandleStateEvent args)
{ {
if (args.Current is not ParallaxComponentState state) return;
component.Parallax = state.Parallax;
if (!_parallax.IsLoaded(component.Parallax)) if (!_parallax.IsLoaded(component.Parallax))
{ {
_parallax.LoadParallaxByName(component.Parallax); _parallax.LoadParallaxByName(component.Parallax);

View File

@@ -1,23 +1,5 @@
using Content.Shared.Parallax; using Content.Shared.Parallax;
using Robust.Shared.GameStates;
namespace Content.Server.Parallax; namespace Content.Server.Parallax;
public sealed class ParallaxSystem : SharedParallaxSystem public sealed class ParallaxSystem : SharedParallaxSystem { }
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ParallaxComponent, ComponentGetState>(OnParallaxGetState);
}
private void OnParallaxGetState(EntityUid uid, ParallaxComponent component, ref ComponentGetState args)
{
args.State = new ParallaxComponentState
{
Parallax = component.Parallax
};
}
}

View File

@@ -6,11 +6,11 @@ namespace Content.Shared.Parallax;
/// <summary> /// <summary>
/// Handles per-map parallax /// Handles per-map parallax
/// </summary> /// </summary>
[RegisterComponent, NetworkedComponent] [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed class ParallaxComponent : Component public sealed partial class ParallaxComponent : Component
{ {
// I wish I could use a typeserializer here but parallax is extremely client-dependent. // I wish I could use a typeserializer here but parallax is extremely client-dependent.
[DataField("parallax")] [DataField("parallax"), AutoNetworkedField]
public string Parallax = "Default"; public string Parallax = "Default";
[UsedImplicitly, ViewVariables(VVAccess.ReadWrite)] [UsedImplicitly, ViewVariables(VVAccess.ReadWrite)]