You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.8 KiB

6 years ago
6 years ago
  1. using IllusionPlugin;
  2. using IPA;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. using Logger = IllusionInjector.Logging.Logger;
  10. namespace IllusionInjector {
  11. public class CompositeBSPlugin : IBeatSaberPlugin
  12. {
  13. IEnumerable<IBeatSaberPlugin> plugins;
  14. private delegate void CompositeCall(IBeatSaberPlugin plugin);
  15. public CompositeBSPlugin(IEnumerable<IBeatSaberPlugin> plugins) {
  16. this.plugins = plugins;
  17. }
  18. public void OnApplicationStart() {
  19. Invoke(plugin => plugin.OnApplicationStart());
  20. }
  21. public void OnApplicationQuit() {
  22. Invoke(plugin => plugin.OnApplicationQuit());
  23. }
  24. public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) {
  25. foreach (var plugin in plugins) {
  26. try {
  27. plugin.OnSceneLoaded(scene, sceneMode);
  28. }
  29. catch (Exception ex) {
  30. Logger.log.Error($"{plugin.Name}: {ex}");
  31. }
  32. }
  33. }
  34. public void OnSceneUnloaded(Scene scene) {
  35. foreach (var plugin in plugins) {
  36. try {
  37. plugin.OnSceneUnloaded(scene);
  38. }
  39. catch (Exception ex) {
  40. Logger.log.Error($"{plugin.Name}: {ex}");
  41. }
  42. }
  43. }
  44. public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
  45. foreach (var plugin in plugins) {
  46. try {
  47. plugin.OnActiveSceneChanged(prevScene, nextScene);
  48. }
  49. catch (Exception ex) {
  50. Logger.log.Error($"{plugin.Name}: {ex}");
  51. }
  52. }
  53. }
  54. private void Invoke(CompositeCall callback) {
  55. foreach (var plugin in plugins) {
  56. try {
  57. callback(plugin);
  58. }
  59. catch (Exception ex) {
  60. Logger.log.Error($"{plugin.Name}: {ex}");
  61. }
  62. }
  63. }
  64. public void OnUpdate() {
  65. Invoke(plugin => plugin.OnUpdate());
  66. }
  67. public void OnFixedUpdate() {
  68. Invoke(plugin => plugin.OnFixedUpdate());
  69. }
  70. public string Name => throw new NotImplementedException();
  71. public string Version => throw new NotImplementedException();
  72. public Uri UpdateUri => throw new NotImplementedException();
  73. public ModsaberModInfo ModInfo => throw new NotImplementedException();
  74. public void OnLateUpdate() {
  75. Invoke(plugin => {
  76. if (plugin is IEnhancedBeatSaberPlugin)
  77. ((IEnhancedBeatSaberPlugin) plugin).OnLateUpdate();
  78. });
  79. }
  80. }
  81. }