Adds trash tag to more items. New component "TrashOnEmpty" (#10166)

This commit is contained in:
Jessica M 2022-08-04 01:52:08 -07:00 committed by GitHub
parent 2f4849eae1
commit 39a6c8afb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 97 additions and 6 deletions

View File

@ -0,0 +1,16 @@
namespace Content.Server.Nutrition.Components
{
/// <summary>
/// Component that tags solution containers as trash when their contents have been emptied.
/// Used for things like used ketchup packets or used syringes.
/// </summary>
[RegisterComponent]
public sealed class TrashOnEmptyComponent : Component
{
/// <summary>
/// The name of the solution of which to check emptiness
/// </summary>
[ViewVariables] [DataField("solution")]
public string Solution { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,53 @@
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Nutrition.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Tag;
namespace Content.Server.Nutrition.EntitySystems
{
public sealed class TrashOnEmptySystem : EntitySystem
{
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<TrashOnEmptyComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<TrashOnEmptyComponent, SolutionChangedEvent>(OnSolutionChange);
}
public void OnStartup(EntityUid uid, TrashOnEmptyComponent component, ComponentStartup args)
{
CheckSolutions(component);
}
public void OnSolutionChange(EntityUid uid, TrashOnEmptyComponent component, SolutionChangedEvent args)
{
CheckSolutions(component);
}
public void CheckSolutions(TrashOnEmptyComponent component)
{
EntityManager.EnsureComponent<TagComponent>(component.Owner);
if (!EntityManager.HasComponent<SolutionContainerManagerComponent>((component).Owner))
return;
if (_solutionContainerSystem.TryGetSolution(component.Owner, component.Solution, out var solution))
UpdateTags(component, solution);
}
public void UpdateTags(TrashOnEmptyComponent component, Solution solution)
{
if (solution.DrainAvailable <= 0)
{
_tagSystem.AddTag(component.Owner, "Trash");
return;
}
if (_tagSystem.HasTag(component.Owner, "Trash"))
_tagSystem.RemoveTag(component.Owner, "Trash");
}
}
}

View File

@ -34,12 +34,11 @@
- type: DrinkCanVisualizer
stateClosed: icon
stateOpen: icon_open
- type: Tag
tags:
- Trash
- type: ItemCooldown
- type: Recyclable
- type: SpaceGarbage
- type: TrashOnEmpty
solution: drink
- type: entity
parent: DrinkCanBaseFull

View File

@ -174,6 +174,8 @@
maxVol: 20
- type: Sprite
sprite: Objects/Consumable/Drinks/hot_coffee.rsi
- type: TrashOnEmpty
solution: drink
- type: entity
parent: DrinkBaseCup
@ -191,6 +193,8 @@
- type: Sprite
sprite: Objects/Consumable/Drinks/teacup.rsi
state: icon-1
- type: TrashOnEmpty
solution: drink
- type: entity
parent: DrinkBaseCup
@ -210,6 +214,8 @@
state: icon
- type: Item
sprite: Objects/Consumable/Drinks/lean.rsi
- type: TrashOnEmpty
solution: drink
- type: entity
parent: DrinkBaseCup
@ -228,3 +234,5 @@
- type: Sprite
sprite: Objects/Consumable/Drinks/water_cup.rsi
state: icon-1
- type: TrashOnEmpty
solution: drink

View File

@ -33,6 +33,8 @@
- type: Icon
sprite: Objects/Consumable/Food/condiments.rsi
state: packet-empty
- type: TrashOnEmpty
solution: food
- type: entity
parent: FoodCondimentPacket
@ -357,6 +359,8 @@
- type: SolutionContainerVisualizer
maxFillLevels: 6
fillBaseName: bottle-alpha-
- type: TrashOnEmpty
solution: food
- type: entity
parent: FoodCondimentBottle
@ -501,6 +505,8 @@
- type: SolutionContainerVisualizer
maxFillLevels: 3
fillBaseName: bottle-s-alpha-
- type: TrashOnEmpty
solution: food
- type: entity
parent: FoodCondimentBottleSmall

View File

@ -43,7 +43,9 @@
sprite: Objects/Consumable/Food/snacks.rsi
heldPrefix: packet
size: 3
- type: Tag
tags:
- Trash
# Tins
# Need something that you can open these tins with. I suggest a prying or cutting tool.

View File

@ -489,6 +489,9 @@
netsync: false
- type: Item
size: 1
- type: Tag
tags:
- Trash
- type: entity
name: onion

View File

@ -40,6 +40,8 @@
sprite: Objects/Specific/Chemistry/beaker.rsi
- type: Spillable
solution: drink
- type: TrashOnEmpty
solution: drink
- type: entity
name: bottle
@ -161,7 +163,7 @@
components:
- type: SolutionContainerManager
solutions:
drink:
drink:
maxVol: 30
reagents:
- ReagentId: Ephedrine
@ -174,7 +176,7 @@
components:
- type: SolutionContainerManager
solutions:
drink:
drink:
maxVol: 30
reagents:
- ReagentId: Omnizine

View File

@ -235,6 +235,8 @@
injectOnly: false
- type: Spillable
solution: injector
- type: TrashOnEmpty
solution: injector
- type: Appearance
visuals:
# this visualizer used for reagent inside