]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
make chameleon verb predicted (#35156)
authorMilon <milonpl.git@proton.me>
Fri, 14 Feb 2025 14:35:27 +0000 (15:35 +0100)
committerGitHub <noreply@github.com>
Fri, 14 Feb 2025 14:35:27 +0000 (15:35 +0100)
* ok but what if we just predicted EVERYTHING

* cleanup

Content.Server/Clothing/Systems/ChameleonClothingSystem.cs
Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs

index 3700aeb549c8b27732dfd2a0040ab091997b8c7f..5c8954cc69b0a6c31d1f842660c1c666d30e7734 100644 (file)
@@ -3,18 +3,13 @@ using Content.Shared.Clothing.Components;
 using Content.Shared.Clothing.EntitySystems;
 using Content.Shared.IdentityManagement.Components;
 using Content.Shared.Prototypes;
-using Content.Shared.Verbs;
-using Robust.Server.GameObjects;
-using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
-using Robust.Shared.Utility;
 
 namespace Content.Server.Clothing.Systems;
 
 public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem
 {
     [Dependency] private readonly IPrototypeManager _proto = default!;
-    [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
     [Dependency] private readonly IComponentFactory _factory = default!;
     [Dependency] private readonly IdentitySystem _identity = default!;
 
@@ -22,7 +17,6 @@ public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem
     {
         base.Initialize();
         SubscribeLocalEvent<ChameleonClothingComponent, MapInitEvent>(OnMapInit);
-        SubscribeLocalEvent<ChameleonClothingComponent, GetVerbsEvent<InteractionVerb>>(OnVerb);
         SubscribeLocalEvent<ChameleonClothingComponent, ChameleonPrototypeSelectedMessage>(OnSelected);
     }
 
@@ -31,40 +25,18 @@ public sealed class ChameleonClothingSystem : SharedChameleonClothingSystem
         SetSelectedPrototype(uid, component.Default, true, component);
     }
 
-    private void OnVerb(EntityUid uid, ChameleonClothingComponent component, GetVerbsEvent<InteractionVerb> args)
-    {
-        if (!args.CanAccess || !args.CanInteract || component.User != args.User)
-            return;
-
-        args.Verbs.Add(new InteractionVerb()
-        {
-            Text = Loc.GetString("chameleon-component-verb-text"),
-            Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/settings.svg.192dpi.png")),
-            Act = () => TryOpenUi(uid, args.User, component)
-        });
-    }
-
     private void OnSelected(EntityUid uid, ChameleonClothingComponent component, ChameleonPrototypeSelectedMessage args)
     {
         SetSelectedPrototype(uid, args.SelectedId, component: component);
     }
 
-    private void TryOpenUi(EntityUid uid, EntityUid user, ChameleonClothingComponent? component = null)
-    {
-        if (!Resolve(uid, ref component))
-            return;
-        if (!TryComp(user, out ActorComponent? actor))
-            return;
-        _uiSystem.TryToggleUi(uid, ChameleonUiKey.Key, actor.PlayerSession);
-    }
-
     private void UpdateUi(EntityUid uid, ChameleonClothingComponent? component = null)
     {
         if (!Resolve(uid, ref component))
             return;
 
         var state = new ChameleonBoundUserInterfaceState(component.Slot, component.Default, component.RequireTag);
-        _uiSystem.SetUiState(uid, ChameleonUiKey.Key, state);
+        UI.SetUiState(uid, ChameleonUiKey.Key, state);
     }
 
     /// <summary>
index 488b7a5b641c3876ea05d72af20497ebb0a9f31a..725b0347661e21665520fa449bc23b0f322155e4 100644 (file)
@@ -5,8 +5,9 @@ using Content.Shared.Inventory;
 using Content.Shared.Inventory.Events;
 using Content.Shared.Item;
 using Content.Shared.Tag;
+using Content.Shared.Verbs;
 using Robust.Shared.Prototypes;
-using Robust.Shared.Serialization.Manager;
+using Robust.Shared.Utility;
 
 namespace Content.Shared.Clothing.EntitySystems;
 
@@ -14,19 +15,20 @@ public abstract class SharedChameleonClothingSystem : EntitySystem
 {
     [Dependency] private readonly IComponentFactory _factory = default!;
     [Dependency] private readonly IPrototypeManager _proto = default!;
-    [Dependency] private readonly ISerializationManager _serialization = default!;
     [Dependency] private readonly ClothingSystem _clothingSystem = default!;
     [Dependency] private readonly ContrabandSystem _contraband = default!;
     [Dependency] private readonly MetaDataSystem _metaData = default!;
     [Dependency] private readonly SharedItemSystem _itemSystem = default!;
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly TagSystem _tag = default!;
+    [Dependency] protected readonly SharedUserInterfaceSystem UI = default!;
 
     public override void Initialize()
     {
         base.Initialize();
         SubscribeLocalEvent<ChameleonClothingComponent, GotEquippedEvent>(OnGotEquipped);
         SubscribeLocalEvent<ChameleonClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
+        SubscribeLocalEvent<ChameleonClothingComponent, GetVerbsEvent<InteractionVerb>>(OnVerb);
     }
 
     private void OnGotEquipped(EntityUid uid, ChameleonClothingComponent component, GotEquippedEvent args)
@@ -94,6 +96,22 @@ public abstract class SharedChameleonClothingSystem : EntitySystem
         }
     }
 
+    private void OnVerb(Entity<ChameleonClothingComponent> ent, ref GetVerbsEvent<InteractionVerb> args)
+    {
+        if (!args.CanAccess || !args.CanInteract || ent.Comp.User != args.User)
+            return;
+
+        // Can't pass args from a ref event inside of lambdas
+        var user = args.User;
+
+        args.Verbs.Add(new InteractionVerb()
+        {
+            Text = Loc.GetString("chameleon-component-verb-text"),
+            Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/settings.svg.192dpi.png")),
+            Act = () => UI.TryToggleUi(ent.Owner, ChameleonUiKey.Key, user)
+        });
+    }
+
     protected virtual void UpdateSprite(EntityUid uid, EntityPrototype proto) { }
 
     /// <summary>