Skip to content

Commit

Permalink
port ore bag magnet toggle from white dream (#2467)
Browse files Browse the repository at this point in the history
* add on textures for ore bags

* add code for toggling magnet and working in-hand

* update ore bag yml

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
  • Loading branch information
deltanedas authored and dvir001 committed Jan 22, 2025
1 parent 80c1f3f commit f2afa1e
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.DeltaV.Item.ItemToggle.Systems;
using Robust.Shared.GameStates;

namespace Content.Shared.DeltaV.Item.ItemToggle.Components;

/// <summary>
/// Adds examine text when the item is on or off.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(ItemToggleExamineSystem))]
public sealed partial class ItemToggleExamineComponent : Component
{
[DataField(required: true)]
public LocId On;

[DataField(required: true)]
public LocId Off;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Shared.DeltaV.Item.ItemToggle.Components;
using Content.Shared.Examine;
using Content.Shared.Item.ItemToggle;

namespace Content.Shared.DeltaV.Item.ItemToggle.Systems;

public sealed class ItemToggleExamineSystem : EntitySystem
{
[Dependency] private readonly ItemToggleSystem _toggle = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ItemToggleExamineComponent, ExaminedEvent>(OnExamined);
}

private void OnExamined(Entity<ItemToggleExamineComponent> ent, ref ExaminedEvent args)
{
var msg = _toggle.IsActivated(ent.Owner) ? ent.Comp.On : ent.Comp.Off;
args.PushMarkup(Loc.GetString(msg));
}
}
89 changes: 16 additions & 73 deletions Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
// using Content.Server.Storage.Components;
using Content.Shared.Clothing.Components; // Frontier
using Content.Shared.Examine; // Frontier
using Content.Shared.Hands.Components; // Frontier
using Content.Server.Storage.Components;
using Content.Shared.Inventory;
using Content.Shared.Verbs; // Frontier
using Content.Shared.Storage.Components; // Frontier
using Content.Shared.Item.ItemToggle; // DeltaV
using Content.Shared.Whitelist;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
using Robust.Shared.Utility; // Frontier

namespace Content.Shared.Storage.EntitySystems;

Expand All @@ -22,6 +16,7 @@ public sealed class MagnetPickupSystem : EntitySystem
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly ItemToggleSystem _toggle = default!; // DeltaV
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedStorageSystem _storage = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
Expand All @@ -36,55 +31,13 @@ public override void Initialize()
base.Initialize();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
SubscribeLocalEvent<MagnetPickupComponent, MapInitEvent>(OnMagnetMapInit);
SubscribeLocalEvent<MagnetPickupComponent, ExaminedEvent>(OnExamined); // Frontier
SubscribeLocalEvent<MagnetPickupComponent, GetVerbsEvent<AlternativeVerb>>(AddToggleMagnetVerb); // Frontier
}

private void OnMagnetMapInit(EntityUid uid, MagnetPickupComponent component, MapInitEvent args)
{
component.NextScan = _timing.CurTime;
}

// Frontier, used to add the magnet toggle to the context menu
private void AddToggleMagnetVerb(EntityUid uid, MagnetPickupComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;

if (!HasComp<HandsComponent>(args.User))
return;

AlternativeVerb verb = new()
{
Act = () =>
{
ToggleMagnet(uid, component);
},
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/Spare/poweronoff.svg.192dpi.png")),
Text = Loc.GetString("magnet-pickup-component-toggle-verb"),
Priority = 3
};

args.Verbs.Add(verb);
}

// Frontier, used to show the magnet state on examination
private void OnExamined(EntityUid uid, MagnetPickupComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("magnet-pickup-component-on-examine-main",
("stateText", Loc.GetString(component.MagnetEnabled
? "magnet-pickup-component-magnet-on"
: "magnet-pickup-component-magnet-off"))));
}

// Frontier, used to toggle the magnet on the ore bag/box
public bool ToggleMagnet(EntityUid uid, MagnetPickupComponent comp)
{
comp.MagnetEnabled = !comp.MagnetEnabled;
Dirty(uid, comp);
return comp.MagnetEnabled;
}

public override void Update(float frameTime)
{
base.Update(frameTime);
Expand All @@ -96,25 +49,24 @@ public override void Update(float frameTime)
if (comp.NextScan > currentTime)
continue;

comp.NextScan = currentTime + ScanDelay; // Frontier: ensure the next scan is in the future
comp.NextScan += ScanDelay;

// No space
if (!_storage.HasSpace((uid, storage)))
// Begin DeltaV Addition: Make ore bags use ItemToggle
if (!_toggle.IsActivated(uid))
continue;
// End DeltaV Addition

// Frontier - magnet disabled
if (!comp.MagnetEnabled)
continue;
// Begin DeltaV Removals: Allow ore bags to work inhand
//if (!_inventory.TryGetContainingSlot((uid, xform, meta), out var slotDef))
// continue;

// Frontier - is ore bag on belt?
if (HasComp<ClothingComponent>(uid))
{
if (!_inventory.TryGetContainingSlot(uid, out var slotDef))
continue;
//if ((slotDef.SlotFlags & comp.SlotFlags) == 0x0)
// continue;
// End DeltaV Removals

if ((slotDef.SlotFlags & comp.SlotFlags) == 0x0)
continue;
}
// No space
if (!_storage.HasSpace((uid, storage)))
continue;

var parentUid = xform.ParentUid;
var playedSound = false;
Expand All @@ -126,15 +78,6 @@ public override void Update(float frameTime)
if (_whitelistSystem.IsWhitelistFail(storage.Whitelist, near))
continue;

// FRONTIER - START
// Makes sure that after the last insertion, there is still bag space.
// Using a cheap 'how many slots left' vs 'how many we need' check, and additional stack check.
// Note: Unfortunately, this is still 'expensive' as it checks the entire bag, however its better than
// to rotate an item n^n times of every item in the bag to find the best fit, for every xy coordinate it has.
if (!_storage.HasSlotSpaceFor(uid, near))
continue;
// FRONTIER - END

if (!_physicsQuery.TryGetComponent(near, out var physics) || physics.BodyStatus != BodyStatus.OnGround)
continue;

Expand Down Expand Up @@ -162,4 +105,4 @@ public override void Update(float frameTime)
}
}
}
}
}
31 changes: 28 additions & 3 deletions Resources/Prototypes/Entities/Objects/Specific/Salvage/ore_bag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
- type: MagnetPickup
- type: Sprite
sprite: Objects/Specific/Mining/ore_bag.rsi
state: icon
#state: icon # DeltaV: use a layer instead
layers: # DeltaV
- state: icon
map: [ "enum.ToggleVisuals.Layer" ]
- type: Clothing
sprite: Objects/Specific/Mining/ore_bag.rsi
quickEquip: false
slots:
- belt
- type: Item
size: Ginormous
size: Huge # DeltaV: Was Ginormous, lets it fit in conscription bag
- type: Storage
maxItemSize: Normal
grid:
Expand All @@ -25,4 +28,26 @@
tags:
- ArtifactFragment
- Ore
- type: Dumpable
- type: Dumpable
# Begin DeltaV Additions: toggle magnet from White Dream
- type: ItemToggle
soundActivate: &soundActivate
collection: sparks
params:
variation: 0.25
soundDeactivate: *soundActivate
- type: ItemToggleExamine
on: magnet-pickup-component-magnet-on
off: magnet-pickup-component-magnet-off
- type: Appearance
- type: GenericVisualizer
visuals:
enum.ToggleVisuals.Toggled:
enum.ToggleVisuals.Layer:
True: { state: icon_on }
False: { state: icon }
# End DeltaV Additions
- type: ReverseEngineering # DeltaV
difficulty: 2
recipes:
- OreBagOfHolding
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion Resources/Textures/Objects/Specific/Mining/ore_bag.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Homegrown by @ninruB#7795, inhand sprites by lzk228(discord 455630609641897984)",
"copyright": "Homegrown by @ninruB#7795, inhand sprites by lzk228(discord 455630609641897984) | icon_on state by @kilath",
"size": {
"x": 32,
"y": 32
Expand All @@ -21,6 +21,19 @@
{
"name": "inhand-right",
"directions": 4
},
{
"name": "icon_on",
"delays": [
[
0.1,
0.1,
0.1,
0.1,
0.1,
0.1
]
]
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from Paradise at https://github.com/ParadiseSS13/Paradise/blob/5ce5a66c814c4a60118d24885389357fd0240002/icons/obj/mining.dmi",
"copyright": "Taken from Paradise at https://github.com/ParadiseSS13/Paradise/blob/5ce5a66c814c4a60118d24885389357fd0240002/icons/obj/mining.dmi | icon_on state by PuroSlavKing (Github)",
"size": {
"x": 32,
"y": 32
Expand Down Expand Up @@ -106,6 +106,25 @@
0.1
]
]
},
{
"name": "icon_on",
"delays": [
[
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1,
0.1
]
]
}
]
}

0 comments on commit f2afa1e

Please sign in to comment.