Skip to content

Commit

Permalink
Merge pull request #1 from Pespiri/bsipa4-update
Browse files Browse the repository at this point in the history
Bsipa4 update
  • Loading branch information
Pespiri authored Aug 18, 2020
2 parents e861be9 + 750b71c commit 7e9584f
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 60 deletions.
56 changes: 30 additions & 26 deletions StepBackWall/Plugin.cs
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;
}
}
}
23 changes: 5 additions & 18 deletions StepBackWall/Settings/Configuration.cs
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;
}
}
}
18 changes: 18 additions & 0 deletions StepBackWall/Settings/UI/MainModifiers.cs
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;
}
}
30 changes: 30 additions & 0 deletions StepBackWall/Settings/UI/SettingsUI.cs
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;
}
}
}
}
8 changes: 8 additions & 0 deletions StepBackWall/Settings/UI/Views/mainmodifiers.bsml
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>
2 changes: 1 addition & 1 deletion StepBackWall/Settings/UI/Views/mainsettings.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
</horizontal>

<bool-setting text='Enable &apos;Step Back&apos; wall' value='enable-stepback-wall'
hover-hint='Default = On' />
hover-hint='Not available in 90/360 levels'/>
</settings-container>
2 changes: 1 addition & 1 deletion StepBackWall/Settings/Utilities/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class PluginConfig
{
public bool RegenerateConfig = true;
public static PluginConfig Instance;

public bool EnableStepBackWall = true;
}
Expand Down
27 changes: 17 additions & 10 deletions StepBackWall/StepBackWall.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,32 @@
<ItemGroup>
<Reference Include="BSML">
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
<private>false</private>
<private>false</private>
</Reference>
<Reference Include="BS_Utils">
<HintPath>$(BeatSaberDir)\Plugins\BS_Utils.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="HMLib">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll</HintPath>
<private>false</private>
<private>false</private>
</Reference>
<Reference Include="IPA.Loader">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<private>false</private>
<private>false</private>
</Reference>
<Reference Include="MainAssembly">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\MainAssembly.dll</HintPath>
<private>false</private>
<Reference Include="Main">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
<private>false</private>
</Reference>
<Reference Include="SemVer.1.2.0.0">
<HintPath>$(BeatSaberDir)\Libs\SemVer.1.2.0.0.dll</HintPath>
<private>false</private>
<Reference Include="SemVer">
<HintPath>$(BeatSaberDir)\Libs\SemVer.dll</HintPath>
<private>false</private>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<private>false</private>
<private>false</private>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -63,14 +67,17 @@
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings\Configuration.cs" />
<Compile Include="Settings\UI\MainModifiers.cs" />
<Compile Include="Settings\UI\MainSettings.cs" />
<Compile Include="Settings\UI\SettingsUI.cs" />
<Compile Include="Settings\Utilities\PluginConfig.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="manifest.json" />
<EmbeddedResource Include="Resources\description.md" />
<EmbeddedResource Include="Resources\icon.png" />
<EmbeddedResource Include="Resources\icon_playersettings.png" />
<EmbeddedResource Include="Settings\UI\Views\mainmodifiers.bsml" />
<EmbeddedResource Include="Settings\UI\Views\mainsettings.bsml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
8 changes: 4 additions & 4 deletions StepBackWall/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"#![StepBackWall.Resources.description.md]",
"Re-enables the Step Back wall layer"
],
"gameVersion": "1.6.2",
"gameVersion": "1.11.0",
"icon": "StepBackWall.Resources.icon.png",
"id": "StepBackWall",
"name": "StepBackWall",
"version": "1.1.0",
"version": "1.2.0",
"dependsOn": {
"BSIPA": "^3.13.4",
"BeatSaberMarkupLanguage": "^1.1.0"
"BeatSaberMarkupLanguage": "^1.3.4",
"BS Utils": "^1.4.11"
},
"features": [],
"links": {
Expand Down

0 comments on commit 7e9584f

Please sign in to comment.