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:
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Content.Client.Botany.Components;
|
||||||
|
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class PlantHolderVisualsComponent : Component
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Content.Client.Botany;
|
namespace Content.Client.Botany.Components;
|
||||||
|
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class PotencyVisualsComponent : Component
|
public sealed class PotencyVisualsComponent : Component
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
using Content.Shared.Botany;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Robust.Client.GameObjects;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Utility;
|
|
||||||
|
|
||||||
namespace Content.Client.Botany
|
|
||||||
{
|
|
||||||
[UsedImplicitly]
|
|
||||||
public sealed class PlantHolderVisualizer : AppearanceVisualizer
|
|
||||||
{
|
|
||||||
public override void InitializeEntity(EntityUid entity)
|
|
||||||
{
|
|
||||||
base.InitializeEntity(entity);
|
|
||||||
|
|
||||||
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<ISpriteComponent>(entity);
|
|
||||||
|
|
||||||
sprite.LayerMapReserveBlank(PlantHolderLayers.Plant);
|
|
||||||
sprite.LayerMapReserveBlank(PlantHolderLayers.HealthLight);
|
|
||||||
sprite.LayerMapReserveBlank(PlantHolderLayers.WaterLight);
|
|
||||||
sprite.LayerMapReserveBlank(PlantHolderLayers.NutritionLight);
|
|
||||||
sprite.LayerMapReserveBlank(PlantHolderLayers.AlertLight);
|
|
||||||
sprite.LayerMapReserveBlank(PlantHolderLayers.HarvestLight);
|
|
||||||
|
|
||||||
var hydroTools = new ResourcePath("Structures/Hydroponics/overlays.rsi");
|
|
||||||
|
|
||||||
sprite.LayerSetSprite(PlantHolderLayers.HealthLight,
|
|
||||||
new SpriteSpecifier.Rsi(hydroTools, "lowhealth3"));
|
|
||||||
sprite.LayerSetSprite(PlantHolderLayers.WaterLight,
|
|
||||||
new SpriteSpecifier.Rsi(hydroTools, "lowwater3"));
|
|
||||||
sprite.LayerSetSprite(PlantHolderLayers.NutritionLight,
|
|
||||||
new SpriteSpecifier.Rsi(hydroTools, "lownutri3"));
|
|
||||||
sprite.LayerSetSprite(PlantHolderLayers.AlertLight,
|
|
||||||
new SpriteSpecifier.Rsi(hydroTools, "alert3"));
|
|
||||||
sprite.LayerSetSprite(PlantHolderLayers.HarvestLight,
|
|
||||||
new SpriteSpecifier.Rsi(hydroTools, "harvest3"));
|
|
||||||
|
|
||||||
// Let's make those invisible for now.
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.Plant, false);
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.HealthLight, false);
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.WaterLight, false);
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.NutritionLight, false);
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.AlertLight, false);
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.HarvestLight, false);
|
|
||||||
|
|
||||||
// Pretty unshaded lights!
|
|
||||||
sprite.LayerSetShader(PlantHolderLayers.HealthLight, "unshaded");
|
|
||||||
sprite.LayerSetShader(PlantHolderLayers.WaterLight, "unshaded");
|
|
||||||
sprite.LayerSetShader(PlantHolderLayers.NutritionLight, "unshaded");
|
|
||||||
sprite.LayerSetShader(PlantHolderLayers.AlertLight, "unshaded");
|
|
||||||
sprite.LayerSetShader(PlantHolderLayers.HarvestLight, "unshaded");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnChangeData(AppearanceComponent component)
|
|
||||||
{
|
|
||||||
base.OnChangeData(component);
|
|
||||||
|
|
||||||
var sprite = IoCManager.Resolve<IEntityManager>().GetComponent<ISpriteComponent>(component.Owner);
|
|
||||||
|
|
||||||
if (component.TryGetData<string>(PlantHolderVisuals.PlantRsi, out var rsi)
|
|
||||||
&& component.TryGetData<string>(PlantHolderVisuals.PlantState, out var state))
|
|
||||||
{
|
|
||||||
var valid = !string.IsNullOrWhiteSpace(state);
|
|
||||||
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.Plant, valid);
|
|
||||||
|
|
||||||
if(valid)
|
|
||||||
{
|
|
||||||
sprite.LayerSetRSI(PlantHolderLayers.Plant, rsi);
|
|
||||||
sprite.LayerSetState(PlantHolderLayers.Plant, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.TryGetData<bool>(PlantHolderVisuals.HealthLight, out var health))
|
|
||||||
{
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.HealthLight, health);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.TryGetData<bool>(PlantHolderVisuals.WaterLight, out var water))
|
|
||||||
{
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.WaterLight, water);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.TryGetData<bool>(PlantHolderVisuals.NutritionLight, out var nutrition))
|
|
||||||
{
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.NutritionLight, nutrition);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.TryGetData<bool>(PlantHolderVisuals.AlertLight, out var alert))
|
|
||||||
{
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.AlertLight, alert);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (component.TryGetData<bool>(PlantHolderVisuals.HarvestLight, out var harvest))
|
|
||||||
{
|
|
||||||
sprite.LayerSetVisible(PlantHolderLayers.HarvestLight, harvest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum PlantHolderLayers : byte
|
|
||||||
{
|
|
||||||
Plant,
|
|
||||||
HealthLight,
|
|
||||||
WaterLight,
|
|
||||||
NutritionLight,
|
|
||||||
AlertLight,
|
|
||||||
HarvestLight,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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,
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Botany;
|
using Content.Shared.Botany;
|
||||||
|
using Content.Client.Botany.Components;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
|
|
||||||
namespace Content.Client.Botany;
|
namespace Content.Client.Botany;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
|
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
|
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace Content.Server.Entry
|
|||||||
"PipeColorVisuals",
|
"PipeColorVisuals",
|
||||||
"FireVisuals",
|
"FireVisuals",
|
||||||
"CrematoriumVisuals",
|
"CrematoriumVisuals",
|
||||||
|
"PlantHolderVisuals",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,52 @@
|
|||||||
- type: Anchorable
|
- type: Anchorable
|
||||||
- type: Pullable
|
- type: Pullable
|
||||||
- type: Sprite
|
- type: Sprite
|
||||||
sprite: Structures/Hydroponics/containers.rsi
|
layers:
|
||||||
state: hydrotray3
|
- sprite: Structures/Hydroponics/containers.rsi
|
||||||
|
state: hydrotray3
|
||||||
|
- sprite: Structures/Hydroponics/overlays.rsi
|
||||||
|
state: lowhealth3
|
||||||
|
map: [ "health_alert" ]
|
||||||
|
visible: false
|
||||||
|
- sprite: Structures/Hydroponics/overlays.rsi
|
||||||
|
state: lowwater3
|
||||||
|
map: [ "water_alert" ]
|
||||||
|
visible: false
|
||||||
|
- sprite: Structures/Hydroponics/overlays.rsi
|
||||||
|
state: lownutri3
|
||||||
|
map: [ "nutri_alert" ]
|
||||||
|
visible: false
|
||||||
|
- sprite: Structures/Hydroponics/overlays.rsi
|
||||||
|
state: alert3
|
||||||
|
map: [ "undefined_alert" ]
|
||||||
|
visible: false
|
||||||
|
- sprite: Structures/Hydroponics/overlays.rsi
|
||||||
|
state: harvest3
|
||||||
|
map: [ "harvest_alert" ]
|
||||||
|
visible: false
|
||||||
|
- type: Appearance
|
||||||
|
- type: GenericVisualizer
|
||||||
|
visuals:
|
||||||
|
enum.PlantHolderVisuals.HealthLight:
|
||||||
|
health_alert:
|
||||||
|
True: { visible: true }
|
||||||
|
False: { visible: false }
|
||||||
|
enum.PlantHolderVisuals.WaterLight:
|
||||||
|
water_alert:
|
||||||
|
True: { visible: true }
|
||||||
|
False: { visible: false }
|
||||||
|
enum.PlantHolderVisuals.NutritionLight:
|
||||||
|
nutri_alert:
|
||||||
|
True: { visible: true }
|
||||||
|
False: { visible: false }
|
||||||
|
enum.PlantHolderVisuals.AlertLight:
|
||||||
|
undefined_alert:
|
||||||
|
True: { visible: true }
|
||||||
|
False: { visible: false }
|
||||||
|
enum.PlantHolderVisuals.HarvestLight:
|
||||||
|
harvest_alert:
|
||||||
|
True: { visible: true }
|
||||||
|
False: { visible: false }
|
||||||
- type: PlantHolder
|
- type: PlantHolder
|
||||||
drawWarnings: true
|
drawWarnings: true
|
||||||
- type: Construction
|
- type: Construction
|
||||||
|
|||||||
@@ -53,5 +53,4 @@
|
|||||||
- !type:AddToSolutionReaction
|
- !type:AddToSolutionReaction
|
||||||
solution: soil
|
solution: soil
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
visuals:
|
- type: PlantHolderVisuals
|
||||||
- type: PlantHolderVisualizer
|
|
||||||
|
|||||||
Reference in New Issue
Block a user