1
0

PuddleSystem.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Content.Client.IconSmoothing;
  2. using Content.Shared.Chemistry.Components;
  3. using Content.Shared.Fluids;
  4. using Content.Shared.Fluids.Components;
  5. using Robust.Client.GameObjects;
  6. using Robust.Shared.Map;
  7. namespace Content.Client.Fluids;
  8. public sealed class PuddleSystem : SharedPuddleSystem
  9. {
  10. [Dependency] private readonly IconSmoothSystem _smooth = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<PuddleComponent, AppearanceChangeEvent>(OnPuddleAppearance);
  15. }
  16. private void OnPuddleAppearance(EntityUid uid, PuddleComponent component, ref AppearanceChangeEvent args)
  17. {
  18. if (args.Sprite == null)
  19. return;
  20. var volume = 1f;
  21. if (args.AppearanceData.TryGetValue(PuddleVisuals.CurrentVolume, out var volumeObj))
  22. {
  23. volume = (float) volumeObj;
  24. }
  25. // Update smoothing and sprite based on volume.
  26. if (TryComp<IconSmoothComponent>(uid, out var smooth))
  27. {
  28. if (volume < LowThreshold)
  29. {
  30. args.Sprite.LayerSetState(0, $"{smooth.StateBase}a");
  31. _smooth.SetEnabled(uid, false, smooth);
  32. }
  33. else if (volume < MediumThreshold)
  34. {
  35. args.Sprite.LayerSetState(0, $"{smooth.StateBase}b");
  36. _smooth.SetEnabled(uid, false, smooth);
  37. }
  38. else
  39. {
  40. if (!smooth.Enabled)
  41. {
  42. args.Sprite.LayerSetState(0, $"{smooth.StateBase}0");
  43. _smooth.SetEnabled(uid, true, smooth);
  44. _smooth.DirtyNeighbours(uid);
  45. }
  46. }
  47. }
  48. var baseColor = Color.White;
  49. if (args.AppearanceData.TryGetValue(PuddleVisuals.SolutionColor, out var colorObj))
  50. {
  51. var color = (Color) colorObj;
  52. args.Sprite.Color = color * baseColor;
  53. }
  54. else
  55. {
  56. args.Sprite.Color *= baseColor;
  57. }
  58. }
  59. #region Spill
  60. // Maybe someday we'll have clientside prediction for entity spawning, but not today.
  61. // Until then, these methods do nothing on the client.
  62. /// <inheritdoc/>
  63. public override bool TrySplashSpillAt(EntityUid uid, EntityCoordinates coordinates, Solution solution, out EntityUid puddleUid, bool sound = true, EntityUid? user = null)
  64. {
  65. puddleUid = EntityUid.Invalid;
  66. return false;
  67. }
  68. /// <inheritdoc/>
  69. public override bool TrySpillAt(EntityCoordinates coordinates, Solution solution, out EntityUid puddleUid, bool sound = true)
  70. {
  71. puddleUid = EntityUid.Invalid;
  72. return false;
  73. }
  74. /// <inheritdoc/>
  75. public override bool TrySpillAt(EntityUid uid, Solution solution, out EntityUid puddleUid, bool sound = true, TransformComponent? transformComponent = null)
  76. {
  77. puddleUid = EntityUid.Invalid;
  78. return false;
  79. }
  80. /// <inheritdoc/>
  81. public override bool TrySpillAt(TileRef tileRef, Solution solution, out EntityUid puddleUid, bool sound = true, bool tileReact = true)
  82. {
  83. puddleUid = EntityUid.Invalid;
  84. return false;
  85. }
  86. #endregion Spill
  87. }