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