diff --git a/Centrifuge.Distance b/Centrifuge.Distance index 17b8e41..1247cb2 160000 --- a/Centrifuge.Distance +++ b/Centrifuge.Distance @@ -1 +1 @@ -Subproject commit 17b8e41f5cfd6c0a0383e0cbceb7a09048b7947a +Subproject commit 1247cb2a46109bf10aea45148e6dc9b7391eb83b diff --git a/Distance.AdventureMaker/Entry.cs b/Distance.AdventureMaker/Entry.cs index 8d2a2cf..6d217cf 100644 --- a/Distance.AdventureMaker/Entry.cs +++ b/Distance.AdventureMaker/Entry.cs @@ -1,9 +1,11 @@ -using Distance.AdventureMaker.Loader; +using Centrifuge.Distance.Game; +using Distance.AdventureMaker.Loader; using Events.MainMenu; using Reactor.API.Attributes; using Reactor.API.Interfaces.Systems; using Reactor.API.Logging; using Reactor.API.Runtime.Patching; +using System; using UnityEngine; namespace Distance.AdventureMaker @@ -40,7 +42,11 @@ public void Initialize(IManager manager) private void OnMainMenuInitialized(Initialized.Data data) { + //Task.Run(CampaignLoader); + CampaignLoader.Run(); //MessageBox.Create($"Arguments:\npreview: {StartParameters.IsPreviewMode}\nfile: {StartParameters.CampaignFile}\nrcon: {StartParameters.RConPort}").Show(); + + Initialized.Unsubscribe(OnMainMenuInitialized); } } } \ No newline at end of file diff --git a/Distance.AdventureMaker/Loader/CampaignLoaderLogic.cs b/Distance.AdventureMaker/Loader/CampaignLoaderLogic.cs index c93d3c3..939b5b6 100644 --- a/Distance.AdventureMaker/Loader/CampaignLoaderLogic.cs +++ b/Distance.AdventureMaker/Loader/CampaignLoaderLogic.cs @@ -1,5 +1,6 @@ using Centrifuge.Distance.Game; using Distance.AdventureMaker.Loader.Steps; +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -15,17 +16,29 @@ public void Start() loader = new CampaignLoader(); } - public IEnumerator Run(Task.Status status) + public void Run() { foreach (LoaderTask task in loader) { - yield return Task.Wrap(task.Run(status, loader)); + Task.Run(task); } } public abstract class LoaderTask { - public abstract IEnumerator Run(Task.Status status, CampaignLoader loader); + protected readonly CampaignLoader loader; + + protected LoaderTask(CampaignLoader loader) + { + this.loader = loader; + } + + public abstract IEnumerator Run(Task.Status status); + + public static implicit operator Task.TaskDelegate(LoaderTask task) + { + return task.Run; + } } public sealed class CampaignLoader : IEnumerable @@ -44,10 +57,10 @@ public CampaignLoader() { tasks = new Queue(); - tasks.Enqueue(WorkspaceSetup = new CampaignWorkspaceSetup()); - tasks.Enqueue(Listing = new CampaignListing()); - tasks.Enqueue(Extractor = new CampaignExtractor()); - tasks.Enqueue(Importer = new CampaignImporter()); + tasks.Enqueue(WorkspaceSetup = new CampaignWorkspaceSetup(this)); + tasks.Enqueue(Listing = new CampaignListing(this)); + tasks.Enqueue(Extractor = new CampaignExtractor(this)); + tasks.Enqueue(Importer = new CampaignImporter(this)); } public IEnumerator GetEnumerator() diff --git a/Distance.AdventureMaker/Loader/Steps/CampaignExtractor.cs b/Distance.AdventureMaker/Loader/Steps/CampaignExtractor.cs index 4e29222..f971f4c 100644 --- a/Distance.AdventureMaker/Loader/Steps/CampaignExtractor.cs +++ b/Distance.AdventureMaker/Loader/Steps/CampaignExtractor.cs @@ -6,9 +6,13 @@ namespace Distance.AdventureMaker.Loader.Steps { public class CampaignExtractor : LoaderTask { - public override IEnumerator Run(Task.Status status, CampaignLoader loader) + public CampaignExtractor(CampaignLoader loader) : base(loader) { - throw new System.NotImplementedException(); + } + + public override IEnumerator Run(Task.Status status) + { + yield break; } } } diff --git a/Distance.AdventureMaker/Loader/Steps/CampaignImporter.cs b/Distance.AdventureMaker/Loader/Steps/CampaignImporter.cs index 66708d2..2b68fcb 100644 --- a/Distance.AdventureMaker/Loader/Steps/CampaignImporter.cs +++ b/Distance.AdventureMaker/Loader/Steps/CampaignImporter.cs @@ -6,9 +6,13 @@ namespace Distance.AdventureMaker.Loader.Steps { public class CampaignImporter : LoaderTask { - public override IEnumerator Run(Task.Status status, CampaignLoader loader) + public CampaignImporter(CampaignLoader loader) : base(loader) { - throw new System.NotImplementedException(); + } + + public override IEnumerator Run(Task.Status status) + { + yield break; } } } diff --git a/Distance.AdventureMaker/Loader/Steps/CampaignListing.cs b/Distance.AdventureMaker/Loader/Steps/CampaignListing.cs index d7dd77d..7cc89eb 100644 --- a/Distance.AdventureMaker/Loader/Steps/CampaignListing.cs +++ b/Distance.AdventureMaker/Loader/Steps/CampaignListing.cs @@ -6,9 +6,31 @@ namespace Distance.AdventureMaker.Loader.Steps { public class CampaignListing : LoaderTask { - public override IEnumerator Run(Task.Status status, CampaignLoader loader) + public CampaignListing(CampaignLoader loader) : base(loader) { - throw new System.NotImplementedException(); + } + + public override IEnumerator Run(Task.Status status) + { + const int max = 100; + + status.SetText("Setting up..."); + status.SetProgress(0, 1); + + yield return Task.Wait(1.5f); + + for (uint i = 1; i <= max; ++i) + { + status.SetText($"Running task {i} of {max}..."); + status.SetProgress(i, max); + + yield return Task.Wait(0.05f); + } + + status.SetText("Finishing..."); + status.SetProgress(1, 1); + + yield return Task.Wait(2.0f); } } } diff --git a/Distance.AdventureMaker/Loader/Steps/CampaignWorkspaceSetup.cs b/Distance.AdventureMaker/Loader/Steps/CampaignWorkspaceSetup.cs index f8b6390..35eefa2 100644 --- a/Distance.AdventureMaker/Loader/Steps/CampaignWorkspaceSetup.cs +++ b/Distance.AdventureMaker/Loader/Steps/CampaignWorkspaceSetup.cs @@ -1,14 +1,33 @@ using Centrifuge.Distance.Game; +using Reactor.API.Storage; using System.Collections; +using System.IO; using static Distance.AdventureMaker.Loader.CampaignLoaderLogic; namespace Distance.AdventureMaker.Loader.Steps { public class CampaignWorkspaceSetup : LoaderTask { - public override IEnumerator Run(Task.Status status, CampaignLoader loader) + DirectoryInfo LocalCampaignsFolder; + DirectoryInfo DocumentsCampaignsFolder; + + public CampaignWorkspaceSetup(CampaignLoader loader) : base(loader) + { + } + + public override IEnumerator Run(Task.Status status) { - throw new System.NotImplementedException(); + status.SetText("Creating directory structure..."); + + FileSystem fs = new FileSystem(); + + LocalCampaignsFolder = new DirectoryInfo(Path.Combine(fs.RootDirectory, "Campaigns")); + LocalCampaignsFolder.CreateIfDoesntExist(); + + DocumentsCampaignsFolder = new DirectoryInfo(Path.Combine(Resource.personalDistanceDirPath_, "Campaigns")); + DocumentsCampaignsFolder.CreateIfDoesntExist(); + + yield break; } } }