Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin settings to toggle loading the plugin when starting new sessions #60

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ProjectObsidian/Injection/Injection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ static ExecutionHook()
{
Engine.Current.OnReady += () =>
{
ShaderInjection.AppendShaders();

ShaderInjection.AppendShaders();
Settings.GetActiveSetting<PluginSettings>();
};
}
catch (Exception e)
Expand Down
1 change: 0 additions & 1 deletion ProjectObsidian/Settings/MIDI_Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ protected override void OnStart()
_localeData.LocaleCode = "en";
_localeData.Authors = new List<string>() { "Nytra" };
_localeData.Messages = new Dictionary<string, string>();
_localeData.Messages.Add("Settings.Category.Obsidian", "Obsidian");
_localeData.Messages.Add("Settings.MIDI_Settings", "MIDI Settings");
_localeData.Messages.Add("Settings.MIDI_Settings.RefreshDeviceLists", "Refresh Devices");
_localeData.Messages.Add("Settings.MIDI_Settings.InputDevices", "Input Devices");
Expand Down
83 changes: 83 additions & 0 deletions ProjectObsidian/Settings/PluginSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FrooxEngine;
using Elements.Core;
using Elements.Assets;
using Commons.Music.Midi;
using System.Reflection;

namespace Obsidian;

[SettingCategory("Obsidian")]
public class PluginSettings : SettingComponent<PluginSettings>
{
public override bool UserspaceOnly => true;

[NonPersistent]
[SettingIndicatorProperty(null, null, null, null, false, 0L)]
public readonly Sync<bool> CoreAssemblyLoaded;

private LocaleData _localeData;

private static AssemblyTypeRegistry obsidianRegistry;

protected override void OnStart()
{
base.OnStart();
_localeData = new LocaleData();
_localeData.LocaleCode = "en";
_localeData.Authors = new List<string>() { "Nytra" };
_localeData.Messages = new Dictionary<string, string>();
_localeData.Messages.Add("Settings.Category.Obsidian", "Obsidian");
_localeData.Messages.Add("Settings.PluginSettings", "Plugin Settings");
_localeData.Messages.Add("Settings.PluginSettings.CoreAssemblyLoaded", "Core Assembly Loaded");
_localeData.Messages.Add("Settings.PluginSettings.ToggleCoreAssembly", "Toggle Core Assembly");

CoreAssemblyLoaded.Value = true;

// Sometimes the locale is null in here, so wait a bit I guess

RunInUpdates(15, () =>
{
UpdateLocale();
Settings.RegisterValueChanges<LocaleSettings>(UpdateLocale);
});
}

protected override void OnDispose()
{
base.OnDispose();
Settings.UnregisterValueChanges<LocaleSettings>(UpdateLocale);
}

private void UpdateLocale(LocaleSettings settings = null)
{
this.GetCoreLocale()?.Asset?.Data.LoadDataAdditively(_localeData);
}

[SettingProperty(null, null, null, false, 0L, null, null)]
[SyncMethod(typeof(Action), new string[] { })]
public void ToggleCoreAssembly()
{
UniLog.Log("Toggle pressed");
var glob = (List<AssemblyTypeRegistry>)typeof(GlobalTypeRegistry).GetField("_coreAssemblies", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
if (CoreAssemblyLoaded)
{
foreach (var thing in glob.ToList())
{
if (thing.Assembly == Assembly.GetExecutingAssembly())
{
obsidianRegistry = thing;
glob.Remove(thing);
}
}
CoreAssemblyLoaded.Value = false;
}
else
{
glob.Add(obsidianRegistry);
CoreAssemblyLoaded.Value = true;
}
}
}