]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix magic mirror (#28084)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sun, 19 May 2024 22:35:55 +0000 (18:35 -0400)
committerGitHub <noreply@github.com>
Sun, 19 May 2024 22:35:55 +0000 (16:35 -0600)
* Fix magic mirror

* buff magic mirror

Content.Server/MagicMirror/MagicMirrorSystem.cs
Content.Shared/MagicMirror/MagicMirrorComponent.cs
Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs
Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml

index 84f1f1c3e57be5b172c993d501489cc01e750be7..fc1bff9756600799c2f30e2126c28f6867dd7926 100644 (file)
@@ -7,9 +7,7 @@ using Content.Shared.Humanoid;
 using Content.Shared.Humanoid.Markings;
 using Content.Shared.Interaction;
 using Content.Shared.MagicMirror;
-using Robust.Server.GameObjects;
 using Robust.Shared.Audio.Systems;
-using Robust.Shared.Player;
 
 namespace Content.Server.MagicMirror;
 
@@ -22,14 +20,14 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
     [Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
     [Dependency] private readonly MarkingManager _markings = default!;
     [Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
-    [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
 
     public override void Initialize()
     {
         base.Initialize();
         SubscribeLocalEvent<MagicMirrorComponent, ActivatableUIOpenAttemptEvent>(OnOpenUIAttempt);
 
-        Subs.BuiEvents<MagicMirrorComponent>(MagicMirrorUiKey.Key, subs =>
+        Subs.BuiEvents<MagicMirrorComponent>(MagicMirrorUiKey.Key,
+            subs =>
         {
             subs.Event<BoundUIClosedEvent>(OnUiClosed);
             subs.Event<MagicMirrorSelectMessage>(OnMagicMirrorSelect);
@@ -278,32 +276,6 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
 
     }
 
-    private void UpdateInterface(EntityUid mirrorUid, EntityUid targetUid, MagicMirrorComponent component)
-    {
-        if (!TryComp<HumanoidAppearanceComponent>(targetUid, out var humanoid))
-            return;
-
-        var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
-            ? new List<Marking>(hairMarkings)
-            : new();
-
-        var facialHair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.FacialHair, out var facialHairMarkings)
-            ? new List<Marking>(facialHairMarkings)
-            : new();
-
-        var state = new MagicMirrorUiState(
-            humanoid.Species,
-            hair,
-            humanoid.MarkingSet.PointsLeft(MarkingCategories.Hair) + hair.Count,
-            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;
index 63575439052426522e1cae40f25aa5ac2224e0fd..95b17369795b7b62afe5e0ef38f09796e17fefe4 100644 (file)
@@ -47,5 +47,5 @@ public sealed partial class MagicMirrorComponent : Component
     /// Sound emitted when slots are changed
     /// </summary>
     [DataField, ViewVariables(VVAccess.ReadWrite)]
-    public SoundSpecifier ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg");
+    public SoundSpecifier? ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg");
 }
index f9c941ffe394b8cf730b4d6fd92dbdf6bd867881..91059d60bfd3efd721b11c1b25b4293d9edbb133 100644 (file)
@@ -1,6 +1,8 @@
 using Content.Shared.DoAfter;
+using Content.Shared.Humanoid;
 using Content.Shared.Humanoid.Markings;
 using Content.Shared.Interaction;
+using Content.Shared.UserInterface;
 using Robust.Shared.Serialization;
 
 namespace Content.Shared.MagicMirror;
@@ -8,10 +10,12 @@ namespace Content.Shared.MagicMirror;
 public abstract class SharedMagicMirrorSystem : EntitySystem
 {
     [Dependency] private readonly SharedInteractionSystem _interaction = default!;
+    [Dependency] protected readonly SharedUserInterfaceSystem _uiSystem = default!;
 
     public override void Initialize()
     {
         base.Initialize();
+        SubscribeLocalEvent<MagicMirrorComponent, BeforeActivatableUIOpenEvent>(OnBeforeUIOpen);
         SubscribeLocalEvent<MagicMirrorComponent, BoundUserInterfaceCheckRangeEvent>(OnMirrorRangeCheck);
     }
 
@@ -22,6 +26,38 @@ public abstract class SharedMagicMirrorSystem : EntitySystem
             args.Result = BoundUserInterfaceRangeResult.Fail;
         }
     }
+
+    private void OnBeforeUIOpen(Entity<MagicMirrorComponent> ent, ref BeforeActivatableUIOpenEvent args)
+    {
+        ent.Comp.Target ??= args.User;
+        UpdateInterface(ent, args.User, ent);
+    }
+
+    protected void UpdateInterface(EntityUid mirrorUid, EntityUid targetUid, MagicMirrorComponent component)
+    {
+        if (!TryComp<HumanoidAppearanceComponent>(targetUid, out var humanoid))
+            return;
+
+        var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
+            ? new List<Marking>(hairMarkings)
+            : new();
+
+        var facialHair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.FacialHair, out var facialHairMarkings)
+            ? new List<Marking>(facialHairMarkings)
+            : new();
+
+        var state = new MagicMirrorUiState(
+            humanoid.Species,
+            hair,
+            humanoid.MarkingSet.PointsLeft(MarkingCategories.Hair) + hair.Count,
+            facialHair,
+            humanoid.MarkingSet.PointsLeft(MarkingCategories.FacialHair) + facialHair.Count);
+
+        // TODO: Component states
+        component.Target = targetUid;
+        _uiSystem.SetUiState(mirrorUid, MagicMirrorUiKey.Key, state);
+        Dirty(mirrorUid, component);
+    }
 }
 
 [Serializable, NetSerializable]
index d02bce020daaa324d6a6cebb19b4b8a5cf79b762..1fe3318ef5581014fccb2aa4eb87cd1aa8ec39e5 100644 (file)
   - type: Clickable
   - type: Transform
     anchored: true
-  - type: MagicMirror
+  - type: MagicMirror #instant and silent
+    changeHairSound: null
+    addSlotTime: 0
+    removeSlotTime: 0
+    selectSlotTime: 0
+    changeSlotTime: 0
   - type: ActivatableUI
     key: enum.MagicMirrorUiKey.Key
   - type: UserInterface