diff --git a/README.md b/README.md
index ca073f8..a844197 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
-
+
diff --git a/SaberFactory/Configuration/PluginConfig.cs b/SaberFactory/Configuration/PluginConfig.cs
index 97fdb1a..cd1f794 100644
--- a/SaberFactory/Configuration/PluginConfig.cs
+++ b/SaberFactory/Configuration/PluginConfig.cs
@@ -47,6 +47,8 @@ internal class PluginConfig
public bool SpecialBackground { get; set; } = true;
+ public bool ReloadOnSaberUpdate { get; set; } = false;
+
// How many threads to spawn when loading all sabers
// ! Not used as of right now !
[Ignore] public int LoadingThreads { get; set; } = 2;
@@ -59,7 +61,7 @@ internal class PluginConfig
// List of sabers / parts marked as favorite
[UseConverter(typeof(ListConverter))]
public List Favorites { get; set; } = new List();
-
+
[Ignore] public bool RuntimeFirstLaunch;
///
diff --git a/SaberFactory/Installers/PluginAppInstaller.cs b/SaberFactory/Installers/PluginAppInstaller.cs
index 6decd9f..a5b583a 100644
--- a/SaberFactory/Installers/PluginAppInstaller.cs
+++ b/SaberFactory/Installers/PluginAppInstaller.cs
@@ -10,6 +10,7 @@
using SaberFactory.Models;
using SaberFactory.Models.CustomSaber;
using SaberFactory.Saving;
+using SaberFactory.UI.CustomSaber.Views;
using SaberFactory.UI.Lib.BSML;
using SiraUtil;
using Zenject;
@@ -74,6 +75,8 @@ public override void InstallBindings()
Container.Bind().AsSingle();
+ Container.Bind().AsSingle();
+
InstallFactories();
InstallMiddlewares();
}
diff --git a/SaberFactory/UI/CustomSaber/Views/SaberFileWatcher.cs b/SaberFactory/UI/CustomSaber/Views/SaberFileWatcher.cs
new file mode 100644
index 0000000..03f93b5
--- /dev/null
+++ b/SaberFactory/UI/CustomSaber/Views/SaberFileWatcher.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using IPA.Utilities.Async;
+using UnityEngine;
+
+namespace SaberFactory.UI.CustomSaber.Views
+{
+ public class SaberFileWatcher
+ {
+ private const string Filter = "*.saber";
+
+ public bool IsWatching { get; private set; }
+ private readonly DirectoryInfo _dir;
+
+ private FileSystemWatcher _watcher;
+
+ public SaberFileWatcher(PluginDirectories dirs)
+ {
+ _dir = dirs.CustomSaberDir;
+ }
+
+ public event Action OnSaberUpdate;
+
+ public void Watch()
+ {
+ if (_watcher is { }) StopWatching();
+
+ _watcher = new FileSystemWatcher(_dir.FullName);
+
+ _watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Attributes | NotifyFilters.LastAccess;
+
+ _watcher.Changed += WatcherOnChanged;
+
+ _watcher.Filter = Filter;
+ _watcher.IncludeSubdirectories = true;
+ _watcher.EnableRaisingEvents = true;
+
+ IsWatching = true;
+
+ Debug.LogError($"Started watching in {_dir.FullName}");
+ }
+
+ private void WatcherOnChanged(object sender, FileSystemEventArgs e)
+ {
+ HMMainThreadDispatcher.instance.Enqueue(Initiate(e.FullPath));
+ }
+
+ private IEnumerator Initiate(string filename)
+ {
+ var seconds = 0f;
+ while (seconds < 10)
+ {
+ if (File.Exists(filename))
+ {
+ yield return new WaitForSeconds(0.5f);
+ OnSaberUpdate?.Invoke(filename);
+ yield break;
+ }
+
+ yield return new WaitForSeconds(0.5f);
+ seconds += 0.5f;
+ }
+ }
+
+ public void StopWatching()
+ {
+ if (_watcher is null) return;
+
+ _watcher.Changed -= WatcherOnChanged;
+ _watcher.EnableRaisingEvents = false;
+ _watcher.Dispose();
+ _watcher = null;
+ IsWatching = false;
+
+ Debug.LogError("Stopped watching");
+ }
+ }
+}
\ No newline at end of file
diff --git a/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs b/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs
index d2f94c8..3fd6f35 100644
--- a/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs
+++ b/SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs
@@ -1,11 +1,10 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
-using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
+using BeatSaberMarkupLanguage;
using BeatSaberMarkupLanguage.Attributes;
using HMUI;
using IPA.Loader;
@@ -19,10 +18,8 @@
using SaberFactory.UI.CustomSaber.CustomComponents;
using SaberFactory.UI.CustomSaber.Popups;
using SaberFactory.UI.Lib;
-using SiraUtil;
using Zenject;
using Debug = UnityEngine.Debug;
-using Utilities = BeatSaberMarkupLanguage.Utilities;
namespace SaberFactory.UI.CustomSaber.Views
{
@@ -60,10 +57,11 @@ private float SaberWidth
[Inject] private readonly EditorInstanceManager _editorInstanceManager = null;
[Inject] private readonly MainAssetStore _mainAssetStore = null;
+ [Inject] private readonly PluginMetadata _metadata = null;
[Inject] private readonly PluginConfig _pluginConfig = null;
[Inject] private readonly List _remoteParts = null;
+ [Inject] private readonly SaberFileWatcher _saberFileWatcher = null;
[Inject] private readonly SaberSet _saberSet = null;
- [Inject] private readonly PluginMetadata _metadata = null;
private ModelComposition _currentComposition;
private PreloadMetaData _currentPreloadMetaData;
private SaberListDirectoryManager _dirManager;
@@ -96,9 +94,9 @@ private async void Setup()
_listTitle = "Saber Factory " + _metadata.HVersion + "";
_saberList.SetText(_listTitle);
await LoadSabers();
-
+
if (CommonHelpers.IsDate(null, 10) &&
- _pluginConfig.SpecialBackground &&
+ _pluginConfig.SpecialBackground &&
_saberList.transform.GetChild(0)?.GetComponent() is { } imageView)
{
imageView.sprite = Utilities.FindSpriteInAssembly("SaberFactory.Resources.UI.halloween_bg.png");
@@ -180,6 +178,14 @@ orderby meta.IsFavorite descending
UpdateUi();
}
+ public void OnSaberFileUpdate(string filename)
+ {
+ var currentSaberPath = _currentComposition.GetLeft().StoreAsset.RelativePath;
+ if (!filename.Contains(currentSaberPath)) return;
+ Debug.LogError("Saber got updated\n"+filename);
+ if(File.Exists(filename)) ClickedReload();
+ }
+
private async void SaberSelected(object item)
{
var reloadList = false;
diff --git a/SaberFactory/UI/TrailPreviewer.cs b/SaberFactory/UI/TrailPreviewer.cs
index 8fb580d..dd983b3 100644
--- a/SaberFactory/UI/TrailPreviewer.cs
+++ b/SaberFactory/UI/TrailPreviewer.cs
@@ -176,11 +176,12 @@ public void SetColor(Color color)
public void UpdateWidth()
{
var locPosStart = _instance.transform.InverseTransformPoint(_pointStart.position);
+ var locPosEnd = _instance.transform.InverseTransformPoint(_pointEnd.position);
var newVerts = new Vector3[4];
newVerts[0] = new Vector3(0, 0, locPosStart.z); // bottom left
- newVerts[1] = new Vector3(0, 0, 0); // top left
- newVerts[2] = new Vector3(1, 0, 0); // top right
+ newVerts[1] = new Vector3(0, 0, locPosEnd.z); // top left
+ newVerts[2] = new Vector3(1, 0, locPosEnd.z); // top right
newVerts[3] = new Vector3(1, 0, locPosStart.z); // bottom right
_mesh.vertices = newVerts;
}