Fix solution visuals (#13456)
This commit is contained in:
@@ -5,9 +5,11 @@ namespace Content.Client.Chemistry.Visualizers;
|
||||
|
||||
public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionContainerVisualsComponent>
|
||||
{
|
||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||
|
||||
protected override void OnAppearanceChange(EntityUid uid, SolutionContainerVisualsComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (!args.Component.TryGetData(SolutionContainerVisuals.VisualState, out SolutionContainerVisualState state))
|
||||
if (!_appearance.TryGetData(uid, SolutionContainerVisuals.FillFraction, out float fraction, args.Component))
|
||||
return;
|
||||
|
||||
if (args.Sprite == null)
|
||||
@@ -16,8 +18,7 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
|
||||
if (!args.Sprite.LayerMapTryGet(component.Layer, out var fillLayer))
|
||||
return;
|
||||
|
||||
var fillPercent = state.FilledVolumePercent;
|
||||
var closestFillSprite = (int) Math.Round(fillPercent * component.MaxFillLevels);
|
||||
var closestFillSprite = (int) Math.Round(fraction * component.MaxFillLevels);
|
||||
|
||||
if (closestFillSprite > 0)
|
||||
{
|
||||
@@ -29,8 +30,8 @@ public sealed class SolutionContainerVisualsSystem : VisualizerSystem<SolutionCo
|
||||
var stateName = component.FillBaseName + closestFillSprite;
|
||||
args.Sprite.LayerSetState(fillLayer, stateName);
|
||||
|
||||
if (component.ChangeColor)
|
||||
args.Sprite.LayerSetColor(fillLayer, state.Color);
|
||||
if (component.ChangeColor && _appearance.TryGetData(uid, SolutionContainerVisuals.Color, out Color color, args.Component))
|
||||
args.Sprite.LayerSetColor(fillLayer, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -35,6 +35,8 @@ public sealed partial class SolutionContainerSystem : EntitySystem
|
||||
[Dependency]
|
||||
private readonly SharedChemicalReactionSystem _chemistrySystem = default!;
|
||||
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
[Dependency]
|
||||
private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
@@ -98,9 +100,8 @@ public sealed partial class SolutionContainerSystem : EntitySystem
|
||||
|| !Resolve(uid, ref appearanceComponent, false))
|
||||
return;
|
||||
|
||||
var filledVolumePercent = solution.FillFraction * 100;
|
||||
appearanceComponent.SetData(SolutionContainerVisuals.VisualState,
|
||||
new SolutionContainerVisualState(solution.GetColor(_prototypeManager), filledVolumePercent));
|
||||
_appearance.SetData(uid, SolutionContainerVisuals.FillFraction, solution.FillFraction, appearanceComponent);
|
||||
_appearance.SetData(uid, SolutionContainerVisuals.Color, solution.GetColor(_prototypeManager), appearanceComponent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,39 +5,8 @@ namespace Content.Shared.Chemistry
|
||||
[Serializable, NetSerializable]
|
||||
public enum SolutionContainerVisuals : byte
|
||||
{
|
||||
VisualState
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class SolutionContainerVisualState : ICloneable
|
||||
{
|
||||
public readonly Color Color;
|
||||
|
||||
public readonly byte FilledVolumeFraction;
|
||||
|
||||
// do we really need this just to save three bytes?
|
||||
// This does seem silly
|
||||
public float FilledVolumePercent => (float) FilledVolumeFraction / byte.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the solution state of a container.
|
||||
/// </summary>
|
||||
public SolutionContainerVisualState(Color color, float filledVolumePercent)
|
||||
{
|
||||
Color = color;
|
||||
FilledVolumeFraction = (byte) (byte.MaxValue * filledVolumePercent);
|
||||
}
|
||||
|
||||
public SolutionContainerVisualState(Color color, byte filledVolumeFraction)
|
||||
{
|
||||
Color = color;
|
||||
FilledVolumeFraction = filledVolumeFraction;
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new SolutionContainerVisualState(Color, FilledVolumeFraction);
|
||||
}
|
||||
Color,
|
||||
FillFraction,
|
||||
}
|
||||
|
||||
public enum SolutionContainerLayers : byte
|
||||
|
||||
Reference in New Issue
Block a user