Rollerbed / foldable strap fixes. (#16106)

This commit is contained in:
Leon Friedrich
2023-05-05 19:27:15 +12:00
committed by GitHub
parent 1a4f522267
commit cc4edb9f87
8 changed files with 19 additions and 24 deletions

View File

@@ -23,11 +23,11 @@ public sealed class RotationVisualizerSystem : VisualizerSystem<RotationVisualsC
{ {
base.OnAppearanceChange(uid, component, ref args); base.OnAppearanceChange(uid, component, ref args);
if (!AppearanceSystem.TryGetData<RotationState>(uid, RotationVisuals.RotationState, out var state, args.Component) || if (args.Sprite == null)
args.Sprite == null)
{
return; return;
}
// If not defined, defaults to standing.
AppearanceSystem.TryGetData<RotationState>(uid, RotationVisuals.RotationState, out var state, args.Component);
switch (state) switch (state)
{ {

View File

@@ -8,6 +8,7 @@ namespace Content.Client.Storage
/// Client version of item storage containers, contains a UI which displays stored entities and their size /// Client version of item storage containers, contains a UI which displays stored entities and their size
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(SharedStorageComponent))]
public sealed class ClientStorageComponent : SharedStorageComponent public sealed class ClientStorageComponent : SharedStorageComponent
{ {
[Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!;

View File

@@ -13,7 +13,6 @@ namespace Content.Server.Foldable
[UsedImplicitly] [UsedImplicitly]
public sealed class FoldableSystem : SharedFoldableSystem public sealed class FoldableSystem : SharedFoldableSystem
{ {
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
[Dependency] private readonly SharedContainerSystem _container = default!; [Dependency] private readonly SharedContainerSystem _container = default!;
public override void Initialize() public override void Initialize()
@@ -65,20 +64,6 @@ namespace Content.Server.Foldable
return true; return true;
} }
/// <summary>
/// Set the folded state of the given <see cref="FoldableComponent"/>
/// </summary>
/// <param name="uid"></param>
/// <param name="component"></param>
/// <param name="folded">If true, the component will become folded, else unfolded</param>
public override void SetFolded(EntityUid uid, FoldableComponent component, bool folded)
{
base.SetFolded(uid, component, folded);
// You can't buckle an entity to a folded object
_buckle.StrapSetEnabled(uid, !component.IsFolded);
}
#region Verb #region Verb
private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetVerbsEvent<AlternativeVerb> args) private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetVerbsEvent<AlternativeVerb> args)

View File

@@ -14,7 +14,7 @@ public sealed class StrapComponent : Component
/// <summary> /// <summary>
/// The entities that are currently buckled /// The entities that are currently buckled
/// </summary> /// </summary>
[ViewVariables] [ViewVariables] // TODO serialization
public readonly HashSet<EntityUid> BuckledEntities = new(); public readonly HashSet<EntityUid> BuckledEntities = new();
/// <summary> /// <summary>

View File

@@ -169,6 +169,7 @@ public abstract partial class SharedBuckleSystem
/// <param name="strapComp"> strap component of the thing we are strapping to </param> /// <param name="strapComp"> strap component of the thing we are strapping to </param>
private void UpdateBuckleStatus(EntityUid uid, BuckleComponent buckleComp, StrapComponent? strapComp = null) private void UpdateBuckleStatus(EntityUid uid, BuckleComponent buckleComp, StrapComponent? strapComp = null)
{ {
AppearanceSystem.SetData(uid, StrapVisuals.State, buckleComp.Buckled);
if (buckleComp.BuckledTo != null) if (buckleComp.BuckledTo != null)
{ {
if (!Resolve(buckleComp.BuckledTo.Value, ref strapComp)) if (!Resolve(buckleComp.BuckledTo.Value, ref strapComp))
@@ -471,8 +472,6 @@ public abstract partial class SharedBuckleSystem
{ {
_standingSystem.Down(buckleUid); _standingSystem.Down(buckleUid);
} }
// Sync StrapComponent data
AppearanceSystem.SetData(strapUid, StrapVisuals.State, false);
if (strapComp.BuckledEntities.Remove(buckleUid)) if (strapComp.BuckledEntities.Remove(buckleUid))
{ {
strapComp.OccupiedSize -= buckleComp.Size; strapComp.OccupiedSize -= buckleComp.Size;
@@ -480,6 +479,7 @@ public abstract partial class SharedBuckleSystem
Dirty(strapComp); Dirty(strapComp);
} }
AppearanceSystem.SetData(strapUid, StrapVisuals.State, strapComp.BuckledEntities.Count != 0);
_audioSystem.PlayPredicted(strapComp.UnbuckleSound, strapUid, buckleUid); _audioSystem.PlayPredicted(strapComp.UnbuckleSound, strapUid, buckleUid);
var ev = new BuckleChangeEvent(strapUid, buckleUid, false); var ev = new BuckleChangeEvent(strapUid, buckleUid, false);

View File

@@ -14,6 +14,7 @@ public abstract partial class SharedBuckleSystem
{ {
private void InitializeStrap() private void InitializeStrap()
{ {
SubscribeLocalEvent<StrapComponent, ComponentStartup>(OnStrapStartup);
SubscribeLocalEvent<StrapComponent, ComponentShutdown>(OnStrapShutdown); SubscribeLocalEvent<StrapComponent, ComponentShutdown>(OnStrapShutdown);
SubscribeLocalEvent<StrapComponent, ComponentRemove>((_, c, _) => StrapRemoveAll(c)); SubscribeLocalEvent<StrapComponent, ComponentRemove>((_, c, _) => StrapRemoveAll(c));
@@ -34,6 +35,11 @@ public abstract partial class SharedBuckleSystem
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent); SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
} }
private void OnStrapStartup(EntityUid uid, StrapComponent component, ComponentStartup args)
{
AppearanceSystem.SetData(uid, StrapVisuals.State, component.BuckledEntities.Count != 0);
}
private void OnStrapShutdown(EntityUid uid, StrapComponent component, ComponentShutdown args) private void OnStrapShutdown(EntityUid uid, StrapComponent component, ComponentShutdown args)
{ {
if (LifeStage(uid) > EntityLifeStage.MapInitialized) if (LifeStage(uid) > EntityLifeStage.MapInitialized)

View File

@@ -1,3 +1,4 @@
using Content.Shared.Buckle;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
@@ -10,6 +11,7 @@ namespace Content.Shared.Foldable;
public abstract class SharedFoldableSystem : EntitySystem public abstract class SharedFoldableSystem : EntitySystem
{ {
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!; [Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
[Dependency] private readonly SharedBuckleSystem _buckle = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -65,6 +67,7 @@ public abstract class SharedFoldableSystem : EntitySystem
component.IsFolded = folded; component.IsFolded = folded;
Dirty(component); Dirty(component);
Appearance.SetData(uid, FoldedVisuals.State, folded); Appearance.SetData(uid, FoldedVisuals.State, folded);
_buckle.StrapSetEnabled(uid, !component.IsFolded);
} }
private void OnInsertEvent(EntityUid uid, FoldableComponent component, ContainerGettingInsertedAttemptEvent args) private void OnInsertEvent(EntityUid uid, FoldableComponent component, ContainerGettingInsertedAttemptEvent args)

View File

@@ -12,9 +12,9 @@ namespace Content.Shared.Rotation
public enum RotationState public enum RotationState
{ {
/// <summary> /// <summary>
/// Standing up /// Standing up. This is the default value.
/// </summary> /// </summary>
Vertical, Vertical = 0,
/// <summary> /// <summary>
/// Laying down /// Laying down