diff --git a/code/BridgeImporter.cs b/code/BridgeImporter.cs index 891a56c..9d48eef 100644 --- a/code/BridgeImporter.cs +++ b/code/BridgeImporter.cs @@ -19,7 +19,7 @@ public void Stop() listener.EndServer(); } - public async Task ImportFrom( Progress.ProgressBar progressBar, BridgeAsset quixelAsset ) + public async Task ImportFrom( BridgeAsset quixelAsset ) { if ( ExportAsset( quixelAsset, out string path ) ) { @@ -30,9 +30,6 @@ public async Task ImportFrom( Progress.ProgressBar progressBar, BridgeAsset quix Mesh mesh = quixelAsset.Meshes[i]; var mdlPath = Path.Join( relativePath, $"{quixelAsset.Name.ToSourceName()}_{quixelAsset.Id}.vmdl" ); - progressBar.SetSubtitle( "Compiling... (2/2)" ); - progressBar.SetValues( 0.66f, 1.0f ); - // Locate imported s&box asset var engineAsset = AssetSystem.All.FirstOrDefault( x => x.Path.NormalizeFilename() == mdlPath.NormalizeFilename() ); @@ -45,14 +42,8 @@ public async Task ImportFrom( Progress.ProgressBar progressBar, BridgeAsset quix // Force a full compile engineAsset.Compile( true ); - Log.Trace( $"Exported to: {engineAsset}" ); - - // Highlight in asset browser - MainAssetBrowser.Instance.FocusOnAsset( engineAsset ); + Log.Info( $"Exported to: {engineAsset}" ); } - - progressBar.SetSubtitle( "Done." ); - progressBar.SetValues( 1.0f, 1.0f ); } } else diff --git a/code/BridgeServer.cs b/code/BridgeServer.cs index 3d7877b..eab4eab 100644 --- a/code/BridgeServer.cs +++ b/code/BridgeServer.cs @@ -39,14 +39,9 @@ public void EndServer() tcpListener.Stop(); } - // - // Shit way of running things on the main thread - // (we should probably just re-write the tcp listener - // code to work better in a single-thread context) - // - [Event.Client.Frame] - public static void OnFrame() + public static void Import() { + Log.Trace( "Frame" ); if ( !queueDirty ) return; @@ -55,57 +50,41 @@ public static void OnFrame() queueDirty = false; importQueue.Clear(); - var asyncTask = async () => - { - using var progress = Progress.Start( "Importing from Quixel Bridge..." ); - var progressList = new List(); - - var queueItem = importQueueCopy[0]; - var quixelAssets = JsonSerializer.Deserialize( queueItem ); - - // - // Add to progress window - // - for ( int i = 0; i < quixelAssets.Length; i++ ) - { - var quixelAsset = quixelAssets[i]; - var progressBar = Progress.Bar( $"Import '{quixelAsset.Name}'" ); - progressList.Add( progressBar ); - progressBar.SetSubtitle( "Waiting..." ); - progressBar.SetValues( 0.0f, 1.0f ); - } + var queueItem = importQueueCopy[0]; + var quixelAssets = JsonSerializer.Deserialize( queueItem ); - // - // Start compiling - // - for ( int i = 0; i < quixelAssets.Length; i++ ) - { - var quixelAsset = quixelAssets[i]; - var progressBar = progressList[i]; - progressBar.SetSubtitle( "Importing... (1/2)" ); - progressBar.SetValues( 0.33f, 1.0f ); - await Task.Delay( 50 ); - - await BridgeImporter.Instance.ImportFrom( progressBar, quixelAsset ); - } + // + // Add to progress window + // + for ( int i = 0; i < quixelAssets.Length; i++ ) + { + var quixelAsset = quixelAssets[i]; + Log.Info( $"Importing '{quixelAsset.Name}'..." ); + } - // - // Play a "success" chime if the queue has more than 1 item in it and the - // user has the chime enabled - // - if ( quixelAssets.Length > 1 && BridgeSettings.Instance.EnableAudio ) - { - var handle = Audio.Play( "quixel_import_success" ); - handle.Position = Vector3.Zero; - handle.ListenLocal = true; - } + // + // Start compiling + // + for ( int i = 0; i < quixelAssets.Length; i++ ) + { + var quixelAsset = quixelAssets[i]; + Log.Info( $"Compiling '{quixelAsset.Name}'..." ); - await Task.Delay( 1000 ); // Give the user an extra second to see that we completed + _ = BridgeImporter.Instance.ImportFrom( quixelAsset ); - progressList.ForEach( x => x.Dispose() ); - }; + Log.Info( $"Completed import for '{quixelAsset.Name}'!" ); + } - _ = asyncTask(); + // + // Play a "success" chime if the queue has more than 1 item in it and the + // user has the chime enabled + // + if ( quixelAssets.Length > 1 && BridgeSettings.Instance.EnableAudio ) + { + var handle = Audio.Play( "quixel_import_success" ); + handle.Position = Vector3.Zero; + handle.ListenLocal = true; + } } private void ListenThread() @@ -135,6 +114,8 @@ private void ListenThread() importQueue.Add( clientMessage ); queueDirty = true; + + Import(); } catch ( Exception ) { diff --git a/code/Progress/Progress.cs b/code/Progress/Progress.cs index 0b6d9ca..20b8982 100644 --- a/code/Progress/Progress.cs +++ b/code/Progress/Progress.cs @@ -6,7 +6,7 @@ public static class Progress static ProgressWindow currentWindow; static int Popups; - class ProgressSection : IDisposable + public class ProgressSection : IDisposable { bool disposed; string oldTitle;