-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into prowlerupdateagain
- Loading branch information
Showing
14 changed files
with
512 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Content.Shared._NF.Foldable.Systems; | ||
|
||
[RegisterComponent] | ||
public sealed partial class FoldableFixtureComponent : Component | ||
{ | ||
[DataField(required: true)] | ||
public List<string> FoldedFixtures; | ||
[DataField(required: true)] | ||
public List<string> UnfoldedFixtures; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Content.Shared.Foldable; | ||
using Robust.Shared.Physics.Systems; | ||
|
||
namespace Content.Shared._NF.Foldable.Systems; | ||
|
||
public sealed class FoldableFixtureSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly FixtureSystem _fixtures = default!; | ||
[Dependency] private readonly SharedPhysicsSystem _physics = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<FoldableFixtureComponent, MapInitEvent>(OnMapInit); | ||
SubscribeLocalEvent<FoldableFixtureComponent, FoldedEvent>(OnFolded); | ||
} | ||
|
||
private void OnMapInit(EntityUid uid, FoldableFixtureComponent component, MapInitEvent args) | ||
{ | ||
if (TryComp<FoldableComponent>(uid, out var foldable)) | ||
SetFoldedFixtures(uid, foldable.IsFolded, component); | ||
} | ||
|
||
private void OnFolded(EntityUid uid, FoldableFixtureComponent? component, ref FoldedEvent args) | ||
{ | ||
SetFoldedFixtures(uid, args.IsFolded, component); | ||
} | ||
|
||
// Sets all relevant fixtures for the entity to an appropriate hard/soft state. | ||
private void SetFoldedFixtures(EntityUid uid, bool isFolded, FoldableFixtureComponent? component) | ||
{ | ||
if (!Resolve(uid, ref component)) | ||
return; | ||
|
||
if (isFolded) | ||
{ | ||
SetAllFixtureHardness(uid, component.FoldedFixtures, true); | ||
SetAllFixtureHardness(uid, component.UnfoldedFixtures, false); | ||
} | ||
else | ||
{ | ||
SetAllFixtureHardness(uid, component.FoldedFixtures, false); | ||
SetAllFixtureHardness(uid, component.UnfoldedFixtures, true); | ||
} | ||
} | ||
|
||
// Sets all fixtures on an entity in a list to either be hard or soft. | ||
void SetAllFixtureHardness(EntityUid uid, List<string> fixtures, bool hard) | ||
{ | ||
foreach (var fixName in fixtures) | ||
{ | ||
var fixture = _fixtures.GetFixtureOrNull(uid, fixName); | ||
if (fixture != null) | ||
_physics.SetHard(uid, fixture, hard); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.