mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
## Mirror of PR #26287: [Code cleanup: Purge obsoleted SharedPhysicsSystem methods](https://github.com/space-wizards/space-station-14/pull/26287) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `964c6d54caae45b205a326143f56d6458a1bbc8a` PR opened by <img src="https://avatars.githubusercontent.com/u/85356?v=4" width="16"/><a href="https://github.com/Tayrtahn"> Tayrtahn</a> at 2024-03-20 13:37:25 UTC --- PR changed 16 files with 43 additions and 43 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > <!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> > <!-- The text between the arrows are comments - they will not be visible on your PR. --> > > Requires https://github.com/space-wizards/RobustToolbox/pull/4979 > > ## About the PR > <!-- What did you change in this PR? --> > Cleans up some obsolete method calls. > > ## Why / Balance / Technical > <!-- Why was it changed? Link any discussions or issues here. Please discuss how this would affect game balance. --> > Cleaning up obsolete Dirty calls in RT required changing the signatures of some public methods in SharedPhysicsSystem. This updates the calls to those methods here in Content to use the new signatures passing in UIDs. > > </details> Co-authored-by: SimpleStation14 <Unknown>
203 lines
6.5 KiB
C#
203 lines
6.5 KiB
C#
using Content.Shared.Actions;
|
|
using Content.Shared.Gravity;
|
|
using Content.Shared.Interaction.Events;
|
|
using Content.Shared.Movement.Components;
|
|
using Content.Shared.Movement.Events;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Physics.Components;
|
|
using Robust.Shared.Physics.Systems;
|
|
using Robust.Shared.Serialization;
|
|
|
|
namespace Content.Shared.Movement.Systems;
|
|
|
|
public abstract class SharedJetpackSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
|
|
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
|
|
[Dependency] protected readonly SharedContainerSystem Container = default!;
|
|
[Dependency] private readonly SharedMoverController _mover = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<JetpackComponent, GetItemActionsEvent>(OnJetpackGetAction);
|
|
SubscribeLocalEvent<JetpackComponent, DroppedEvent>(OnJetpackDropped);
|
|
SubscribeLocalEvent<JetpackComponent, ToggleJetpackEvent>(OnJetpackToggle);
|
|
SubscribeLocalEvent<JetpackComponent, CanWeightlessMoveEvent>(OnJetpackCanWeightlessMove);
|
|
|
|
SubscribeLocalEvent<JetpackUserComponent, CanWeightlessMoveEvent>(OnJetpackUserCanWeightless);
|
|
SubscribeLocalEvent<JetpackUserComponent, EntParentChangedMessage>(OnJetpackUserEntParentChanged);
|
|
|
|
SubscribeLocalEvent<GravityChangedEvent>(OnJetpackUserGravityChanged);
|
|
SubscribeLocalEvent<JetpackComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, JetpackComponent component, MapInitEvent args)
|
|
{
|
|
_actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
|
|
Dirty(uid, component);
|
|
}
|
|
|
|
private void OnJetpackCanWeightlessMove(EntityUid uid, JetpackComponent component, ref CanWeightlessMoveEvent args)
|
|
{
|
|
args.CanMove = true;
|
|
}
|
|
|
|
private void OnJetpackUserGravityChanged(ref GravityChangedEvent ev)
|
|
{
|
|
var gridUid = ev.ChangedGridIndex;
|
|
var jetpackQuery = GetEntityQuery<JetpackComponent>();
|
|
|
|
var query = EntityQueryEnumerator<JetpackUserComponent, TransformComponent>();
|
|
while (query.MoveNext(out var uid, out var user, out var transform))
|
|
{
|
|
if (transform.GridUid == gridUid && ev.HasGravity &&
|
|
jetpackQuery.TryGetComponent(user.Jetpack, out var jetpack))
|
|
{
|
|
_popup.PopupClient(Loc.GetString("jetpack-to-grid"), uid, uid);
|
|
|
|
SetEnabled(user.Jetpack, jetpack, false, uid);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnJetpackDropped(EntityUid uid, JetpackComponent component, DroppedEvent args)
|
|
{
|
|
SetEnabled(uid, component, false, args.User);
|
|
}
|
|
|
|
private void OnJetpackUserCanWeightless(EntityUid uid, JetpackUserComponent component, ref CanWeightlessMoveEvent args)
|
|
{
|
|
args.CanMove = true;
|
|
}
|
|
|
|
private void OnJetpackUserEntParentChanged(EntityUid uid, JetpackUserComponent component, ref EntParentChangedMessage args)
|
|
{
|
|
if (TryComp<JetpackComponent>(component.Jetpack, out var jetpack) &&
|
|
!CanEnableOnGrid(args.Transform.GridUid))
|
|
{
|
|
SetEnabled(component.Jetpack, jetpack, false, uid);
|
|
|
|
_popup.PopupClient(Loc.GetString("jetpack-to-grid"), uid, uid);
|
|
}
|
|
}
|
|
|
|
private void SetupUser(EntityUid user, EntityUid jetpackUid)
|
|
{
|
|
var userComp = EnsureComp<JetpackUserComponent>(user);
|
|
_mover.SetRelay(user, jetpackUid);
|
|
|
|
if (TryComp<PhysicsComponent>(user, out var physics))
|
|
_physics.SetBodyStatus(user, physics, BodyStatus.InAir);
|
|
|
|
userComp.Jetpack = jetpackUid;
|
|
}
|
|
|
|
private void RemoveUser(EntityUid uid)
|
|
{
|
|
if (!RemComp<JetpackUserComponent>(uid))
|
|
return;
|
|
|
|
if (TryComp<PhysicsComponent>(uid, out var physics))
|
|
_physics.SetBodyStatus(uid, physics, BodyStatus.OnGround);
|
|
|
|
RemComp<RelayInputMoverComponent>(uid);
|
|
}
|
|
|
|
private void OnJetpackToggle(EntityUid uid, JetpackComponent component, ToggleJetpackEvent args)
|
|
{
|
|
if (args.Handled)
|
|
return;
|
|
|
|
if (TryComp<TransformComponent>(uid, out var xform) && !CanEnableOnGrid(xform.GridUid))
|
|
{
|
|
_popup.PopupClient(Loc.GetString("jetpack-no-station"), uid, args.Performer);
|
|
|
|
return;
|
|
}
|
|
|
|
SetEnabled(uid, component, !IsEnabled(uid));
|
|
}
|
|
|
|
private bool CanEnableOnGrid(EntityUid? gridUid)
|
|
{
|
|
return gridUid == null ||
|
|
(!HasComp<GravityComponent>(gridUid));
|
|
}
|
|
|
|
private void OnJetpackGetAction(EntityUid uid, JetpackComponent component, GetItemActionsEvent args)
|
|
{
|
|
args.AddAction(ref component.ToggleActionEntity, component.ToggleAction);
|
|
}
|
|
|
|
private bool IsEnabled(EntityUid uid)
|
|
{
|
|
return HasComp<ActiveJetpackComponent>(uid);
|
|
}
|
|
|
|
public void SetEnabled(EntityUid uid, JetpackComponent component, bool enabled, EntityUid? user = null)
|
|
{
|
|
if (IsEnabled(uid) == enabled ||
|
|
enabled && !CanEnable(uid, component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (enabled)
|
|
{
|
|
EnsureComp<ActiveJetpackComponent>(uid);
|
|
}
|
|
else
|
|
{
|
|
RemComp<ActiveJetpackComponent>(uid);
|
|
}
|
|
|
|
if (user == null)
|
|
{
|
|
Container.TryGetContainingContainer(uid, out var container);
|
|
user = container?.Owner;
|
|
}
|
|
|
|
// Can't activate if no one's using.
|
|
if (user == null && enabled)
|
|
return;
|
|
|
|
if (user != null)
|
|
{
|
|
if (enabled)
|
|
{
|
|
SetupUser(user.Value, uid);
|
|
}
|
|
else
|
|
{
|
|
RemoveUser(user.Value);
|
|
}
|
|
|
|
_movementSpeedModifier.RefreshMovementSpeedModifiers(user.Value);
|
|
}
|
|
|
|
Appearance.SetData(uid, JetpackVisuals.Enabled, enabled);
|
|
Dirty(uid, component);
|
|
}
|
|
|
|
public bool IsUserFlying(EntityUid uid)
|
|
{
|
|
return HasComp<JetpackUserComponent>(uid);
|
|
}
|
|
|
|
protected virtual bool CanEnable(EntityUid uid, JetpackComponent component)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public enum JetpackVisuals : byte
|
|
{
|
|
Enabled,
|
|
}
|