forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from iaada/slotable-lenses
Slotable lenses
- Loading branch information
Showing
15 changed files
with
242 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.Lens; | ||
|
||
/// <summary> | ||
/// This component is used alongside <see cref="ItemSlotsComponent"/> to find a specific container. | ||
/// Enables clothing to change functionality based on items inside of it. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class LensSlotComponent : Component | ||
{ | ||
[DataField("LensSlotId", required: true)] | ||
public string LensSlotId = string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Raised directed at an entity with a lens slot when the lens is ejected/inserted. | ||
/// </summary> | ||
public sealed class LensChangedEvent : EntityEventArgs | ||
{ | ||
public readonly bool Ejected; | ||
|
||
public LensChangedEvent(bool ejected) | ||
{ | ||
Ejected = ejected; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Content.Shared.Containers.ItemSlots; | ||
using Content.Shared.Examine; | ||
using Robust.Shared.Containers; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Shared.Lens; | ||
|
||
public sealed class LensSlotSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<LensSlotComponent, ExaminedEvent>(OnExamine); | ||
|
||
SubscribeLocalEvent<LensSlotComponent, EntInsertedIntoContainerMessage>(OnLensInserted); | ||
SubscribeLocalEvent<LensSlotComponent, EntRemovedFromContainerMessage>(OnLensRemoved); | ||
} | ||
|
||
private void OnExamine(EntityUid glasses, LensSlotComponent component, ref ExaminedEvent args) | ||
{ | ||
if (!_itemSlots.TryGetSlot(glasses, component.LensSlotId, out var itemSlot)) | ||
return; | ||
|
||
var msg = new FormattedMessage(); | ||
|
||
if (itemSlot.Item == null) | ||
msg.AddMarkupOrThrow(Loc.GetString("lens-empty")); | ||
else | ||
{ | ||
var metadata = MetaData(itemSlot.Item.Value); | ||
msg.AddMarkupOrThrow(Loc.GetString("lens-filled") + " [color=white]" + metadata.EntityName + "[/color]."); | ||
} | ||
|
||
args.PushMessage(msg); | ||
} | ||
|
||
private void OnLensInserted(EntityUid glasses, LensSlotComponent component, EntInsertedIntoContainerMessage args) | ||
{ | ||
if (!component.Initialized) | ||
return; | ||
|
||
if (args.Container.ID != component.LensSlotId) | ||
return; | ||
|
||
RaiseLocalEvent(glasses, new LensChangedEvent(false)); | ||
} | ||
|
||
private void OnLensRemoved(EntityUid glasses, LensSlotComponent component, EntRemovedFromContainerMessage args) | ||
{ | ||
if (args.Container.ID != component.LensSlotId) | ||
return; | ||
|
||
RaiseLocalEvent(glasses, new LensChangedEvent(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lens-empty = Contains no special lens. | ||
lens-filled = Contains a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,4 +66,3 @@ | |
containers: | ||
item: | ||
- ThrowingKnife | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.