Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Updated setup tasks system
Browse files Browse the repository at this point in the history
  • Loading branch information
REHERC committed Apr 27, 2021
1 parent 9fa8153 commit 6a85c98
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Centrifuge.Distance
8 changes: 7 additions & 1 deletion Distance.AdventureMaker/Entry.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}
}
}
27 changes: 20 additions & 7 deletions Distance.AdventureMaker/Loader/CampaignLoaderLogic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Centrifuge.Distance.Game;
using Distance.AdventureMaker.Loader.Steps;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -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<LoaderTask>
Expand All @@ -44,10 +57,10 @@ public CampaignLoader()
{
tasks = new Queue<LoaderTask>();

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<LoaderTask> GetEnumerator()
Expand Down
8 changes: 6 additions & 2 deletions Distance.AdventureMaker/Loader/Steps/CampaignExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
8 changes: 6 additions & 2 deletions Distance.AdventureMaker/Loader/Steps/CampaignImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
26 changes: 24 additions & 2 deletions Distance.AdventureMaker/Loader/Steps/CampaignListing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
23 changes: 21 additions & 2 deletions Distance.AdventureMaker/Loader/Steps/CampaignWorkspaceSetup.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 6a85c98

Please sign in to comment.