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:
metalgearsloth
2022-07-25 15:10:23 +10:00
committed by GitHub
parent aad6a22a6a
commit bfac53e7bc
36 changed files with 607 additions and 412 deletions

View File

@@ -1,17 +1,15 @@
using Content.Shared.Sound;
using Robust.Shared.GameStates;
namespace Content.Shared.Movement.Components
{
/// <summary>
/// Changes footstep sound
/// </summary>
[RegisterComponent]
[RegisterComponent, NetworkedComponent]
public sealed class FootstepModifierComponent : Component
{
[DataField("footstepSoundCollection", required: true)]
public SoundSpecifier SoundCollection = default!;
[DataField("variation")]
public float Variation = default;
public SoundSpecifier Sound = default!;
}
}

View File

@@ -49,7 +49,7 @@ namespace Content.Shared.Movement.Components
var gridId = transform.GridUid;
if ((entityManager.TryGetComponent<GravityComponent>(transform.GridUid, out var gravity) ||
entityManager.TryGetComponent(transform.MapUid, out gravity)) && gravity.Enabled)
entityManager.TryGetComponent(transform.MapUid, out gravity)) && gravity.EnabledVV)
return false;
if (gridId == null)
@@ -67,7 +67,7 @@ namespace Content.Shared.Movement.Components
return false;
}
if (!entityManager.GetComponent<GravityComponent>(grid.GridEntityId).Enabled)
if (!entityManager.GetComponent<GravityComponent>(grid.GridEntityId).EnabledVV)
{
return true;
}

View File

@@ -36,7 +36,7 @@ public abstract class SharedJetpackSystem : EntitySystem
SubscribeLocalEvent<JetpackUserComponent, ComponentGetState>(OnJetpackUserGetState);
SubscribeLocalEvent<JetpackUserComponent, ComponentHandleState>(OnJetpackUserHandleState);
SubscribeLocalEvent<GravityChangedMessage>(OnJetpackUserGravityChanged);
SubscribeLocalEvent<GravityChangedEvent>(OnJetpackUserGravityChanged);
}
private void OnJetpackCanWeightlessMove(EntityUid uid, JetpackComponent component, ref CanWeightlessMoveEvent args)
@@ -44,7 +44,7 @@ public abstract class SharedJetpackSystem : EntitySystem
args.CanMove = true;
}
private void OnJetpackUserGravityChanged(GravityChangedMessage ev)
private void OnJetpackUserGravityChanged(GravityChangedEvent ev)
{
var gridUid = ev.ChangedGridIndex;
var jetpackQuery = GetEntityQuery<JetpackComponent>();

View File

@@ -0,0 +1,35 @@
using Content.Shared.Movement.Components;
using Content.Shared.Sound;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Movement.Systems;
public abstract partial class SharedMoverController
{
private void InitializeFootsteps()
{
SubscribeLocalEvent<FootstepModifierComponent, ComponentGetState>(OnFootGetState);
SubscribeLocalEvent<FootstepModifierComponent, ComponentHandleState>(OnFootHandleState);
}
private void OnFootHandleState(EntityUid uid, FootstepModifierComponent component, ref ComponentHandleState args)
{
if (args.Current is not FootstepModifierComponentState state) return;
component.Sound = state.Sound;
}
private void OnFootGetState(EntityUid uid, FootstepModifierComponent component, ref ComponentGetState args)
{
args.State = new FootstepModifierComponentState()
{
Sound = component.Sound,
};
}
[Serializable, NetSerializable]
private sealed class FootstepModifierComponentState : ComponentState
{
public SoundSpecifier Sound = default!;
}
}

View File

@@ -10,6 +10,7 @@ using Content.Shared.MobState.EntitySystems;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Pulling.Components;
using Content.Shared.Sound;
using Content.Shared.Tag;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
@@ -61,6 +62,7 @@ namespace Content.Shared.Movement.Systems
public override void Initialize()
{
base.Initialize();
InitializeFootsteps();
InitializeInput();
InitializeMob();
InitializePushing();
@@ -215,12 +217,13 @@ namespace Content.Shared.Movement.Systems
: worldTotal.ToWorldAngle();
rotateXform.DeferUpdates = false;
if (!weightless && TryComp<MobMoverComponent>(mover.Owner, out var mobMover) && TryGetSound(mover, mobMover, xform, out var variation, out var sound))
if (!weightless && TryComp<MobMoverComponent>(mover.Owner, out var mobMover) &&
TryGetSound(weightless, mover, mobMover, xform, out var sound))
{
var soundModifier = mover.Sprinting ? 1.0f : FootstepWalkingAddedVolumeMultiplier;
SoundSystem.Play(sound,
SoundSystem.Play(sound.GetSound(),
GetSoundPlayers(mover.Owner),
mover.Owner, AudioHelpers.WithVariation(variation).WithVolume(FootstepVolume * soundModifier));
mover.Owner, sound.Params.WithVolume(FootstepVolume * soundModifier));
}
}
@@ -313,19 +316,17 @@ namespace Content.Shared.Movement.Systems
protected abstract bool CanSound();
private bool TryGetSound(InputMoverComponent mover, MobMoverComponent mobMover, TransformComponent xform, out float variation, [NotNullWhen(true)] out string? sound)
private bool TryGetSound(bool weightless, InputMoverComponent mover, MobMoverComponent mobMover, TransformComponent xform, [NotNullWhen(true)] out SoundSpecifier? sound)
{
sound = null;
variation = 0f;
if (!CanSound() || !_tags.HasTag(mover.Owner, "FootstepSound")) return false;
var coordinates = xform.Coordinates;
var gridId = coordinates.GetGridUid(EntityManager);
var distanceNeeded = mover.Sprinting ? StepSoundMoveDistanceRunning : StepSoundMoveDistanceWalking;
// Handle footsteps.
if (_mapManager.GridExists(gridId))
if (!weightless)
{
// Can happen when teleporting between grids.
if (!coordinates.TryDistance(EntityManager, mobMover.LastPosition, out var distance) ||
@@ -344,7 +345,6 @@ namespace Content.Shared.Movement.Systems
return false;
}
DebugTools.Assert(gridId != null);
mobMover.LastPosition = coordinates;
if (mobMover.StepSoundDistance < distanceNeeded) return false;
@@ -354,19 +354,31 @@ namespace Content.Shared.Movement.Systems
if (_inventory.TryGetSlotEntity(mover.Owner, "shoes", out var shoes) &&
EntityManager.TryGetComponent<FootstepModifierComponent>(shoes, out var modifier))
{
sound = modifier.SoundCollection.GetSound();
variation = modifier.Variation;
sound = modifier.Sound;
return true;
}
return TryGetFootstepSound(gridId!.Value, coordinates, out variation, out sound);
return TryGetFootstepSound(coordinates, out sound);
}
private bool TryGetFootstepSound(EntityUid gridId, EntityCoordinates coordinates, out float variation, [NotNullWhen(true)] out string? sound)
private bool TryGetFootstepSound(EntityCoordinates coordinates, [NotNullWhen(true)] out SoundSpecifier? sound)
{
variation = 0f;
sound = null;
var grid = _mapManager.GetGrid(gridId);
var gridUid = coordinates.GetGridUid(EntityManager);
// Fallback to the map
if (gridUid == null)
{
if (TryComp<FootstepModifierComponent>(coordinates.GetMapUid(EntityManager), out var modifier))
{
sound = modifier.Sound;
return true;
}
return false;
}
var grid = _mapManager.GetGrid(gridUid.Value);
var tile = grid.GetTileRef(coordinates);
if (tile.IsSpace(_tileDefinitionManager)) return false;
@@ -377,18 +389,15 @@ namespace Content.Shared.Movement.Systems
{
if (EntityManager.TryGetComponent(maybeFootstep, out FootstepModifierComponent? footstep))
{
sound = footstep.SoundCollection.GetSound();
variation = footstep.Variation;
sound = footstep.Sound;
return true;
}
}
// Walking on a tile.
var def = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];
sound = def.FootstepSounds?.GetSound();
variation = FootstepVariation;
return !string.IsNullOrEmpty(sound);
sound = def.FootstepSounds;
return sound != null;
}
}
}