Dumb orbit fix (#6806)

This commit is contained in:
mirrorcult
2022-02-19 17:42:11 -07:00
committed by GitHub
parent 3e6bf54727
commit 35f0b9bbcd
2 changed files with 33 additions and 58 deletions

View File

@@ -7,7 +7,7 @@ using Robust.Shared.Random;
namespace Content.Client.Orbit; namespace Content.Client.Orbit;
public sealed class OrbitVisualsSystem : VisualizerSystem<OrbitVisualsComponent> public sealed class OrbitVisualsSystem : EntitySystem
{ {
[Dependency] private readonly IRobustRandom _robustRandom = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!;
@@ -19,6 +19,7 @@ public sealed class OrbitVisualsSystem : VisualizerSystem<OrbitVisualsComponent>
base.Initialize(); base.Initialize();
SubscribeLocalEvent<OrbitVisualsComponent, ComponentInit>(OnComponentInit); SubscribeLocalEvent<OrbitVisualsComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<OrbitVisualsComponent, ComponentRemove>(OnComponentRemove);
SubscribeLocalEvent<OrbitVisualsComponent, AnimationCompletedEvent>(OnAnimationCompleted); SubscribeLocalEvent<OrbitVisualsComponent, AnimationCompletedEvent>(OnAnimationCompleted);
} }
@@ -28,6 +29,34 @@ public sealed class OrbitVisualsSystem : VisualizerSystem<OrbitVisualsComponent>
_robustRandom.NextFloat(0.75f * component.OrbitDistance, 1.25f * component.OrbitDistance); _robustRandom.NextFloat(0.75f * component.OrbitDistance, 1.25f * component.OrbitDistance);
component.OrbitLength = _robustRandom.NextFloat(0.5f * component.OrbitLength, 1.5f * component.OrbitLength); component.OrbitLength = _robustRandom.NextFloat(0.5f * component.OrbitLength, 1.5f * component.OrbitLength);
var animationPlayer = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
return;
if (animationPlayer.HasRunningAnimation(_orbitStopKey))
{
animationPlayer.Stop(_orbitStopKey);
}
animationPlayer.Play(GetOrbitAnimation(component), _orbitAnimationKey);
}
private void OnComponentRemove(EntityUid uid, OrbitVisualsComponent component, ComponentRemove args)
{
if (!TryComp<ISpriteComponent>(uid, out var sprite))
return;
var animationPlayer = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
{
animationPlayer.Stop(_orbitAnimationKey);
}
if (!animationPlayer.HasRunningAnimation(_orbitStopKey))
{
animationPlayer.Play(GetStopAnimation(component, sprite), _orbitStopKey);
}
} }
public override void FrameUpdate(float frameTime) public override void FrameUpdate(float frameTime)
@@ -44,43 +73,6 @@ public sealed class OrbitVisualsSystem : VisualizerSystem<OrbitVisualsComponent>
} }
} }
protected override void OnAppearanceChange(EntityUid uid, OrbitVisualsComponent component, ref AppearanceChangeEvent args)
{
if (!args.Component.TryGetData<bool>(OrbitingVisuals.IsOrbiting, out var orbiting))
return;
if (!TryComp<ISpriteComponent>(uid, out var sprite))
return;
var animationPlayer = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
if (orbiting)
{
if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
return;
if (animationPlayer.HasRunningAnimation(_orbitStopKey))
{
animationPlayer.Stop(_orbitStopKey);
}
animationPlayer.Play(GetOrbitAnimation(component), _orbitAnimationKey);
}
else
{
RemComp<OrbitVisualsComponent>(uid);
if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
{
animationPlayer.Stop(_orbitAnimationKey);
}
if (!animationPlayer.HasRunningAnimation(_orbitStopKey))
{
animationPlayer.Play(GetStopAnimation(component, sprite), _orbitStopKey);
}
}
}
private void OnAnimationCompleted(EntityUid uid, OrbitVisualsComponent component, AnimationCompletedEvent args) private void OnAnimationCompleted(EntityUid uid, OrbitVisualsComponent component, AnimationCompletedEvent args)
{ {
if (args.Key == _orbitAnimationKey) if (args.Key == _orbitAnimationKey)

View File

@@ -71,18 +71,13 @@ public sealed class FollowerSystem : EntitySystem
followerComp.Following = entity; followerComp.Following = entity;
var followedComp = EnsureComp<FollowedComponent>(entity); var followedComp = EnsureComp<FollowedComponent>(entity);
if (!followedComp.Following.Add(follower)) followedComp.Following.Add(follower);
return;
var xform = Transform(follower); var xform = Transform(follower);
xform.AttachParent(entity); xform.AttachParent(entity);
xform.LocalPosition = Vector2.Zero; xform.LocalPosition = Vector2.Zero;
if (TryComp<AppearanceComponent>(follower, out var appearance))
{
EnsureComp<OrbitVisualsComponent>(follower); EnsureComp<OrbitVisualsComponent>(follower);
appearance.SetData(OrbitingVisuals.IsOrbiting, true);
}
var followerEv = new StartedFollowingEntityEvent(entity, follower); var followerEv = new StartedFollowingEntityEvent(entity, follower);
var entityEv = new EntityStartedFollowingEvent(entity, follower); var entityEv = new EntityStartedFollowingEvent(entity, follower);
@@ -110,12 +105,7 @@ public sealed class FollowerSystem : EntitySystem
Transform(uid).AttachToGridOrMap(); Transform(uid).AttachToGridOrMap();
if (TryComp<AppearanceComponent>(uid, out var appearance)) RemComp<OrbitVisualsComponent>(uid);
{
// We don't remove OrbitVisuals here since the OrbitVisualsSystem will handle that itself
// during the OnChangeData, which is deferred..
appearance.SetData(OrbitingVisuals.IsOrbiting, false);
}
var uidEv = new StoppedFollowingEntityEvent(target, uid); var uidEv = new StoppedFollowingEntityEvent(target, uid);
var targetEv = new EntityStoppedFollowingEvent(target, uid); var targetEv = new EntityStoppedFollowingEvent(target, uid);
@@ -191,10 +181,3 @@ public sealed class EntityStoppedFollowingEvent : FollowEvent
{ {
} }
} }
[Serializable, NetSerializable]
public enum OrbitingVisuals : byte
{
IsOrbiting
}