Skip to content

Commit

Permalink
Switch to plugin settings in dash
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytra committed Nov 28, 2024
1 parent 7935db1 commit 033123c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 27 deletions.
27 changes: 1 addition & 26 deletions ProjectObsidian/Injection/Injection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using FrooxEngine;
using FrooxEngine.ProtoFlux.Core;
using Obsidian.Shaders;
using System.Collections.Generic;

namespace Obsidian
{
Expand All @@ -16,9 +15,6 @@ internal static class ExecutionHook
private static Type? __connectorType;
private static Type? __connectorTypes;

private static AssemblyTypeRegistry obsidianRegistry;
private static bool registered = true;

// Static constructor for initializing the hook
static ExecutionHook()
{
Expand All @@ -27,28 +23,7 @@ static ExecutionHook()
Engine.Current.OnReady += () =>
{
ShaderInjection.AppendShaders();
DevCreateNewForm.AddAction("Plugins", "Register/Unregister Obsidian Assembly", (Slot s) =>
{
s.Destroy();
var glob = (List<AssemblyTypeRegistry>)typeof(GlobalTypeRegistry).GetField("_coreAssemblies", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
if (registered)
{
foreach (var thing in glob.ToList())
{
if (thing.Assembly == Assembly.GetExecutingAssembly())
{
obsidianRegistry = thing;
glob.Remove(thing);
}
}
registered = false;
}
else
{
glob.Add(obsidianRegistry);
registered = true;
}
});
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;
}
}
}

0 comments on commit 033123c

Please sign in to comment.