Files
tbd-station-14/Content.Server/Gravity/EntitySystems/GravitySystem.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

74 lines
2.3 KiB
C#

using Content.Shared.Gravity;
using JetBrains.Annotations;
namespace Content.Server.Gravity.EntitySystems
{
[UsedImplicitly]
public sealed class GravitySystem : SharedGravitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GravityComponent, ComponentInit>(OnGravityInit);
SubscribeLocalEvent<GravityComponent, ComponentShutdown>(OnGravityShutdown);
}
private void OnGravityInit(EntityUid uid, GravityComponent component, ComponentInit args)
{
// Incase there's already a generator on the grid we'll just set it now.
var gridId = Transform(component.Owner).GridUid;
if (gridId == null)
return;
GravityChangedEvent message;
foreach (var generator in EntityManager.EntityQuery<GravityGeneratorComponent>())
{
if (Transform(generator.Owner).GridUid == gridId && generator.GravityActive)
{
component.Enabled = true;
message = new GravityChangedEvent(gridId.Value, true);
RaiseLocalEvent(message);
return;
}
}
component.Enabled = false;
message = new GravityChangedEvent(gridId.Value, false);
RaiseLocalEvent(message);
}
private void OnGravityShutdown(EntityUid uid, GravityComponent component, ComponentShutdown args)
{
DisableGravity(component);
}
public void EnableGravity(GravityComponent comp)
{
if (comp.Enabled) return;
var gridId = Transform(comp.Owner).GridUid;
if (gridId == null)
return;
comp.Enabled = true;
var message = new GravityChangedEvent(gridId.Value, true);
RaiseLocalEvent(message);
}
public void DisableGravity(GravityComponent comp)
{
if (!comp.Enabled) return;
comp.Enabled = false;
var gridId = Transform(comp.Owner).GridUid;
if (gridId == null)
return;
var message = new GravityChangedEvent(gridId.Value, false);
RaiseLocalEvent(message);
}
}
}