]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Remove server-side sprite references from Flash system (#15893)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Sat, 29 Apr 2023 10:20:09 +0000 (22:20 +1200)
committerGitHub <noreply@github.com>
Sat, 29 Apr 2023 10:20:09 +0000 (20:20 +1000)
Content.Server/Flash/FlashSystem.cs
Content.Shared/Flash/FlashableComponent.cs
Resources/Prototypes/Entities/Objects/Tools/lantern.yml
Resources/Prototypes/Entities/Objects/Weapons/security.yml

index 016ea7e7818c54e1778b9eab3a5a9d32b7ddb11e..40bb9eb6f0997c39f43ab45b319c686a74110434 100644 (file)
@@ -1,9 +1,9 @@
 using System.Linq;
 using Content.Server.Flash.Components;
 using Content.Server.Light.EntitySystems;
+using Content.Server.Popups;
 using Content.Server.Stunnable;
 using Content.Shared.Examine;
-using Content.Shared.Eye.Blinding;
 using Content.Shared.Eye.Blinding.Components;
 using Content.Shared.Flash;
 using Content.Shared.IdentityManagement;
@@ -29,9 +29,11 @@ namespace Content.Server.Flash
         [Dependency] private readonly IGameTiming _gameTiming = default!;
         [Dependency] private readonly StunSystem _stunSystem = default!;
         [Dependency] private readonly InventorySystem _inventorySystem = default!;
-        [Dependency] private readonly MetaDataSystem _metaSystem = default!;
+        [Dependency] private readonly AudioSystem _audio = default!;
         [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
         [Dependency] private readonly TagSystem _tagSystem = default!;
+        [Dependency] private readonly PopupSystem _popup = default!;
+        [Dependency] private readonly AppearanceSystem _appearance = default!;
 
         public override void Initialize()
         {
@@ -51,7 +53,7 @@ namespace Content.Server.Flash
         {
             if (!args.IsHit ||
                 !args.HitEntities.Any() ||
-                !UseFlash(comp, args.User))
+                !UseFlash(uid, comp, args.User))
             {
                 return;
             }
@@ -65,46 +67,37 @@ namespace Content.Server.Flash
 
         private void OnFlashUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args)
         {
-            if (args.Handled || !UseFlash(comp, args.User))
+            if (args.Handled || !UseFlash(uid, comp, args.User))
                 return;
 
             args.Handled = true;
             FlashArea(uid, args.User, comp.Range, comp.AoeFlashDuration, comp.SlowTo, true);
         }
 
-        private bool UseFlash(FlashComponent comp, EntityUid user)
+        private bool UseFlash(EntityUid uid, FlashComponent comp, EntityUid user)
         {
-            if (comp.HasUses)
+            if (!comp.HasUses || comp.Flashing)
+                return false;
+
+            comp.Uses--;
+            _audio.PlayPvs(comp.Sound, uid);
+            comp.Flashing = true;
+            _appearance.SetData(uid, FlashVisuals.Flashing, true);
+
+            if (comp.Uses == 0)
             {
-                // TODO flash visualizer
-                if (!EntityManager.TryGetComponent<SpriteComponent?>(comp.Owner, out var sprite))
-                    return false;
-
-                if (--comp.Uses == 0)
-                {
-                    sprite.LayerSetState(0, "burnt");
-
-                    _tagSystem.AddTag(comp.Owner, "Trash");
-                    comp.Owner.PopupMessage(user, Loc.GetString("flash-component-becomes-empty"));
-                }
-                else if (!comp.Flashing)
-                {
-                    int animLayer = sprite.AddLayerWithState("flashing");
-                    comp.Flashing = true;
-
-                    comp.Owner.SpawnTimer(400, () =>
-                    {
-                        sprite.RemoveLayer(animLayer);
-                        comp.Flashing = false;
-                    });
-                }
-
-                SoundSystem.Play(comp.Sound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner, AudioParams.Default);
-
-                return true;
+                _appearance.SetData(uid, FlashVisuals.Burnt, true);
+                _tagSystem.AddTag(uid, "Trash");
+                _popup.PopupEntity(Loc.GetString("flash-component-becomes-empty"), user);
             }
 
-            return false;
+            uid.SpawnTimer(400, () =>
+            {
+                _appearance.SetData(uid, FlashVisuals.Flashing, false);
+                comp.Flashing = false;
+            });
+
+            return true;
         }
 
         public void Flash(EntityUid target, EntityUid? user, EntityUid? used, float flashDuration, float slowTo, bool displayPopup = true, FlashableComponent? flashable = null)
index 74dec8bf0b70845b9e2eecb96fdb86a1e7fbfe08..c51933e0a6e6856ca6aefb440ae17882fba5c051 100644 (file)
@@ -24,4 +24,13 @@ namespace Content.Shared.Flash
             Time = time;
         }
     }
+
+    [Serializable, NetSerializable]
+    public enum FlashVisuals : byte
+    {
+        BaseLayer,
+        LightLayer,
+        Burnt,
+        Flashing,
+    }
 }
index b3c32d64d83be7ef1fcdf504d6940b8c6516d4e1..2262675d35662a01995181ea809c012dfdeeb045 100644 (file)
   id: lanternextrabright
   description: Blinding.
   components:
+    - type: Sprite
+      sprite: Objects/Tools/lantern.rsi
+      layers:
+      - state: lantern
+        map: [ "enum.FlashVisuals.BaseLayer" ]
+      - state: lantern-on
+        shader: unshaded
+        visible: false
+        map: [ "light" ]
+      - state: flashing
+        map: [ "enum.FlashVisuals.LightLayer" ]
+        visible: false
     - type: PointLight
       enabled: false
       radius: 5
       color: "#FFC458"
     - type: Flash
       uses: 15
+    - type: Appearance
+    - type: GenericVisualizer
+      visuals:
+        enum.FlashVisuals.Burnt:
+          enum.FlashVisuals.BaseLayer:
+            True: {state: burnt}
+        enum.FlashVisuals.Flashing:
+          enum.FlashVisuals.LightLayer:
+            True: {visible: true}
+            False: {visible: false}
index 3bfec3d583603cf0fdac4680019a5031e4b3db22..8e3e333090741d0c926836824df023611012a719 100644 (file)
   components:
     - type: Sprite
       sprite: Objects/Weapons/Melee/flash.rsi
-      state: flash
+      layers:
+      - state: flash
+        map: [ "enum.FlashVisuals.BaseLayer" ]
+      - state: flashing
+        map: [ "enum.FlashVisuals.LightLayer" ]
+        visible: false
+        shader: unshaded
     - type: Flash
     - type: MeleeWeapon
       damage:
     - type: ItemCooldown
     - type: StaticPrice
       price: 40
+    - type: Appearance
+    - type: GenericVisualizer
+      visuals:
+        enum.FlashVisuals.Burnt:
+          enum.FlashVisuals.BaseLayer:
+            True: {state: burnt}
+        enum.FlashVisuals.Flashing:
+          enum.FlashVisuals.LightLayer:
+            True: {visible: true}
+            False: {visible: false}
 
 - type: entity
   name: portable flasher