EffectManager.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class EffectManager : IManager, ISerializable
  6. {
  7. public const string header = "EFFECT";
  8. public const string footer = "END_EFFECT";
  9. private Dictionary<Type, IEffectManager> EffectManagers = new Dictionary<Type, IEffectManager>();
  10. private BloomEffectManager bloomEffectManager;
  11. public EffectManager()
  12. {
  13. // Not going to add more effects because SceneCapture does it better anyway
  14. bloomEffectManager = AddManager<BloomEffectManager>();
  15. AddManager<DepthOfFieldEffectManager>();
  16. AddManager<VignetteEffectManager>();
  17. AddManager<FogEffectManager>();
  18. }
  19. public T Get<T>() where T : IEffectManager
  20. {
  21. if (EffectManagers.ContainsKey(typeof(T))) return (T)EffectManagers[typeof(T)];
  22. else return default(T);
  23. }
  24. private T AddManager<T>() where T : IEffectManager, new()
  25. {
  26. T manager = new T();
  27. EffectManagers[typeof(T)] = manager;
  28. return manager;
  29. }
  30. public void Serialize(System.IO.BinaryWriter binaryWriter)
  31. {
  32. binaryWriter.Write(header);
  33. foreach (IEffectManager effectManager in EffectManagers.Values)
  34. {
  35. effectManager.Serialize(binaryWriter);
  36. }
  37. binaryWriter.Write(footer);
  38. }
  39. public void Deserialize(System.IO.BinaryReader binaryReader)
  40. {
  41. string header;
  42. while ((header = binaryReader.ReadString()) != footer)
  43. {
  44. switch (header)
  45. {
  46. case BloomEffectManager.header:
  47. Get<BloomEffectManager>().Deserialize(binaryReader);
  48. break;
  49. case DepthOfFieldEffectManager.header:
  50. Get<DepthOfFieldEffectManager>().Deserialize(binaryReader);
  51. break;
  52. case VignetteEffectManager.header:
  53. Get<VignetteEffectManager>().Deserialize(binaryReader);
  54. break;
  55. case FogEffectManager.header:
  56. Get<FogEffectManager>().Deserialize(binaryReader);
  57. break;
  58. }
  59. }
  60. }
  61. public void Activate()
  62. {
  63. foreach (IEffectManager effectManager in EffectManagers.Values)
  64. {
  65. effectManager.Activate();
  66. }
  67. }
  68. public void Deactivate()
  69. {
  70. foreach (IEffectManager effectManager in EffectManagers.Values)
  71. {
  72. effectManager.Deactivate();
  73. }
  74. }
  75. public void Update()
  76. {
  77. // Bloom is the only effect that needs to update because I'm dumb/lazy
  78. bloomEffectManager.Update();
  79. }
  80. }
  81. }