EffectManager.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class EffectManager : IManager, ISerializable
  6. {
  7. public const string header = "EFFECT";
  8. public const string footer = "END_EFFECT";
  9. private readonly Dictionary<Type, IEffectManager> EffectManagers = new Dictionary<Type, IEffectManager>();
  10. public T Get<T>() where T : IEffectManager
  11. => EffectManagers.ContainsKey(typeof(T)) ? (T)EffectManagers[typeof(T)] : default;
  12. public T AddManager<T>() where T : IEffectManager, new()
  13. {
  14. T manager = new T();
  15. EffectManagers[typeof(T)] = manager;
  16. manager.Activate();
  17. return manager;
  18. }
  19. public void Serialize(System.IO.BinaryWriter binaryWriter)
  20. {
  21. binaryWriter.Write(header);
  22. foreach (IEffectManager effectManager in EffectManagers.Values) effectManager.Serialize(binaryWriter);
  23. binaryWriter.Write(footer);
  24. }
  25. public void Deserialize(System.IO.BinaryReader binaryReader)
  26. {
  27. string header;
  28. while ((header = binaryReader.ReadString()) != footer)
  29. {
  30. switch (header)
  31. {
  32. case BloomEffectManager.header:
  33. Get<BloomEffectManager>().Deserialize(binaryReader);
  34. break;
  35. case DepthOfFieldEffectManager.header:
  36. Get<DepthOfFieldEffectManager>().Deserialize(binaryReader);
  37. break;
  38. case VignetteEffectManager.header:
  39. Get<VignetteEffectManager>().Deserialize(binaryReader);
  40. break;
  41. case FogEffectManager.header:
  42. Get<FogEffectManager>().Deserialize(binaryReader);
  43. break;
  44. case SepiaToneEffectManger.header:
  45. Get<SepiaToneEffectManger>().Deserialize(binaryReader);
  46. break;
  47. case BlurEffectManager.header:
  48. Get<BlurEffectManager>().Deserialize(binaryReader);
  49. break;
  50. }
  51. }
  52. }
  53. public void Activate()
  54. {
  55. foreach (IEffectManager effectManager in EffectManagers.Values) effectManager.Activate();
  56. }
  57. public void Deactivate()
  58. {
  59. foreach (IEffectManager effectManager in EffectManagers.Values) effectManager.Deactivate();
  60. }
  61. public void Update() { }
  62. }
  63. }