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.

111 lines
2.9 KiB

  1. using IPA;
  2. using UnityEngine.SceneManagement;
  3. using IPALogger = IPA.Logging.Logger;
  4. using BSIPA_ModList.UI;
  5. using UnityEngine;
  6. using IPA.Logging;
  7. using BSIPA_ModList.UI.ViewControllers;
  8. using System.Collections;
  9. using IPA.Loader;
  10. using IPA.Config;
  11. using IPA.Utilities;
  12. using System;
  13. namespace BSIPA_ModList
  14. {
  15. internal static class Logger
  16. {
  17. internal static IPALogger log { get; set; }
  18. internal static IPALogger md => log.GetChildLogger("MarkDown");
  19. }
  20. internal class SelfConfig
  21. {
  22. public bool Regenerate = true;
  23. public bool ShowEnableDisable = false;
  24. }
  25. /// <summary>
  26. /// The main plugin type for the in-game mod list mod.
  27. /// </summary>
  28. internal class Plugin : IBeatSaberPlugin
  29. {
  30. internal static IConfigProvider provider;
  31. internal static Ref<SelfConfig> config;
  32. internal static event Action<SelfConfig> OnConfigChaned;
  33. /// <summary>
  34. /// Initializes the plugin with certain parameters. Is only called once.
  35. ///
  36. /// This is called by the plugin loader in BSIPA, and thus must be <see langword="public"/>.
  37. /// </summary>
  38. /// <param name="logger">a logger to initialize the plugin with</param>
  39. public void Init(IPALogger logger, IConfigProvider provider)
  40. {
  41. Logger.log = logger;
  42. Plugin.provider = provider;
  43. config = provider.MakeLink<SelfConfig>((p, r) =>
  44. {
  45. if (r.Value.Regenerate)
  46. p.Store(r.Value = new SelfConfig { Regenerate = false });
  47. OnConfigChaned?.Invoke(r.Value);
  48. });
  49. IPA.Updating.BeatMods.Updater.ModListPresent = true;
  50. // Load resources ahead of time
  51. MarkdownView.StartLoadResourcesAsync();
  52. SharedCoroutineStarter.instance.StartCoroutine(LoadPluginIcons());
  53. }
  54. public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
  55. {
  56. }
  57. public void OnApplicationQuit()
  58. {
  59. }
  60. public void OnApplicationStart()
  61. {
  62. }
  63. private static IEnumerator LoadPluginIcons()
  64. {
  65. foreach (var p in PluginManager.AllPlugins)
  66. {
  67. yield return null;
  68. Logger.log.Debug($"Loading icon for {p.Metadata.Name}");
  69. var _ = p.Metadata.GetIcon();
  70. }
  71. }
  72. public void OnFixedUpdate()
  73. {
  74. }
  75. public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  76. {
  77. if (scene.name == "MenuCore")
  78. {
  79. FloatingNotification.Create();
  80. if (ButtonUI.Instance == null)
  81. new GameObject("BSIPA Mod List Object").AddComponent<ButtonUI>().Init();
  82. }
  83. }
  84. public void OnSceneUnloaded(Scene scene)
  85. {
  86. }
  87. public void OnUpdate()
  88. {
  89. }
  90. }
  91. }