-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Pespiri/bsipa4-update
Bsipa4 update
- Loading branch information
Showing
9 changed files
with
114 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,70 @@ | ||
using BeatSaberMarkupLanguage.Settings; | ||
using IPA; | ||
using IPA; | ||
using IPA.Config; | ||
using IPA.Loader; | ||
using StepBackWall.Gameplay; | ||
using StepBackWall.Settings; | ||
using StepBackWall.Settings.UI; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
using IPALogger = IPA.Logging.Logger; | ||
|
||
namespace StepBackWall | ||
{ | ||
public class Plugin : IBeatSaberPlugin, IDisablablePlugin | ||
[Plugin(RuntimeOptions.DynamicInit)] | ||
public class Plugin | ||
{ | ||
public static string PluginName = "StepBackWall"; | ||
public static SemVer.Version PluginVersion = new SemVer.Version("0.0.0"); // Default | ||
public static string PluginName => "StepBackWall"; | ||
public static SemVer.Version PluginVersion { get; private set; } = new SemVer.Version("0.0.0"); // Default | ||
|
||
public void Init(IPALogger logger, [Config.Prefer("json")] IConfigProvider cfgProvider, PluginLoader.PluginMetadata metadata) | ||
[Init] | ||
public void Init(IPALogger logger, Config config, PluginMetadata metadata) | ||
{ | ||
Logger.log = logger; | ||
Configuration.Init(cfgProvider); | ||
Configuration.Init(config); | ||
|
||
if (metadata?.Version != null) | ||
{ | ||
PluginVersion = metadata.Version; | ||
} | ||
} | ||
|
||
[OnEnable] | ||
public void OnEnable() => Load(); | ||
[OnDisable] | ||
public void OnDisable() => Unload(); | ||
public void OnApplicationQuit() => Unload(); | ||
|
||
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) | ||
private void OnGameSceneLoaded() | ||
{ | ||
if (nextScene.name == "GameCore") | ||
if (Configuration.EnableStepBackWalls && !BS_Utils.Gameplay.Gamemode.SelectedCharacteristic.containsRotationEvents) | ||
{ | ||
if (Configuration.EnableStepBackWalls) | ||
{ | ||
new GameObject(PluginName).AddComponent<StepBackWallEnabler>(); | ||
} | ||
} | ||
else if (nextScene.name == "MenuViewControllers" && prevScene.name == "EmptyTransition") | ||
{ | ||
BSMLSettings.instance.AddSettingsMenu("StepBack Wall", "StepBackWall.Settings.UI.Views.mainsettings.bsml", MainSettings.instance); | ||
new GameObject(PluginName).AddComponent<StepBackWallEnabler>(); | ||
} | ||
} | ||
|
||
public void OnApplicationStart() { } | ||
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { } | ||
public void OnSceneUnloaded(Scene scene) { } | ||
public void OnUpdate() { } | ||
public void OnFixedUpdate() { } | ||
|
||
private void Load() | ||
{ | ||
Configuration.Load(); | ||
Logger.log.Info($"{PluginName} v{PluginVersion} has started."); | ||
SettingsUI.CreateMenu(); | ||
AddEvents(); | ||
|
||
Logger.log.Info($"{PluginName} v.{PluginVersion} has started."); | ||
} | ||
|
||
private void Unload() | ||
{ | ||
RemoveEvents(); | ||
Configuration.Save(); | ||
SettingsUI.RemoveMenu(); | ||
} | ||
|
||
private void AddEvents() | ||
{ | ||
RemoveEvents(); | ||
BS_Utils.Utilities.BSEvents.gameSceneLoaded += OnGameSceneLoaded; | ||
} | ||
|
||
private void RemoveEvents() | ||
{ | ||
BS_Utils.Utilities.BSEvents.gameSceneLoaded -= OnGameSceneLoaded; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,26 @@ | ||
using IPA.Config; | ||
using IPA.Utilities; | ||
using IPA.Config.Stores; | ||
using StepBackWall.Settings.Utilities; | ||
|
||
namespace StepBackWall.Settings | ||
{ | ||
public class Configuration | ||
{ | ||
private static Ref<PluginConfig> config; | ||
private static IConfigProvider configProvider; | ||
|
||
public static bool EnableStepBackWalls { get; internal set; } | ||
|
||
internal static void Init(IConfigProvider cfgProvider) | ||
internal static void Init(Config config) | ||
{ | ||
configProvider = cfgProvider; | ||
config = cfgProvider.MakeLink<PluginConfig>((p, v) => | ||
{ | ||
if (v.Value == null || v.Value.RegenerateConfig) | ||
{ | ||
p.Store(v.Value = new PluginConfig() { RegenerateConfig = false }); | ||
} | ||
config = v; | ||
}); | ||
PluginConfig.Instance = config.Generated<PluginConfig>(); | ||
} | ||
|
||
internal static void Load() | ||
{ | ||
EnableStepBackWalls = config.Value.EnableStepBackWall; | ||
EnableStepBackWalls = PluginConfig.Instance.EnableStepBackWall; | ||
} | ||
|
||
internal static void Save() | ||
{ | ||
config.Value.EnableStepBackWall = EnableStepBackWalls; | ||
|
||
configProvider.Store(config.Value); | ||
PluginConfig.Instance.EnableStepBackWall = EnableStepBackWalls; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using BeatSaberMarkupLanguage.Attributes; | ||
using BeatSaberMarkupLanguage.Components; | ||
|
||
namespace StepBackWall.Settings.UI | ||
{ | ||
public class MainModifiers : NotifiableSingleton<MainModifiers> | ||
{ | ||
[UIValue("enable-stepback-wall")] | ||
public bool IsStepBackWallEnabled | ||
{ | ||
get => Configuration.EnableStepBackWalls; | ||
set => Configuration.EnableStepBackWalls = value; | ||
} | ||
|
||
[UIAction("trigger-toggle")] | ||
void TriggerEnable(bool val) => IsStepBackWallEnabled = val; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using BeatSaberMarkupLanguage.GameplaySetup; | ||
using BeatSaberMarkupLanguage.Settings; | ||
|
||
namespace StepBackWall.Settings.UI | ||
{ | ||
internal class SettingsUI | ||
{ | ||
public static bool created = false; | ||
|
||
public static void CreateMenu() | ||
{ | ||
if (!created) | ||
{ | ||
BSMLSettings.instance.AddSettingsMenu("StepBack Wall", "StepBackWall.Settings.UI.Views.mainsettings.bsml", MainSettings.instance); | ||
GameplaySetup.instance.AddTab("StepBack Wall", "StepBackWall.Settings.UI.Views.mainmodifiers.bsml", MainModifiers.instance); | ||
created = true; | ||
} | ||
} | ||
|
||
public static void RemoveMenu() | ||
{ | ||
if (created) | ||
{ | ||
BSMLSettings.instance.RemoveSettingsMenu(MainSettings.instance); | ||
GameplaySetup.instance.RemoveTab("StepBack Wall"); | ||
created = false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<bg xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://monkeymanboy.github.io/BSML-Docs/ https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd'> | ||
<settings-container pref-width='50' pref-height='5'> | ||
<modifier text='Enable' value='enable-stepback-wall' | ||
hover-hint='Not available in 90/360 levels' | ||
source='StepBackWall.Resources.icon_playersettings.png' | ||
on-change='trigger-toggle'/> | ||
</settings-container> | ||
</bg> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters