]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix magic mirror prediction (#27356)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fri, 26 Apr 2024 12:37:09 +0000 (22:37 +1000)
committerGitHub <noreply@github.com>
Fri, 26 Apr 2024 12:37:09 +0000 (22:37 +1000)
Content.Client/MagicMirror/MagicMirrorBoundUserInterface.cs
Content.Client/MagicMirror/MagicMirrorSystem.cs [new file with mode: 0644]
Content.Server/MagicMirror/MagicMirrorSystem.cs
Content.Shared/MagicMirror/MagicMirrorComponent.cs [moved from Content.Server/MagicMirror/MagicMirrorComponent.cs with 89% similarity]
Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs

index bfbf2efe4f96f0084754c94ed36f9d04e14c734e..f6979bf8d7bbee1d0de9e7810b8c380c2cd16b0e 100644 (file)
@@ -72,9 +72,6 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
         if (!disposing)
             return;
 
-        if (_window != null)
-            _window.OnClose -= Close;
-
         _window?.Dispose();
     }
 }
diff --git a/Content.Client/MagicMirror/MagicMirrorSystem.cs b/Content.Client/MagicMirror/MagicMirrorSystem.cs
new file mode 100644 (file)
index 0000000..9b0b1de
--- /dev/null
@@ -0,0 +1,8 @@
+using Content.Shared.MagicMirror;
+
+namespace Content.Client.MagicMirror;
+
+public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
+{
+
+}
index 188ff40b020ce1548a8d0141b3562b623202d1e5..84f1f1c3e57be5b172c993d501489cc01e750be7 100644 (file)
@@ -16,13 +16,12 @@ namespace Content.Server.MagicMirror;
 /// <summary>
 /// Allows humanoids to change their appearance mid-round.
 /// </summary>
-public sealed class MagicMirrorSystem : EntitySystem
+public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
 {
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
     [Dependency] private readonly MarkingManager _markings = default!;
     [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
-    [Dependency] private readonly SharedInteractionSystem _interaction = default!;
     [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
 
     public override void Initialize()
@@ -45,16 +44,6 @@ public sealed class MagicMirrorSystem : EntitySystem
         SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorDoAfterEvent>(OnChangeColorDoAfter);
         SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorRemoveSlotDoAfterEvent>(OnRemoveSlotDoAfter);
         SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotDoAfterEvent>(OnAddSlotDoAfter);
-
-        SubscribeLocalEvent<MagicMirrorComponent, BoundUserInterfaceCheckRangeEvent>(OnMirrorRangeCheck);
-    }
-
-    private void OnMirrorRangeCheck(EntityUid uid, MagicMirrorComponent component, ref BoundUserInterfaceCheckRangeEvent args)
-    {
-        if (!Exists(component.Target) || !_interaction.InRangeUnobstructed(uid, component.Target.Value))
-        {
-            args.Result = BoundUserInterfaceRangeResult.Fail;
-        }
     }
 
     private void OnMagicMirrorInteract(Entity<MagicMirrorComponent> mirror, ref AfterInteractEvent args)
@@ -309,12 +298,15 @@ public sealed class MagicMirrorSystem : EntitySystem
             facialHair,
             humanoid.MarkingSet.PointsLeft(MarkingCategories.FacialHair) + facialHair.Count);
 
+        // TODO: Component states
         component.Target = targetUid;
         _uiSystem.SetUiState(mirrorUid, MagicMirrorUiKey.Key, state);
+        Dirty(mirrorUid, component);
     }
 
     private void OnUiClosed(Entity<MagicMirrorComponent> ent, ref BoundUIClosedEvent args)
     {
         ent.Comp.Target = null;
+        Dirty(ent);
     }
 }
similarity index 89%
rename from Content.Server/MagicMirror/MagicMirrorComponent.cs
rename to Content.Shared/MagicMirror/MagicMirrorComponent.cs
index 624a381ca58088a8f3544533c7c6c198eeef2d2b..63575439052426522e1cae40f25aa5ac2224e0fd 100644 (file)
@@ -1,13 +1,13 @@
 using Content.Shared.DoAfter;
-using Content.Shared.Humanoid;
 using Robust.Shared.Audio;
+using Robust.Shared.GameStates;
 
-namespace Content.Server.MagicMirror;
+namespace Content.Shared.MagicMirror;
 
 /// <summary>
 /// Allows humanoids to change their appearance mid-round.
 /// </summary>
-[RegisterComponent]
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
 public sealed partial class MagicMirrorComponent : Component
 {
     [DataField]
@@ -16,7 +16,7 @@ public sealed partial class MagicMirrorComponent : Component
     /// <summary>
     /// Magic mirror target, used for validating UI messages.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public EntityUid? Target;
 
     /// <summary>
index 0b22e024982e4b534a5a08a8360b4392503c78be..f9c941ffe394b8cf730b4d6fd92dbdf6bd867881 100644 (file)
@@ -1,10 +1,29 @@
 using Content.Shared.DoAfter;
 using Content.Shared.Humanoid.Markings;
-using Robust.Shared.Player;
+using Content.Shared.Interaction;
 using Robust.Shared.Serialization;
 
 namespace Content.Shared.MagicMirror;
 
+public abstract class SharedMagicMirrorSystem : EntitySystem
+{
+    [Dependency] private readonly SharedInteractionSystem _interaction = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+        SubscribeLocalEvent<MagicMirrorComponent, BoundUserInterfaceCheckRangeEvent>(OnMirrorRangeCheck);
+    }
+
+    private void OnMirrorRangeCheck(EntityUid uid, MagicMirrorComponent component, ref BoundUserInterfaceCheckRangeEvent args)
+    {
+        if (!Exists(component.Target) || !_interaction.InRangeUnobstructed(uid, component.Target.Value))
+        {
+            args.Result = BoundUserInterfaceRangeResult.Fail;
+        }
+    }
+}
+
 [Serializable, NetSerializable]
 public enum MagicMirrorUiKey : byte
 {