Files
RobustToolbox/Robust.Shared/Player/ActorSystem.cs
83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

56 lines
1.4 KiB
C#

using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Robust.Shared.Player;
/// <summary>
/// System that handles <see cref="ActorComponent"/>.
/// </summary>
public sealed partial class ActorSystem : EntitySystem
{
[Dependency] private ISharedPlayerManager _playerManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ActorComponent, ComponentShutdown>(OnActorShutdown);
}
private void OnActorShutdown(EntityUid entity, ActorComponent component, ComponentShutdown args)
{
_playerManager.SetAttachedEntity(component.PlayerSession, null);
}
/// <summary>
/// Retrieves the session on a given entity, if one exists.
/// </summary>
[PublicAPI]
public bool TryGetSession(EntityUid? uid, out ICommonSession? session)
{
if (TryComp(uid, out ActorComponent? actorComp))
{
session = actorComp.PlayerSession;
return true;
}
session = null;
return false;
}
/// <summary>
/// Retrieves the session on a given entity, if one exists.
/// </summary>
[PublicAPI]
[Pure]
public ICommonSession? GetSession(EntityUid? uid)
{
if (TryComp(uid, out ActorComponent? actorComp))
{
return actorComp.PlayerSession;
}
return null;
}
}