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.Shared.Parallax;
using Robust.Client.Graphics;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
@@ -22,8 +21,9 @@ public sealed class ParallaxSystem : SharedParallaxSystem
{
base.Initialize();
_overlay.AddOverlay(new ParallaxOverlay());
SubscribeLocalEvent<ParallaxComponent, ComponentHandleState>(OnParallaxHandleState);
_protoManager.PrototypesReloaded += OnReload;
SubscribeLocalEvent<ParallaxComponent, AfterAutoHandleStateEvent>(OnAfterAutoHandleState);
}
private void OnReload(PrototypesReloadedEventArgs obj)
@@ -48,11 +48,8 @@ public sealed class ParallaxSystem : SharedParallaxSystem
_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))
{
_parallax.LoadParallaxByName(component.Parallax);

View File

@@ -1,23 +1,5 @@
using Content.Shared.Parallax;
using Robust.Shared.GameStates;
namespace Content.Server.Parallax;
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
};
}
}
public sealed class ParallaxSystem : SharedParallaxSystem { }

View File

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