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>
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Gravity
|
||||
{
|
||||
public abstract class SharedGravitySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly AlertsSystem _alerts = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
|
||||
public bool IsWeightless(EntityUid uid, PhysicsComponent? body = null, TransformComponent? xform = null)
|
||||
@@ -21,23 +24,16 @@ namespace Content.Shared.Gravity
|
||||
if (TryComp<MovementIgnoreGravityComponent>(uid, out var ignoreGravityComponent))
|
||||
return ignoreGravityComponent.Weightless;
|
||||
|
||||
if (!Resolve(uid, ref xform)) return true;
|
||||
|
||||
bool gravityEnabled = false;
|
||||
if (!Resolve(uid, ref xform))
|
||||
return true;
|
||||
|
||||
// If grid / map has gravity
|
||||
if ((TryComp<GravityComponent>(xform.GridUid, out var gravity) ||
|
||||
TryComp(xform.MapUid, out gravity)) && gravity.Enabled)
|
||||
{
|
||||
gravityEnabled = gravity.Enabled;
|
||||
|
||||
if (gravityEnabled) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// On the map then always weightless (unless it has gravity comp obv).
|
||||
if (!_mapManager.TryGetGrid(xform.GridUid, out var grid))
|
||||
return true;
|
||||
|
||||
// Something holding us down
|
||||
if (_inventory.TryGetSlotEntity(uid, "shoes", out var ent))
|
||||
{
|
||||
@@ -45,21 +41,76 @@ namespace Content.Shared.Gravity
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!gravityEnabled || !xform.Coordinates.IsValid(EntityManager)) return true;
|
||||
|
||||
var tile = grid.GetTileRef(xform.Coordinates).Tile;
|
||||
return tile.IsEmpty;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<GridInitializeEvent>(HandleGridInitialize);
|
||||
SubscribeLocalEvent<AlertsComponent, EntParentChangedMessage>(OnAlertsParentChange);
|
||||
SubscribeLocalEvent<GravityChangedEvent>(OnGravityChange);
|
||||
SubscribeLocalEvent<GravityComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<GravityComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, GravityComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not GravityComponentState state) return;
|
||||
|
||||
if (component.EnabledVV == state.Enabled) return;
|
||||
component.EnabledVV = state.Enabled;
|
||||
RaiseLocalEvent(new GravityChangedEvent(uid, component.EnabledVV));
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, GravityComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new GravityComponentState(component.EnabledVV);
|
||||
}
|
||||
|
||||
private void OnGravityChange(GravityChangedEvent ev)
|
||||
{
|
||||
foreach (var (comp, xform) in EntityQuery<AlertsComponent, TransformComponent>(true))
|
||||
{
|
||||
if (xform.GridUid != ev.ChangedGridIndex) continue;
|
||||
|
||||
if (!ev.HasGravity)
|
||||
{
|
||||
_alerts.ShowAlert(comp.Owner, AlertType.Weightless);
|
||||
}
|
||||
else
|
||||
{
|
||||
_alerts.ClearAlert(comp.Owner, AlertType.Weightless);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAlertsParentChange(EntityUid uid, AlertsComponent component, ref EntParentChangedMessage args)
|
||||
{
|
||||
if (IsWeightless(component.Owner))
|
||||
{
|
||||
_alerts.ShowAlert(uid, AlertType.Weightless);
|
||||
}
|
||||
else
|
||||
{
|
||||
_alerts.ClearAlert(uid, AlertType.Weightless);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleGridInitialize(GridInitializeEvent ev)
|
||||
{
|
||||
EntityManager.EnsureComponent<GravityComponent>(ev.EntityUid);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class GravityComponentState : ComponentState
|
||||
{
|
||||
public bool Enabled { get; }
|
||||
|
||||
public GravityComponentState(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user