]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Candy Bucket for Halloween (#21257)
authorBixkitts <72874643+Bixkitts@users.noreply.github.com>
Tue, 31 Oct 2023 15:54:41 +0000 (16:54 +0100)
committerGitHub <noreply@github.com>
Tue, 31 Oct 2023 15:54:41 +0000 (11:54 -0400)
* Added candy bucket and component to update appearance of held containers akin to it

* cleanup newline

* newline was load-bearing

* moved component to Shared, cleanup

* newline is spooky

* You build and run without errors, stop pretending otherwise

* Updated for new storage system in master branch

Content.Shared/ContainerHeld/ContainerHeldComponent.cs [new file with mode: 0644]
Content.Shared/ContainerHeld/ContainerHeldSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Fun/candy_bucket.yml [new file with mode: 0644]
Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-left.png [new file with mode: 0644]
Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-right.png [new file with mode: 0644]
Resources/Textures/Objects/Fun/candy_bucket.rsi/empty_icon.png [new file with mode: 0644]
Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-left.png [new file with mode: 0644]
Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-right.png [new file with mode: 0644]
Resources/Textures/Objects/Fun/candy_bucket.rsi/full_icon.png [new file with mode: 0644]
Resources/Textures/Objects/Fun/candy_bucket.rsi/meta.json [new file with mode: 0644]

diff --git a/Content.Shared/ContainerHeld/ContainerHeldComponent.cs b/Content.Shared/ContainerHeld/ContainerHeldComponent.cs
new file mode 100644 (file)
index 0000000..cc6d2bf
--- /dev/null
@@ -0,0 +1,14 @@
+namespace Content.Shared.ContainerHeld;
+
+[RegisterComponent]
+public sealed partial class ContainerHeldComponent: Component
+{
+    /// <summary>
+    ///     The amount of weight needed to be in the container
+    ///     in order for it to toggle it's appearance
+    ///     to ToggleVisuals.Toggled = true, and
+    ///     SetHeldPrefix() to "full" instead of "empty".
+    /// </summary>
+    [DataField("threshold")]
+    public int Threshold { get; private set; } = 1;
+}
diff --git a/Content.Shared/ContainerHeld/ContainerHeldSystem.cs b/Content.Shared/ContainerHeld/ContainerHeldSystem.cs
new file mode 100644 (file)
index 0000000..e0ecfe1
--- /dev/null
@@ -0,0 +1,43 @@
+using Robust.Shared.Containers;
+
+using Content.Shared.Item;
+using Content.Shared.Storage;
+using Content.Shared.Storage.EntitySystems;
+using Content.Shared.Toggleable;
+
+namespace Content.Shared.ContainerHeld;
+
+public sealed class ContainerHeldSystem : EntitySystem
+{
+    [Dependency] private readonly SharedItemSystem _item = default!;
+    [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+    [Dependency] private readonly SharedStorageSystem _storage = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<ContainerHeldComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
+        SubscribeLocalEvent<ContainerHeldComponent, EntRemovedFromContainerMessage>(OnContainerModified);
+    }
+
+    private void OnContainerModified(EntityUid uid, ContainerHeldComponent comp, ContainerModifiedMessage args)
+    {
+        if (!(TryComp<StorageComponent>(uid, out var storage)
+              && TryComp<AppearanceComponent>(uid, out var appearance)
+              && TryComp<ItemComponent>(uid, out var item)))
+        {
+            return;
+        }
+        if (_storage.GetCumulativeItemSizes(uid, storage) >= comp.Threshold)
+        {
+            _item.SetHeldPrefix(uid, "full", item);
+            _appearance.SetData(uid, ToggleVisuals.Toggled, true, appearance);
+        }
+        else
+        {
+            _item.SetHeldPrefix(uid, "empty", item);
+            _appearance.SetData(uid, ToggleVisuals.Toggled, false, appearance);
+        }
+    }
+}
diff --git a/Resources/Prototypes/Entities/Objects/Fun/candy_bucket.yml b/Resources/Prototypes/Entities/Objects/Fun/candy_bucket.yml
new file mode 100644 (file)
index 0000000..5bdf80f
--- /dev/null
@@ -0,0 +1,42 @@
+- type: entity
+  name: "candy bucket"
+  parent: BaseItem
+  id: CandyBucket
+  description: A festive bucket for all your treats.
+  components:
+  - type: Sprite
+    sprite: Objects/Fun/candy_bucket.rsi
+    layers:
+    - state: empty_icon
+      map: [ "enum.ToggleVisuals.Layer" ]
+  - type: ContainerHeld
+    threshold: 1
+  - type: Item
+    heldPrefix: empty
+    size: 20
+  - type: Appearance
+  - type: GenericVisualizer
+    visuals:
+     enum.ToggleVisuals.Toggled:
+        enum.ToggleVisuals.Layer:
+          True: {state: full_icon}
+          False: {state: empty_icon}
+  - type: Storage
+    maxItemSize: Small
+    maxTotalWeight: 10
+    whitelist:
+      components:
+        - Pill
+      tags:
+        - FoodSnack
+  - type: ContainerContainer
+    containers:
+      storagebase: !type:Container
+        ents: []
+  - type: UserInterface
+    interfaces:
+    - key: enum.StorageUiKey.Key
+      type: StorageBoundUserInterface
+  # to prevent bag open/honk spam
+  - type: UseDelay
+    delay: 0.5
diff --git a/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-left.png b/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-left.png
new file mode 100644 (file)
index 0000000..b1a487b
Binary files /dev/null and b/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-left.png differ
diff --git a/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-right.png b/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-right.png
new file mode 100644 (file)
index 0000000..3cdffed
Binary files /dev/null and b/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty-inhand-right.png differ
diff --git a/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty_icon.png b/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty_icon.png
new file mode 100644 (file)
index 0000000..b2216f0
Binary files /dev/null and b/Resources/Textures/Objects/Fun/candy_bucket.rsi/empty_icon.png differ
diff --git a/Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-left.png b/Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-left.png
new file mode 100644 (file)
index 0000000..2a804cf
Binary files /dev/null and b/Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-left.png differ
diff --git a/Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-right.png b/Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-right.png
new file mode 100644 (file)
index 0000000..32a28cb
Binary files /dev/null and b/Resources/Textures/Objects/Fun/candy_bucket.rsi/full-inhand-right.png differ
diff --git a/Resources/Textures/Objects/Fun/candy_bucket.rsi/full_icon.png b/Resources/Textures/Objects/Fun/candy_bucket.rsi/full_icon.png
new file mode 100644 (file)
index 0000000..673d50f
Binary files /dev/null and b/Resources/Textures/Objects/Fun/candy_bucket.rsi/full_icon.png differ
diff --git a/Resources/Textures/Objects/Fun/candy_bucket.rsi/meta.json b/Resources/Textures/Objects/Fun/candy_bucket.rsi/meta.json
new file mode 100644 (file)
index 0000000..e5d850f
--- /dev/null
@@ -0,0 +1,33 @@
+{
+  "version": 1,
+  "license": "CC-BY-SA-3.0",
+  "copyright": "Made by @ps3moira#9488",
+  "size": {
+    "x": 32,
+    "y": 32
+  },
+  "states": [
+    {
+      "name": "empty_icon"
+    },
+    {
+      "name": "full_icon"
+    },
+    {
+      "name": "empty-inhand-right",
+      "directions": 4
+    },
+    {
+      "name": "empty-inhand-left",
+      "directions": 4
+    },
+    {
+      "name": "full-inhand-right",
+      "directions": 4
+    },
+    {
+      "name": "full-inhand-left",
+      "directions": 4
+    }
+  ]
+}