PlantHolderVisualizer component system refactor (#10091)
* Converted PlantHolderVisualizer to component and system. * Cleaned up Botany folder. * Converted initialization of HydroTrayVisualizer under PlantHolderVisualizerSystem to it's own GenericVisualizer. * Cleaned up hydro_tray.yml.
This commit is contained in:
54
Content.Client/Botany/PlantHolderVisualizerSystem.cs
Normal file
54
Content.Client/Botany/PlantHolderVisualizerSystem.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Content.Client.Botany.Components;
|
||||
using Content.Shared.Botany;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Botany;
|
||||
|
||||
public sealed class PlantHolderVisualizerSystem : VisualizerSystem<PlantHolderVisualsComponent>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PlantHolderVisualsComponent, ComponentInit>(OnComponentInit);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, PlantHolderVisualsComponent component, ComponentInit args)
|
||||
{
|
||||
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
||||
return;
|
||||
|
||||
sprite.LayerMapReserveBlank(PlantHolderLayers.Plant);
|
||||
sprite.LayerSetVisible(PlantHolderLayers.Plant, false);
|
||||
}
|
||||
|
||||
protected override void OnAppearanceChange(EntityUid uid, PlantHolderVisualsComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
if (args.Component.TryGetData<string>(PlantHolderVisuals.PlantRsi, out var rsi)
|
||||
&& args.Component.TryGetData<string>(PlantHolderVisuals.PlantState, out var state))
|
||||
{
|
||||
var valid = !string.IsNullOrWhiteSpace(state);
|
||||
|
||||
args.Sprite.LayerSetVisible(PlantHolderLayers.Plant, valid);
|
||||
|
||||
if (valid)
|
||||
{
|
||||
args.Sprite.LayerSetRSI(PlantHolderLayers.Plant, rsi);
|
||||
args.Sprite.LayerSetState(PlantHolderLayers.Plant, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlantHolderLayers : byte
|
||||
{
|
||||
Plant,
|
||||
HealthLight,
|
||||
WaterLight,
|
||||
NutritionLight,
|
||||
AlertLight,
|
||||
HarvestLight,
|
||||
}
|
||||
Reference in New Issue
Block a user