1
0

SharedAbsorbentSystem.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Linq;
  2. using Robust.Shared.GameStates;
  3. using Robust.Shared.Serialization;
  4. namespace Content.Shared.Fluids;
  5. /// <summary>
  6. /// Mopping logic for interacting with puddle components.
  7. /// </summary>
  8. public abstract class SharedAbsorbentSystem : EntitySystem
  9. {
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<AbsorbentComponent, ComponentGetState>(OnAbsorbentGetState);
  14. SubscribeLocalEvent<AbsorbentComponent, ComponentHandleState>(OnAbsorbentHandleState);
  15. }
  16. private void OnAbsorbentHandleState(EntityUid uid, AbsorbentComponent component, ref ComponentHandleState args)
  17. {
  18. if (args.Current is not AbsorbentComponentState state)
  19. return;
  20. if (component.Progress.OrderBy(x => x.Key.ToArgb()).SequenceEqual(state.Progress))
  21. return;
  22. component.Progress.Clear();
  23. foreach (var item in state.Progress)
  24. {
  25. component.Progress.Add(item.Key, item.Value);
  26. }
  27. }
  28. private void OnAbsorbentGetState(EntityUid uid, AbsorbentComponent component, ref ComponentGetState args)
  29. {
  30. args.State = new AbsorbentComponentState(component.Progress);
  31. }
  32. [Serializable, NetSerializable]
  33. protected sealed class AbsorbentComponentState : ComponentState
  34. {
  35. public Dictionary<Color, float> Progress;
  36. public AbsorbentComponentState(Dictionary<Color, float> progress)
  37. {
  38. Progress = progress;
  39. }
  40. }
  41. }