mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-02 18:17:09 +02:00
* [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>
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Physics.Components;
|
|
|
|
namespace Robust.Shared.Physics.Systems;
|
|
|
|
public sealed partial class FixturesChangeSystem : EntitySystem
|
|
{
|
|
[Dependency] private FixtureSystem _fixtures = default!;
|
|
[Dependency] private SharedPhysicsSystem _physics = default!;
|
|
|
|
private EntityQuery<FixturesComponent> _fixturesQuery;
|
|
private EntityQuery<PhysicsComponent> _physicsQuery;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_fixturesQuery = GetEntityQuery<FixturesComponent>();
|
|
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
|
SubscribeLocalEvent<FixturesChangeComponent, ComponentStartup>(OnChangeStartup);
|
|
SubscribeLocalEvent<FixturesChangeComponent, ComponentShutdown>(OnChangeShutdown);
|
|
}
|
|
|
|
private void OnChangeStartup(Entity<FixturesChangeComponent> ent, ref ComponentStartup args)
|
|
{
|
|
if (!_physicsQuery.TryComp(ent, out var physics) || !_fixturesQuery.TryComp(ent, out var fixtures))
|
|
return;
|
|
|
|
foreach (var (id, fixture) in ent.Comp.Fixtures)
|
|
{
|
|
_fixtures.TryCreateFixture(ent.Owner,
|
|
fixture.Shape,
|
|
id,
|
|
fixture.Density,
|
|
fixture.Hard,
|
|
fixture.CollisionLayer,
|
|
fixture.CollisionMask,
|
|
fixture.Friction,
|
|
fixture.Restitution,
|
|
manager: fixtures,
|
|
body: physics);
|
|
}
|
|
|
|
// TODO: Fixture creation should be handling this.
|
|
_physics.WakeBody(ent.Owner, manager: fixtures, body: physics);
|
|
}
|
|
|
|
private void OnChangeShutdown(Entity<FixturesChangeComponent> ent, ref ComponentShutdown args)
|
|
{
|
|
foreach (var id in ent.Comp.Fixtures.Keys)
|
|
{
|
|
_fixtures.DestroyFixture(ent.Owner, id);
|
|
}
|
|
}
|
|
}
|