Files
tbd-station-14/Content.Client/Parallax/ParallaxSystem.cs
metalgearsloth bfac53e7bc Per-map parallax support (#9786)
* Per-map parallax support

* Comments for future sloth

* c

* bet

* Fix exception

* VV support

* Fix parallax

* mem

* weightless sounds

* Gravity stuff

* placeholder coz im too lazy to stash don't @ me son

* decent clouds

* sky

* Fast parallax

* Imagine spelling

* Loicense

* perish

* Fix weightless status

Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
2022-07-25 00:10:23 -05:00

72 lines
2.2 KiB
C#

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;
namespace Content.Client.Parallax;
public sealed class ParallaxSystem : SharedParallaxSystem
{
[Dependency] private readonly IMapManager _map = default!;
[Dependency] private readonly IOverlayManager _overlay = default!;
[Dependency] private readonly IParallaxManager _parallax = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
private const string Fallback = "Default";
public override void Initialize()
{
base.Initialize();
_overlay.AddOverlay(new ParallaxOverlay());
SubscribeLocalEvent<ParallaxComponent, ComponentHandleState>(OnParallaxHandleState);
_protoManager.PrototypesReloaded += OnReload;
}
private void OnReload(PrototypesReloadedEventArgs obj)
{
_parallax.UnloadParallax(Fallback);
_parallax.LoadDefaultParallax();
foreach (var comp in EntityQuery<ParallaxComponent>(true))
{
_parallax.UnloadParallax(comp.Parallax);
_parallax.LoadParallaxByName(comp.Parallax);
}
}
public override void Shutdown()
{
base.Shutdown();
_overlay.RemoveOverlay<ParallaxOverlay>();
_protoManager.PrototypesReloaded -= OnReload;
}
private void OnParallaxHandleState(EntityUid uid, ParallaxComponent component, ref ComponentHandleState args)
{
if (args.Current is not ParallaxComponentState state) return;
component.Parallax = state.Parallax;
if (!_parallax.IsLoaded(component.Parallax))
{
_parallax.LoadParallaxByName(component.Parallax);
}
}
public ParallaxLayerPrepared[] GetParallaxLayers(MapId mapId)
{
return _parallax.GetParallaxLayers(GetParallax(_map.GetMapEntityId(mapId)));
}
public string GetParallax(MapId mapId)
{
return GetParallax(_map.GetMapEntityId(mapId));
}
public string GetParallax(EntityUid mapUid)
{
return TryComp<ParallaxComponent>(mapUid, out var parallax) ? parallax.Parallax : Fallback;
}
}