Add support for metamorphic fill levels (#25022)

* Added support for fill levels to metamorphic glasses

* Fix warnings and cleanup

* Don't break non-metamorphic fills!
This commit is contained in:
Tayrtahn
2024-02-19 16:29:42 -05:00
committed by GitHub
parent 706b0725a6
commit e74f3019f7
2 changed files with 45 additions and 13 deletions

View File

@@ -49,12 +49,17 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
if (!args.Sprite.LayerMapTryGet(component.Layer, out var fillLayer)) if (!args.Sprite.LayerMapTryGet(component.Layer, out var fillLayer))
return; return;
var maxFillLevels = component.MaxFillLevels;
var fillBaseName = component.FillBaseName;
var changeColor = component.ChangeColor;
var fillSprite = component.MetamorphicDefaultSprite;
// Currently some solution methods such as overflowing will try to update appearance with a // Currently some solution methods such as overflowing will try to update appearance with a
// volume greater than the max volume. We'll clamp it so players don't see // volume greater than the max volume. We'll clamp it so players don't see
// a giant error sign and error for debug. // a giant error sign and error for debug.
if (fraction > 1f) if (fraction > 1f)
{ {
Logger.Error("Attempted to set solution container visuals volume ratio on " + ToPrettyString(uid) + " to a value greater than 1. Volume should never be greater than max volume!"); Log.Error("Attempted to set solution container visuals volume ratio on " + ToPrettyString(uid) + " to a value greater than 1. Volume should never be greater than max volume!");
fraction = 1f; fraction = 1f;
} }
if (component.Metamorphic) if (component.Metamorphic)
@@ -72,13 +77,23 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
if (reagentProto?.MetamorphicSprite is { } sprite) if (reagentProto?.MetamorphicSprite is { } sprite)
{ {
args.Sprite.LayerSetSprite(baseLayer, sprite); args.Sprite.LayerSetSprite(baseLayer, sprite);
if (reagentProto.MetamorphicMaxFillLevels > 0)
{
args.Sprite.LayerSetVisible(fillLayer, true);
maxFillLevels = reagentProto.MetamorphicMaxFillLevels;
fillBaseName = reagentProto.MetamorphicFillBaseName;
changeColor = reagentProto.MetamorphicChangeColor;
fillSprite = sprite;
}
else
args.Sprite.LayerSetVisible(fillLayer, false); args.Sprite.LayerSetVisible(fillLayer, false);
if (hasOverlay) if (hasOverlay)
args.Sprite.LayerSetVisible(overlayLayer, false); args.Sprite.LayerSetVisible(overlayLayer, false);
return;
} }
else else
{ {
args.Sprite.LayerSetVisible(fillLayer, true);
if (hasOverlay) if (hasOverlay)
args.Sprite.LayerSetVisible(overlayLayer, true); args.Sprite.LayerSetVisible(overlayLayer, true);
if (component.MetamorphicDefaultSprite != null) if (component.MetamorphicDefaultSprite != null)
@@ -87,21 +102,27 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
} }
} }
} }
else
{
args.Sprite.LayerSetVisible(fillLayer, true);
}
int closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, component.MaxFillLevels + 1); var closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, maxFillLevels + 1);
if (closestFillSprite > 0) if (closestFillSprite > 0)
{ {
if (component.FillBaseName == null) if (fillBaseName == null)
return; return;
args.Sprite.LayerSetVisible(fillLayer, true); var stateName = fillBaseName + closestFillSprite;
if (fillSprite != null)
var stateName = component.FillBaseName + closestFillSprite; args.Sprite.LayerSetSprite(fillLayer, fillSprite);
args.Sprite.LayerSetState(fillLayer, stateName); args.Sprite.LayerSetState(fillLayer, stateName);
if (component.ChangeColor && AppearanceSystem.TryGetData<Color>(uid, SolutionContainerVisuals.Color, out var color, args.Component)) if (changeColor && AppearanceSystem.TryGetData<Color>(uid, SolutionContainerVisuals.Color, out var color, args.Component))
args.Sprite.LayerSetColor(fillLayer, color); args.Sprite.LayerSetColor(fillLayer, color);
else
args.Sprite.LayerSetColor(fillLayer, Color.White);
} }
else else
{ {
@@ -110,8 +131,10 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
else else
{ {
args.Sprite.LayerSetState(fillLayer, component.EmptySpriteName); args.Sprite.LayerSetState(fillLayer, component.EmptySpriteName);
if (component.ChangeColor) if (changeColor)
args.Sprite.LayerSetColor(fillLayer, component.EmptySpriteColor); args.Sprite.LayerSetColor(fillLayer, component.EmptySpriteColor);
else
args.Sprite.LayerSetColor(fillLayer, Color.White);
} }
} }
@@ -130,7 +153,7 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
if (!AppearanceSystem.TryGetData<float>(uid, SolutionContainerVisuals.FillFraction, out var fraction, appearance)) if (!AppearanceSystem.TryGetData<float>(uid, SolutionContainerVisuals.FillFraction, out var fraction, appearance))
return; return;
int closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, component.InHandsMaxFillLevels + 1); var closestFillSprite = ContentHelpers.RoundToLevels(fraction, 1, component.InHandsMaxFillLevels + 1);
if (closestFillSprite > 0) if (closestFillSprite > 0)
{ {

View File

@@ -89,6 +89,15 @@ namespace Content.Shared.Chemistry.Reagent
[DataField] [DataField]
public SpriteSpecifier? MetamorphicSprite { get; private set; } = null; public SpriteSpecifier? MetamorphicSprite { get; private set; } = null;
[DataField]
public int MetamorphicMaxFillLevels { get; private set; } = 0;
[DataField]
public string? MetamorphicFillBaseName { get; private set; } = null;
[DataField]
public bool MetamorphicChangeColor { get; private set; } = true;
/// <summary> /// <summary>
/// If this reagent is part of a puddle is it slippery. /// If this reagent is part of a puddle is it slippery.
/// </summary> /// </summary>
@@ -163,7 +172,7 @@ namespace Content.Shared.Chemistry.Reagent
if (plantMetabolizable.ShouldLog) if (plantMetabolizable.ShouldLog)
{ {
var entity = args.SolutionEntity; var entity = args.SolutionEntity;
EntitySystem.Get<SharedAdminLogSystem>().Add(LogType.ReagentEffect, plantMetabolizable.LogImpact, entMan.System<SharedAdminLogSystem>().Add(LogType.ReagentEffect, plantMetabolizable.LogImpact,
$"Plant metabolism effect {plantMetabolizable.GetType().Name:effect} of reagent {ID:reagent} applied on entity {entMan.ToPrettyString(entity):entity} at {entMan.GetComponent<TransformComponent>(entity).Coordinates:coordinates}"); $"Plant metabolism effect {plantMetabolizable.GetType().Name:effect} of reagent {ID:reagent} applied on entity {entMan.ToPrettyString(entity):entity} at {entMan.GetComponent<TransformComponent>(entity).Coordinates:coordinates}");
} }