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

fixed trail offset #91

Merged
merged 1 commit into from
Oct 2, 2021
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p align="center">
<a href="https://github.com/ToniMacaroni/SaberFactory/actions/workflows/integrate.yml" alt="build status">
<img src="https://img.shields.io/github/workflow/status/ToniMacaroni/SaberFactory/Build%20Saber%20Factory" /></a>
<a href="#backers" alt="total downloads">
<a alt="total downloads">
<img src="https://img.shields.io/github/downloads/ToniMacaroni/SaberFactory/total" /></a>
<a href="https://github.com/ToniMacaroni/SaberFactory/releases" alt="latest version">
<img src="https://img.shields.io/github/v/tag/ToniMacaroni/SaberFactory?label=version" /></a>
Expand Down
4 changes: 3 additions & 1 deletion SaberFactory/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,7 +61,7 @@ internal class PluginConfig
// List of sabers / parts marked as favorite
[UseConverter(typeof(ListConverter<string>))]
public List<string> Favorites { get; set; } = new List<string>();

[Ignore] public bool RuntimeFirstLaunch;

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions SaberFactory/Installers/PluginAppInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,8 @@ public override void InstallBindings()

Container.Bind<SaberSet>().AsSingle();

Container.Bind<SaberFileWatcher>().AsSingle();

InstallFactories();
InstallMiddlewares();
}
Expand Down
80 changes: 80 additions & 0 deletions SaberFactory/UI/CustomSaber/Views/SaberFileWatcher.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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");
}
}
}
22 changes: 14 additions & 8 deletions SaberFactory/UI/CustomSaber/Views/SaberSelectorView.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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<RemoteLocationPart> _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;
Expand Down Expand Up @@ -96,9 +94,9 @@ private async void Setup()
_listTitle = "<color=#2f6594>Saber Factory " + _metadata.HVersion + "</color>";
_saberList.SetText(_listTitle);
await LoadSabers();

if (CommonHelpers.IsDate(null, 10) &&
_pluginConfig.SpecialBackground &&
_pluginConfig.SpecialBackground &&
_saberList.transform.GetChild(0)?.GetComponent<ImageView>() is { } imageView)
{
imageView.sprite = Utilities.FindSpriteInAssembly("SaberFactory.Resources.UI.halloween_bg.png");
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions SaberFactory/UI/TrailPreviewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down