Skip to content
Draft
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
72 changes: 72 additions & 0 deletions Content.Client/_Echo/Dirt/DirtSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared._Echo.Dirt;
using Content.Shared.Clothing;
using Robust.Client.GameObjects;
using Robust.Shared.Prototypes;

namespace Content.Client._Echo.Dirt;

public sealed class DirtSystem : SharedDirtSystem
{
[Dependency] private readonly SpriteSystem _sprite = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

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

SubscribeLocalEvent<DirtVisualsComponent, AfterAutoHandleStateEvent>(OnHandleState);
SubscribeLocalEvent<DirtVisualsComponent, GetEquipmentVisualsEvent>(OnGetEquipmentVisuals);
}

private void OnHandleState(Entity<DirtVisualsComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (!_sprite.TryGetLayer(ent.Owner, DirtVisualsComponent.DirtLayer, out var layer, false))
return;

if (!TryGetDirtLayer(ent, out var dirtLayer, out var color))
{
_sprite.LayerSetVisible(ent.Owner, DirtVisualsComponent.DirtLayer, false);
return;
}

dirtLayer.Color = color;

_sprite.LayerSetData(ent.Owner, DirtVisualsComponent.DirtLayer, dirtLayer);
_sprite.LayerSetVisible(ent.Owner, DirtVisualsComponent.DirtLayer, true);
}

private void OnGetEquipmentVisuals(Entity<DirtVisualsComponent> ent, ref GetEquipmentVisualsEvent args)
{
if (!TryGetDirtLayer(ent, out var layer, out var color))
return;

layer.Color = color;
args.Layers.Add((DirtVisualsComponent.DirtLayer, layer));
}

private bool TryGetDirtLayer(Entity<DirtVisualsComponent> ent, [NotNullWhen(true)] out PrototypeLayerData? layer, [NotNullWhen(true)] out Color? color)
{
layer = null;
color = null;

if (!Solution.TryGetSolution(ent.Owner, DirtVisualsComponent.DirtSolution, out var solution))
return false;

var dirtAmount = DirtAmount.None;
foreach (var (threshold, amount) in ent.Comp.DirtThresholds)
{
if (solution.Value.Comp.Solution.Volume < amount)
continue;

dirtAmount = threshold;
}

if (dirtAmount == DirtAmount.None)
return false;

layer = ent.Comp.DirtLayers[dirtAmount];
color = solution.Value.Comp.Solution.GetColor(_proto);
return true;
}
}
7 changes: 7 additions & 0 deletions Content.Server/_Echo/Dirt/DirtSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Content.Shared._Echo.Dirt;

namespace Content.Server._Echo.Dirt;

public sealed class DirtSystem : SharedDirtSystem
{
}
5 changes: 5 additions & 0 deletions Content.Shared/Inventory/InventorySystem.Relay.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared._Echo.Dirt;
using Content.Shared.Armor;
using Content.Shared.Atmos;
using Content.Shared.Chat;
Expand Down Expand Up @@ -80,6 +81,10 @@ public void InitializeRelay()
SubscribeLocalEvent<InventoryComponent, UnwieldAttemptEvent>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, IngestionAttemptEvent>(RefRelayInventoryEvent);

// PE-Tweak-Start: Inventory relayed events
SubscribeLocalEvent<InventoryComponent, AdjustDirtEvent>(RefRelayInventoryEvent);
// PE-Tweak-End

// Eye/vision events
SubscribeLocalEvent<InventoryComponent, CanSeeAttemptEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, GetEyeProtectionEvent>(RelayInventoryEvent);
Expand Down
30 changes: 30 additions & 0 deletions Content.Shared/_Echo/Dirt/Components/DirtVisualsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Robust.Shared.GameStates;

namespace Content.Shared._Echo.Dirt;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
public sealed partial class DirtVisualsComponent : Component
{
public const string DirtSolution = "dirt";
public const string DirtLayer = "dirt";

[DataField, AutoNetworkedField]
public Dictionary<DirtAmount, float> DirtThresholds = new()
{
{ DirtAmount.None, 0f },
{ DirtAmount.Light, 5f },
{ DirtAmount.Medium, 10f },
{ DirtAmount.Heavy, 15f }
};

[DataField(required: true), AutoNetworkedField]
public Dictionary<DirtAmount, PrototypeLayerData> DirtLayers = new();
}

public enum DirtAmount : int
{
None = 0,
Light = 1,
Medium = 2,
Heavy = 3
}
10 changes: 10 additions & 0 deletions Content.Shared/_Echo/Dirt/Events/AdjustDirtEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Inventory;

namespace Content.Shared._Echo.Dirt;

[ByRefEvent]
public record struct AdjustDirtEvent(ReagentQuantity ReagentQuantity, ReagentPrototype Reagent) : IInventoryRelayEvent
{
public SlotFlags TargetSlots { get; } = SlotFlags.WITHOUT_POCKET;
}
59 changes: 59 additions & 0 deletions Content.Shared/_Echo/Dirt/SharedDirtSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Inventory;
using Content.Shared.Item;

namespace Content.Shared._Echo.Dirt;

public abstract class SharedDirtSystem : EntitySystem
{
[Dependency] protected readonly SharedSolutionContainerSystem Solution = default!;
[Dependency] private readonly SharedItemSystem _item = default!;

private const float DirtPerUnit = 0.6f;

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

SubscribeLocalEvent<DirtVisualsComponent, ReactionEntityEvent>(OnReactionEntity);
SubscribeLocalEvent<DirtVisualsComponent, AdjustDirtEvent>(OnAdjustDirt);
SubscribeLocalEvent<DirtVisualsComponent, InventoryRelayedEvent<AdjustDirtEvent>>(OnAdjustDirt);
}

private void OnReactionEntity(Entity<DirtVisualsComponent> ent, ref ReactionEntityEvent args)
{
if (args.Method != ReactionMethod.Touch)
return;

var ev = new AdjustDirtEvent(args.ReagentQuantity, args.Reagent);
RaiseLocalEvent(ent.Owner, ref ev);
}

private void OnAdjustDirt(Entity<DirtVisualsComponent> ent, ref AdjustDirtEvent args)
{
if (args.ReagentQuantity.Quantity <= 0)
return;

if (!Solution.TryGetSolution(ent.Owner, DirtVisualsComponent.DirtSolution, out var solution))
return;

var dirtAmount = args.ReagentQuantity.Quantity * DirtPerUnit;
Solution.TryAddReagent(solution.Value, new ReagentQuantity(args.ReagentQuantity.Reagent, dirtAmount), out _);
_item.VisualsChanged(ent.Owner);
}

private void OnAdjustDirt(Entity<DirtVisualsComponent> ent, ref InventoryRelayedEvent<AdjustDirtEvent> args)
{
if (args.Args.ReagentQuantity.Quantity <= 0)
return;

if (!Solution.TryGetSolution(ent.Owner, DirtVisualsComponent.DirtSolution, out var solution))
return;

var dirtAmount = args.Args.ReagentQuantity.Quantity * DirtPerUnit;
Solution.TryAddReagent(solution.Value, new ReagentQuantity(args.Args.ReagentQuantity.Reagent, dirtAmount), out _);
_item.VisualsChanged(ent.Owner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
reagents:
- ReagentId: Fiber
Quantity: 30
dirt:
maxVol: 30
reagents: []
- type: Tag
tags:
- ClothMade
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
- state: icon
color: "#b3b3b3"
- state: trinkets-icon
- map: ["dirt"]
sprite: _ECHO/Clothing/dirt.rsi
visible: false
- type: Item
inhandVisuals:
left:
Expand All @@ -55,6 +58,34 @@
- state: equipped-INNERCLOTHING
color: "#b3b3b3"
- state: trinkets-equipped-INNERCLOTHING
- type: DirtVisuals
dirtLayers:
None:
sprite: ECHO/Clothing/dirt.rsi
state: jumpsuit
visible: false
Light:
sprite: ECHO/Clothing/dirt.rsi
state: jumpsuit
visible: true
Medium:
sprite: ECHO/Clothing/dirt.rsi
state: jumpsuit
visible: true
Heavy:
sprite: ECHO/Clothing/dirt.rsi
state: jumpsuit
visible: true
dirtThresholds:
None: 0
Light: 5
Medium: 10
Heavy: 15
- type: SolutionContainerManager
reagents: []
solutions:
dirt:
maxVol: 30

# Black Jumpsuit
- type: entity
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Resources/Textures/_ECHO/Clothing/dirt.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "da",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "jumpsuit",
"directions": 4
}
]
}
Loading