Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slotable lenses #304

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion Content.Shared/Eye/Blinding/Systems/BlurryVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Lens;

namespace Content.Shared.Eye.Blinding.Systems;

public sealed class BlurryVisionSystem : EntitySystem
{

[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;

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

SubscribeLocalEvent<VisionCorrectionComponent, GotEquippedEvent>(OnGlassesEquipped);
SubscribeLocalEvent<VisionCorrectionComponent, GotUnequippedEvent>(OnGlassesUnequipped);
SubscribeLocalEvent<VisionCorrectionComponent, InventoryRelayedEvent<GetBlurEvent>>(OnGetBlur);

SubscribeLocalEvent<LensSlotComponent, GotEquippedEvent>(OnLensEquipped);
SubscribeLocalEvent<LensSlotComponent, GotUnequippedEvent>(OnLensUnequipped);
SubscribeLocalEvent<LensSlotComponent, LensChangedEvent>(OnLensChanged);
SubscribeLocalEvent<LensSlotComponent, InventoryRelayedEvent<GetBlurEvent>>(OnGetBlurLens);
}

private void OnGetBlur(Entity<VisionCorrectionComponent> glasses, ref InventoryRelayedEvent<GetBlurEvent> args)
Expand All @@ -21,6 +31,18 @@ private void OnGetBlur(Entity<VisionCorrectionComponent> glasses, ref InventoryR
args.Args.CorrectionPower *= glasses.Comp.CorrectionPower;
}

private void OnGetBlurLens(Entity<LensSlotComponent> glasses, ref InventoryRelayedEvent<GetBlurEvent> args)
{
if (!_itemSlots.TryGetSlot(glasses.Owner, glasses.Comp.LensSlotId, out var itemSlot))
return;

if (!TryComp<VisionCorrectionComponent>(itemSlot.Item, out var component))
return;

args.Args.Blur += component.VisionBonus;
args.Args.CorrectionPower *= component.CorrectionPower;
}

public void UpdateBlurMagnitude(Entity<BlindableComponent?> ent)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
Expand Down Expand Up @@ -51,6 +73,21 @@ private void OnGlassesUnequipped(Entity<VisionCorrectionComponent> glasses, ref
{
UpdateBlurMagnitude(args.Equipee);
}

private void OnLensEquipped(Entity<LensSlotComponent> glasses, ref GotEquippedEvent args)
{
UpdateBlurMagnitude(args.Equipee);
}

private void OnLensUnequipped(Entity<LensSlotComponent> glasses, ref GotUnequippedEvent args)
{
UpdateBlurMagnitude(args.Equipee);
}

private void OnLensChanged(Entity<LensSlotComponent> glasses, ref LensChangedEvent args)
{
UpdateBlurMagnitude(Transform(glasses.Owner).ParentUid);
}
}

public sealed class GetBlurEvent : EntityEventArgs, IInventoryRelayEvent
Expand Down
27 changes: 27 additions & 0 deletions Content.Shared/Lens/LensSlotComponent.cs
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;
}
}
59 changes: 59 additions & 0 deletions Content.Shared/Lens/LensSlotSystem.cs
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));
}
}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/lens/lens.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lens-empty = Contains no special lens.
lens-filled = Contains a
1 change: 0 additions & 1 deletion Resources/Prototypes/Catalog/Fills/Items/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@
containers:
item:
- ThrowingKnife

49 changes: 36 additions & 13 deletions Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
Blunt: 10

- type: entity
parent: [ClothingEyesBase, BaseEngineeringContraband]
parent: [ClothingEyesBase, BaseLensSlot, BaseEngineeringContraband]
id: ClothingEyesGlassesMeson
name: engineering goggles #less confusion
description: Green-tinted goggles using a proprietary polymer that provides protection from eye damage of all types.
Expand All @@ -67,23 +67,46 @@
coverage: EYES

- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesGlasses
name: glasses
description: A pair of spectacular spectacles with prescription lenses.
description: A pair of spectacular spectacles with removable prescription lenses.
components:
- type: Sprite
sprite: Clothing/Eyes/Glasses/glasses.rsi
- type: Clothing
sprite: Clothing/Eyes/Glasses/glasses.rsi
- type: VisionCorrection
- type: ItemSlots
slots:
lens_slot:
startingItem: PrescriptionLens
whitelist:
tags:
- Lens
- type: Tag
tags:
- HamsterWearable
- WhitelistChameleon

# Given to near-sighted trait
- type: entity
parent: ClothingEyesBase
parent: ClothingEyesGlasses
id: ClothingEyesGlassesStrong
suffix: Strong
components:
- type: ItemSlots
slots:
lens_slot:
startingItem: PrescriptionLensStrong
whitelist:
tags:
- Lens
- type: Tag
tags:
- HamsterWearable

- type: entity
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesGlassesJensen
name: jensen glasses
description: A pair of yellow tinted folding glasses. You never asked for these.
Expand All @@ -107,13 +130,14 @@
- type: Clothing
sprite: Clothing/Eyes/Glasses/jamjar.rsi
- type: VisionCorrection
correctionPower: 4 # Jam Jars fix your eyes better
- type: Tag
tags:
- HamsterWearable
- WhitelistChameleon

- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesGlassesOutlawGlasses
name: outlaw glasses
description: A must for every self-respecting undercover agent.
Expand All @@ -122,7 +146,6 @@
sprite: Clothing/Eyes/Glasses/outlawglasses.rsi
- type: Clothing
sprite: Clothing/Eyes/Glasses/outlawglasses.rsi
- type: VisionCorrection
- type: IdentityBlocker

- type: entity
Expand Down Expand Up @@ -158,7 +181,7 @@
- WhitelistChameleon

- type: entity
parent: [ClothingEyesBase, ShowSecurityIcons, BaseRestrictedContraband]
parent: [ClothingEyesBase, BaseLensSlot, ShowSecurityIcons, BaseRestrictedContraband]
id: ClothingEyesGlassesSecurity
name: security glasses
description: Upgraded sunglasses that provide flash immunity and a security HUD.
Expand All @@ -185,10 +208,10 @@
coverage: EYES

- type: entity
parent: [ClothingEyesBase, BaseCommandContraband]
parent: [ClothingEyesBase, BaseLensSlot, BaseCommandContraband]
id: ClothingEyesGlassesCommand
name: administration glasses
description: Upgraded sunglasses that provide flash immunity and show ID card status.
description: Upgraded sunglasses that provide flash immunity and show ID card status.
components:
- type: Sprite
sprite: Clothing/Eyes/Glasses/commandglasses.rsi
Expand All @@ -206,7 +229,7 @@
- type: ShowJobIcons

- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesGlassesMercenary
name: mercenary glasses
description: Glasses made for combat, to protect the eyes from bright blinding flashes.
Expand All @@ -223,7 +246,7 @@

#Make a scanner category when these actually function and we get the trayson
- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesGlassesThermal
name: optical thermal scanner
description: Thermals in the shape of glasses.
Expand All @@ -241,7 +264,7 @@
coverage: EYES

- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesGlassesChemical
name: chemical analysis goggles
description: Goggles that can scan the chemical composition of a solution.
Expand Down
16 changes: 8 additions & 8 deletions Resources/Prototypes/Entities/Clothing/Eyes/hud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- Biological

- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesHudDiagnostic
name: diagnostic hud
description: A heads-up display capable of analyzing the integrity and status of robotics and exosuits. Made out of see-borg-ium.
Expand All @@ -35,7 +35,7 @@
- Silicon

- type: entity
parent: [ClothingEyesBase, ShowMedicalIcons]
parent: [ClothingEyesBase, BaseLensSlot, ShowMedicalIcons]
id: ClothingEyesHudMedical
name: medical hud
description: A heads-up display that scans the humanoids in view and provides accurate data about their health status.
Expand All @@ -49,7 +49,7 @@
- HudMedical

- type: entity
parent: [ClothingEyesBase, ShowSecurityIcons, BaseRestrictedContraband]
parent: [ClothingEyesBase, BaseLensSlot, ShowSecurityIcons, BaseRestrictedContraband]
id: ClothingEyesHudSecurity
name: security hud
description: A heads-up display that scans the humanoids in view and provides accurate data about their ID status and security records.
Expand All @@ -63,7 +63,7 @@
- HudSecurity

- type: entity
parent: [ClothingEyesBase, BaseCommandContraband]
parent: [ClothingEyesBase, BaseLensSlot, BaseCommandContraband]
id: ClothingEyesHudCommand
name: administration hud
description: A heads-up display that scans the humanoids in view and provides accurate data about their ID status.
Expand All @@ -75,7 +75,7 @@
- type: ShowJobIcons

- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesHudBeer
name: beer goggles
description: A pair of sunHud outfitted with apparatus to scan reagents, as well as providing an innate understanding of liquid viscosity while in motion.
Expand Down Expand Up @@ -152,7 +152,7 @@
- type: ShowThirstIcons

- type: entity
parent: [ClothingEyesBase, ShowSecurityIcons, ShowMedicalIcons, BaseSecurityCommandContraband]
parent: [ClothingEyesBase, BaseLensSlot, ShowSecurityIcons, ShowMedicalIcons, BaseSecurityCommandContraband]
id: ClothingEyesHudMedSec
name: medsec hud
description: An eye display that looks like a mixture of medical and security huds.
Expand All @@ -166,7 +166,7 @@
node: medsecHud

- type: entity
parent: [ClothingEyesBase, ShowSecurityIcons, ShowMedicalIcons]
parent: [ClothingEyesBase, BaseLensSlot, ShowSecurityIcons, ShowMedicalIcons]
id: ClothingEyesHudMultiversal
name: multiversal hud
description: Filler
Expand All @@ -182,7 +182,7 @@
- type: ShowSyndicateIcons

- type: entity
parent: [ClothingEyesBase, ShowSecurityIcons, ShowMedicalIcons]
parent: [ClothingEyesBase, BaseLensSlot, ShowSecurityIcons, ShowMedicalIcons]
id: ClothingEyesHudOmni
name: omni hud
description: Filler
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/Entities/Clothing/Eyes/specific.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- type: entity
parent: ClothingEyesBase
parent: [ClothingEyesBase, BaseLensSlot]
id: ClothingEyesChameleon # no flash immunity, sorry
name: sun glasses
description: Useful both for security and cargonia.
Expand Down
14 changes: 14 additions & 0 deletions Resources/Prototypes/Entities/Clothing/base_clothing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@
- type: ItemToggle
onUse: false # can't really wear it like that
- type: ToggleClothing

# for clothing that updates functionality from items inside it
- type: entity
abstract: true
id: BaseLensSlot
components:
- type: LensSlot
LensSlotId: lens_slot
- type: ItemSlots
slots:
lens_slot:
whitelist:
tags:
- Lens
Loading
Loading