2022-08-07 01:50:52 -07:00
using Content.Shared.Chemistry ;
using Robust.Client.GameObjects ;
namespace Content.Client.Chemistry.Visualizers ;
public sealed class SolutionContainerVisualsSystem : VisualizerSystem < SolutionContainerVisualsComponent >
{
protected override void OnAppearanceChange ( EntityUid uid , SolutionContainerVisualsComponent component , ref AppearanceChangeEvent args )
{
2023-02-02 17:34:53 +01:00
if ( ! AppearanceSystem . TryGetData < float > ( uid , SolutionContainerVisuals . FillFraction , out var fraction , args . Component ) )
2022-08-07 01:50:52 -07:00
return ;
if ( args . Sprite = = null )
return ;
if ( ! args . Sprite . LayerMapTryGet ( component . Layer , out var fillLayer ) )
return ;
2023-01-23 19:33:11 -05:00
// 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
// a giant error sign and error for debug.
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!" ) ;
fraction = 1f ;
}
2023-01-14 13:21:15 +13:00
var closestFillSprite = ( int ) Math . Round ( fraction * component . MaxFillLevels ) ;
2022-08-07 01:50:52 -07:00
if ( closestFillSprite > 0 )
{
if ( component . FillBaseName = = null )
return ;
args . Sprite . LayerSetVisible ( fillLayer , true ) ;
var stateName = component . FillBaseName + closestFillSprite ;
args . Sprite . LayerSetState ( fillLayer , stateName ) ;
2023-02-02 17:34:53 +01:00
if ( component . ChangeColor & & AppearanceSystem . TryGetData < Color > ( uid , SolutionContainerVisuals . Color , out var color , args . Component ) )
2023-01-14 13:21:15 +13:00
args . Sprite . LayerSetColor ( fillLayer , color ) ;
2022-08-07 01:50:52 -07:00
}
else
{
if ( component . EmptySpriteName = = null )
args . Sprite . LayerSetVisible ( fillLayer , false ) ;
else
{
args . Sprite . LayerSetState ( fillLayer , component . EmptySpriteName ) ;
if ( component . ChangeColor )
args . Sprite . LayerSetColor ( fillLayer , component . EmptySpriteColor ) ;
}
}
}
}