Skip to content

Commit

Permalink
[Feature] Added Toggle to magnetPickupSystem / [FIX] Ore Processor Fix (
Browse files Browse the repository at this point in the history
#15)

* [NEW] Added toggle to magnetPickupSystem / [FIX] ore processor fix

* Ru locale / En localisation fix

* code change after review

* WHITE comments added

* ON sprites added by @Kilath

* update test.

* fix

* update tests

* Changed ContainingSlot/SlotDef checks. Added ForcePickup.

* Component fixed

* microfix

* style: a bit of styling

---------

Co-authored-by: Remuchi <[email protected]>
  • Loading branch information
HellCatten and Remuchi committed Sep 3, 2024
1 parent 50088ac commit 86534e1
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 20 deletions.
11 changes: 7 additions & 4 deletions Content.Shared/Storage/Components/MagnetPickupComponent.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using Content.Shared.Inventory;
using Robust.Shared.GameStates;

namespace Content.Server.Storage.Components;

/// <summary>
/// Applies an ongoing pickup area around the attached entity.
/// </summary>
[RegisterComponent, AutoGenerateComponentPause]
[NetworkedComponent]
[RegisterComponent, AutoGenerateComponentPause, AutoGenerateComponentState]
public sealed partial class MagnetPickupComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("nextScan")]
[AutoPausedField]
public TimeSpan NextScan = TimeSpan.Zero;

/// <summary>
/// What container slot the magnet needs to be in to work.
/// If true, ignores SlotFlags and can magnet pickup on hands/ground.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("slotFlags")]
public SlotFlags SlotFlags = SlotFlags.BELT;
[ViewVariables(VVAccess.ReadWrite), DataField]
[AutoNetworkedField]
public bool ForcePickup = true;

[ViewVariables(VVAccess.ReadWrite), DataField("range")]
public float Range = 1f;
Expand Down
45 changes: 36 additions & 9 deletions Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Content.Server.Storage.Components;
using Content.Shared.Examine;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.Item.ItemToggle;
using Content.Shared.Item.ItemToggle.Components;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
Expand All @@ -16,6 +20,8 @@ public sealed class MagnetPickupSystem : EntitySystem
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedStorageSystem _storage = default!;
[Dependency] private readonly SharedItemToggleSystem _itemToggle = default!; // WD EDIT
[Dependency] private readonly SharedItemSystem _item = default!; // White Dream

private static readonly TimeSpan ScanDelay = TimeSpan.FromSeconds(1);

Expand All @@ -25,6 +31,8 @@ public override void Initialize()
{
base.Initialize();
_physicsQuery = GetEntityQuery<PhysicsComponent>();
SubscribeLocalEvent<MagnetPickupComponent, ItemToggledEvent>(OnItemToggled); // White Dream
SubscribeLocalEvent<MagnetPickupComponent, ExaminedEvent>(OnExamined); // WD EDIT
SubscribeLocalEvent<MagnetPickupComponent, MapInitEvent>(OnMagnetMapInit);
}

Expand All @@ -33,6 +41,21 @@ private void OnMagnetMapInit(EntityUid uid, MagnetPickupComponent component, Map
component.NextScan = _timing.CurTime;
}

//WD EDIT start
private void OnExamined(Entity<MagnetPickupComponent> entity, ref ExaminedEvent args)
{
var onMsg = _itemToggle.IsActivated(entity.Owner)
? Loc.GetString("comp-magnet-pickup-examined-on")
: Loc.GetString("comp-magnet-pickup-examined-off");
args.PushMarkup(onMsg);
}

private void OnItemToggled(Entity<MagnetPickupComponent> entity, ref ItemToggledEvent args)
{
_item.SetHeldPrefix(entity.Owner, args.Activated ? "on" : "off");
}
//WD EDIT end

public override void Update(float frameTime)
{
base.Update(frameTime);
Expand All @@ -41,16 +64,23 @@ public override void Update(float frameTime)

while (query.MoveNext(out var uid, out var comp, out var storage, out var xform, out var meta))
{
if (comp.NextScan > currentTime)
// WD EDIT START
if (!TryComp<ItemToggleComponent>(uid, out var toggle))
continue;

comp.NextScan += ScanDelay;
if (!_itemToggle.IsActivated(uid, toggle))
continue;
// WD EDIT END

if (!_inventory.TryGetContainingSlot((uid, xform, meta), out var slotDef))
if (comp.NextScan > currentTime)
continue;

if ((slotDef.SlotFlags & comp.SlotFlags) == 0x0)
comp.NextScan += ScanDelay;

// WD EDIT START. Added ForcePickup.
if (!comp.ForcePickup && !_inventory.TryGetContainingSlot((uid, xform, meta), out _))
continue;
//WD EDIT END.

// No space
if (!_storage.HasSpace((uid, storage)))
Expand All @@ -77,17 +107,14 @@ public override void Update(float frameTime)
// the problem is that stack pickups delete the original entity, which is fine, but due to
// game state handling we can't show a lerp animation for it.
var nearXform = Transform(near);
var nearMap = nearXform.MapPosition;
var nearMap = _transform.GetMapCoordinates(near);
var nearCoords = EntityCoordinates.FromMap(moverCoords.EntityId, nearMap, _transform, EntityManager);

if (!_storage.Insert(uid, near, out var stacked, storageComp: storage, playSound: !playedSound))
continue;

// Play pickup animation for either the stack entity or the original entity.
if (stacked != null)
_storage.PlayPickupAnimation(stacked.Value, nearCoords, finalCoords, nearXform.LocalRotation);
else
_storage.PlayPickupAnimation(near, nearCoords, finalCoords, nearXform.LocalRotation);
_storage.PlayPickupAnimation(stacked ?? near, nearCoords, finalCoords, nearXform.LocalRotation);

playedSound = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Used when examining the MagnetPickupComponent

comp-magnet-pickup-examined-on = The magnet is currently [color=darkgreen]on[/color].
comp-magnet-pickup-examined-off = The magnet is currently [color=darkred]off[/color].
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Выводится при осмотре предмета с MagnetPickupCompontent

comp-magnet-pickup-examined-on = Магнит сейчас [color=darkgreen]включен[/color].
comp-magnet-pickup-examined-off = Магнит сейчас [color=darkred]выключен[/color].
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
- type: MagnetPickup
- type: Sprite
sprite: Objects/Specific/Mining/ore_bag.rsi
state: icon
layers:
- state: orebag_off
map: [ "enum.ToggleVisuals.Layer" ]
- type: Clothing
sprite: Objects/Specific/Mining/ore_bag.rsi
quickEquip: false
slots:
- belt
- type: Item
heldPrefix: off
size: Ginormous
- type: Storage
maxItemSize: Normal
Expand All @@ -26,3 +29,21 @@
- ArtifactFragment
- Ore
- type: Dumpable
# WHITE EDIT START
- type: ItemToggle
soundActivate:
collection: sparks
params:
variation: 0.250
soundDeactivate:
collection: sparks
params:
variation: 0.250
- type: Appearance
- type: GenericVisualizer
visuals:
enum.ToggleVisuals.Toggled:
enum.ToggleVisuals.Layer:
True: { state: orebag_on }
False: { state: orebag_off }
# WHITE EDIT END
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
range: 2
- type: Sprite
sprite: Objects/Specific/Mining/ore_bag_holding.rsi
state: icon
layers:
- state: orebag_off
map: [ "enum.ToggleVisuals.Layer" ]
- type: GenericVisualizer
visuals:
enum.ToggleVisuals.Toggled:
enum.ToggleVisuals.Layer:
True: { state: orebag_on }
False: { state: orebag_off }
- type: Clothing
sprite: Objects/Specific/Mining/ore_bag_holding.rsi
- type: Storage
Expand Down
3 changes: 2 additions & 1 deletion Resources/Prototypes/Entities/Structures/Machines/lathe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@
- type: MaterialStorageMagnetPickup # Delta V - Summary: Adds magnet pull from Frontier
magnetEnabled: True
range: 0.30 # Delta V - End Magnet Pull
- type: PlaceableSurface # WHITE EDIT

- type: entity
parent: OreProcessor
Expand Down Expand Up @@ -1412,4 +1413,4 @@
- type: MaterialStorage
whitelist:
tags:
- PrizeTicket
- PrizeTicket
17 changes: 15 additions & 2 deletions Resources/Textures/Objects/Specific/Mining/ore_bag.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Homegrown by @ninruB#7795, inhand sprites by лазік#7305",
"copyright": "Homegrown by @ninruB#7795, inhand sprites by лазік#7305, ON state sprite by @kilath",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon"
"name": "orebag_off"
},
{
"name": "equipped-BELT",
Expand All @@ -21,6 +21,19 @@
{
"name": "inhand-right",
"directions": 4
},
{
"name": "orebag_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,14 +1,14 @@
{
"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, ON state sprite by @kilath",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon",
"name": "orebag_off",
"delays": [
[
0.1,
Expand All @@ -19,6 +19,25 @@
]
]
},
{
"name": "orebag_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
]
]
},
{
"name": "equipped-BELT",
"directions": 4
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 86534e1

Please sign in to comment.