CatStation/Content.Client/Botany/PlantTrayVisualizerSystem.cs
Pok 6f6a5694c8
Botany refactor (#44576)
* Restarting files from scratch

* reduce file count, more progress

* Additional partial work

* update 1

* update 2

* TODO execution

* fix

* Update PlantGrowthComponent.cs

* fix 1

* growth correction

* PlantGrowthComponent

* update 99

* last update

* oops

* Update vegan-meatball.yml

* Data loss

* ToxinsComponent

* Default components

* minor fix

* PlantTraitsComponent

* fix error

* fix error 2

* Copy growth components

* last update within this PR

* AutoHarvestGrowth remote

* Viable

* fix

* Fix growth rate

* Improvements to the YAML

* merge update

* fix

* code cleanup

* TODO

* fix

* oops

* oops 2

* more TODO

* fix names

* fix names oops

* Harvest bug fixes

* fix tests

* refactor: cleanup after mering master

* Update ConsumeExudeGasGrowthSystem.cs

* refactor: make this piece of happiness and ponies work

* review

* oops

* fix <summary>

* Separation of plant components into PlantComponent and PlantTraitsComponent and cleaning

* EnsureUniqueSeed

* refactor: change Resolve to TryComp where appropriate

* refactor: review comments - try get for components, clenaups

* refactor: minor yaml cleanups

* fixing trifles

* botany-rework-part-3

* API and mutations

* minor fixes

* Update WeedPestGrowthSystem.cs

* Update plants.yml

* PlantChemicals

* YAMLLinter

* review and some lost code

* YAMLLinter part 2

* plants.yml

* Aaaa tests

* seedId

* clone plant component

* Update clone.yml

* refactor: remove suppress possible null reference exception

* refactor: changed HasPlantAlive to TryGetAlivePlant, minor cleanup

* Separation of tray and plant

* oops

* PlantingPlant

* a little more cleaning

* oops 2

* botany-rework-part-4

* predict and API

* Field OldAgeDamage

* oops

* YMAL

* YMAL 2

* YMAAAAAL

* Update PlantToxinsSystem.cs

* review

* Update randomMutations.yml

* minor fix design

* Updates the plants visuals not every frame

* bug fixes

* some fixes

* bugfix and renames

* Dirty

* Replace ComponentRegistry

* unnecessary API

* fix merge

* build

* build 2

* Review by AJCM

* del PlantDataComponent and fix harvest

* fix all

* final review

* Update PlantTrayVisualizerSystem.cs

* fix merge

* Update PlantTraitsComponent.cs

* Traits LocId fix

* Update SpawnEntitiesBehavior.cs

* aaaaaaaaa

* fix all part 2

* PlantDataComponent revert

* aoao

* fix all part 3

* Update PlantTraitsComponent.cs

* Update clone.yml

* Reviews

---------

Co-authored-by: PraxisMapper <praxismapper@gmail.com>
Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
2026-08-08 21:58:01 +00:00

86 lines
3 KiB
C#

using Content.Client.Botany.Components;
using Content.Shared.Botany;
using Content.Shared.Botany.Components;
using Content.Shared.Botany.Systems;
using Robust.Client.GameObjects;
namespace Content.Client.Botany;
public sealed partial class PlantTrayVisualizerSystem : VisualizerSystem<PlantTrayVisualsComponent>
{
[Dependency] private PlantTraySystem _plantTray = default!;
[Dependency] private PlantHolderSystem _plantHolder = default!;
/// <summary>
/// Defers appearance writes until after network state application and deduplicates multiple state events per frame.
/// </summary>
private readonly HashSet<EntityUid> _pendingTrayUpdates = [];
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var uid in _pendingTrayUpdates)
{
UpdateTrayWarnings(uid);
}
_pendingTrayUpdates.Clear();
}
[SubscribeLocalEvent]
private void OnComponentStartup(Entity<PlantTrayVisualsComponent> ent, ref ComponentStartup args)
{
QueueTrayWarnings(ent.Owner);
}
[SubscribeLocalEvent]
private void OnPlantTrayState(Entity<PlantTrayComponent> ent, ref AfterAutoHandleStateEvent args)
{
QueueTrayWarnings(ent.Owner);
}
private void QueueTrayWarnings(EntityUid uid)
{
_pendingTrayUpdates.Add(uid);
}
public void UpdateTrayWarnings(Entity<PlantTrayComponent?> ent)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
if (!ent.Comp.DrawWarnings)
return;
var water = _plantTray.GetWaterThreshold(ent.AsNullable());
var nutrition = _plantTray.GetNutrientThreshold(ent.AsNullable());
var alert = _plantTray.GetWeedThreshold(ent.AsNullable())
|| _plantTray.GetToxinThreshold(ent.AsNullable())
|| _plantTray.GetPestThreshold(ent.AsNullable());
var health = false;
var harvest = false;
if (_plantTray.TryGetPlant(ent.AsNullable(), out var plantUid))
{
if (TryComp<PlantHolderComponent>(plantUid, out var plantHolder))
{
alert |= plantHolder.ImproperHeat
|| plantHolder.ImproperPressure
|| plantHolder.MissingGas;
health = _plantHolder.GetHealthThreshold(plantUid.Value);
}
if (TryComp<PlantHarvestComponent>(plantUid, out var plantHarvest))
harvest = plantHarvest.ReadyForHarvest;
}
// These are appearance keys consumed by the prototype's <see cref="GenericVisualizerComponent"/>.
AppearanceSystem.SetData(ent.Owner, PlantTrayVisuals.HealthLight, health);
AppearanceSystem.SetData(ent.Owner, PlantTrayVisuals.WaterLight, water);
AppearanceSystem.SetData(ent.Owner, PlantTrayVisuals.NutritionLight, nutrition);
AppearanceSystem.SetData(ent.Owner, PlantTrayVisuals.AlertLight, alert);
AppearanceSystem.SetData(ent.Owner, PlantTrayVisuals.HarvestLight, harvest);
}
}