Skip to content

Commit

Permalink
namespace refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Sep 17, 2023
1 parent 93ed4c1 commit 6f37402
Show file tree
Hide file tree
Showing 36 changed files with 321 additions and 189 deletions.
9 changes: 7 additions & 2 deletions Editor/API/Attributes/BuildPhase.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System.Collections.Immutable;
#region

using System.Collections.Immutable;

#endregion

namespace nadena.dev.ndmf
{
public class BuildPhase
{
public string Name { get; }

// Prevent extension for now
internal BuildPhase(string name)
{
Expand All @@ -15,7 +20,7 @@ internal BuildPhase(string name)
public static readonly BuildPhase Generating = new BuildPhase("Generating");
public static readonly BuildPhase Transforming = new BuildPhase("Transforming");
public static readonly BuildPhase Optimizing = new BuildPhase("Optimizing");

public static readonly ImmutableList<BuildPhase> BuiltInPhases
= ImmutableList.Create(Resolving, Generating, Transforming, Optimizing);

Expand Down
8 changes: 6 additions & 2 deletions Editor/API/Attributes/ExportsPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
#region

using System;

#endregion

namespace nadena.dev.ndmf
{
Expand All @@ -13,7 +17,7 @@ namespace nadena.dev.ndmf
public sealed class ExportsPlugin : Attribute
{
public Type PluginType { get; }

public ExportsPlugin(Type pluginType)
{
PluginType = pluginType;
Expand Down
11 changes: 7 additions & 4 deletions Editor/API/Attributes/NDMFInternalEarlyPass.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
#region

using System;

#endregion

namespace nadena.dev.ndmf
{
[System.AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
internal class NDMFInternalEarlyPass : System.Attribute
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
internal class NDMFInternalEarlyPass : Attribute
{

}
}
15 changes: 10 additions & 5 deletions Editor/API/BuildContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
#region

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using nadena.dev.ndmf.reporting;
using nadena.dev.ndmf.runtime;
Expand All @@ -12,6 +15,8 @@
using Debug = UnityEngine.Debug;
using UnityObject = UnityEngine.Object;

#endregion

namespace nadena.dev.ndmf
{
/// <summary>
Expand Down Expand Up @@ -46,7 +51,7 @@ public sealed class BuildContext
/// referenced by the avatar to this container when the build completes, but in some cases it can be necessary
/// to manually save assets (e.g. when using AnimatorController builtins).
/// </summary>
public UnityEngine.Object AssetContainer { get; private set; }
public UnityObject AssetContainer { get; private set; }

private Dictionary<Type, object> _state = new Dictionary<Type, object>();
private Dictionary<Type, IExtensionContext> _extensions = new Dictionary<Type, IExtensionContext>();
Expand Down Expand Up @@ -96,8 +101,8 @@ public BuildContext(VRCAvatarDescriptor avatarDescriptor, string assetRootPath)
if (assetRootPath != null)
{
// Ensure the target directory exists
System.IO.Directory.CreateDirectory(assetRootPath);
var avatarPath = System.IO.Path.Combine(assetRootPath, avatarName) + ".asset";
Directory.CreateDirectory(assetRootPath);
var avatarPath = Path.Combine(assetRootPath, avatarName) + ".asset";
AssetDatabase.GenerateUniqueAssetPath(avatarPath);
AssetDatabase.CreateAsset(AssetContainer, avatarPath);
if (string.IsNullOrEmpty(AssetDatabase.GetAssetPath(AssetContainer)))
Expand All @@ -118,7 +123,7 @@ public BuildContext(VRCAvatarDescriptor avatarDescriptor, string assetRootPath)
sw.Stop();
}

public bool IsTemporaryAsset(UnityEngine.Object obj)
public bool IsTemporaryAsset(UnityObject obj)
{
return !EditorUtility.IsPersistent(obj)
|| AssetDatabase.GetAssetPath(obj) == AssetDatabase.GetAssetPath(AssetContainer);
Expand Down
22 changes: 13 additions & 9 deletions Editor/API/Fluent/Pass.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
#region

using System;
using System.Threading;
using NUnit.Framework;
using nadena.dev.ndmf.fluent;

#endregion

namespace nadena.dev.ndmf.fluent
namespace nadena.dev.ndmf
{
internal interface IPass
{
Expand All @@ -25,29 +29,29 @@ internal class AnonymousPass : IPass

internal bool IsPhantom { get; set; }
bool IPass.IsPhantom => IsPhantom;

public AnonymousPass(string qualifiedName, string displayName, InlinePass execute)
{
QualifiedName = qualifiedName;
DisplayName = displayName;
_executor = execute;
}

public void Execute(BuildContext context)
{
_executor(context);
}
}

public abstract class Pass<T> : IPass where T : Pass<T>, new()
{
private static Lazy<T> _instance = new Lazy<T>(() => new T(),
private static Lazy<T> _instance = new Lazy<T>(() => new T(),
LazyThreadSafetyMode.ExecutionAndPublication);

public static T Instance => _instance.Value;

PassKey IPass.PassKey => new PassKey(QualifiedName);

public virtual string QualifiedName => typeof(T).FullName;
public virtual string DisplayName => typeof(T).Name;
bool IPass.IsPhantom => false;
Expand Down
6 changes: 3 additions & 3 deletions Editor/API/Fluent/PassKey.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace nadena.dev.ndmf.fluent
namespace nadena.dev.ndmf
{
internal class PassKey
{
public readonly string QualifiedName;

public PassKey(string qualifiedName)
{
QualifiedName = qualifiedName;
}

public override string ToString()
{
return QualifiedName;
Expand Down
25 changes: 15 additions & 10 deletions Editor/API/Fluent/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
#region

using System;
using System.Threading;
using nadena.dev.ndmf;
using nadena.dev.ndmf.fluent;

#endregion

namespace nadena.dev.ndmf.fluent
namespace nadena.dev.ndmf
{
internal interface IPlugin
{
Expand All @@ -11,20 +15,21 @@ internal interface IPlugin

void Configure(PluginInfo info);
}
public abstract class Plugin<T> : IPlugin where T: Plugin<T>, new()

public abstract class Plugin<T> : IPlugin where T : Plugin<T>, new()
{
private static object _lock = new object();
private static Lazy<Plugin<T>> _instance = new Lazy<Plugin<T>>(() => new T(),

private static Lazy<Plugin<T>> _instance = new Lazy<Plugin<T>>(() => new T(),
LazyThreadSafetyMode.ExecutionAndPublication);

public static Plugin<T> Instance => _instance.Value;

private PluginInfo _info;

public virtual string QualifiedName => typeof(T).FullName;
public virtual string DisplayName => QualifiedName;

void IPlugin.Configure(PluginInfo info)
{
_info = info;
Expand All @@ -37,7 +42,7 @@ void IPlugin.Configure(PluginInfo info)
_info = null;
}
}

protected abstract void Configure();

protected Sequence InPhase(BuildPhase phase)
Expand Down
11 changes: 8 additions & 3 deletions Editor/API/Fluent/PluginInfo.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using nadena.dev.ndmf.model;
#region

namespace nadena.dev.ndmf.fluent
using nadena.dev.ndmf.fluent;
using nadena.dev.ndmf.model;

#endregion

namespace nadena.dev.ndmf
{
internal class PluginInfo
{
private readonly SolverContext _solverContext;
private readonly IPlugin _plugin;
private int sequenceIndex = 0;

public PluginInfo(SolverContext solverContext, IPlugin plugin)
{
_solverContext = solverContext;
Expand Down
32 changes: 22 additions & 10 deletions Editor/API/Fluent/Sequence/Constraints.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
#region

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using nadena.dev.ndmf.model;

#endregion

namespace nadena.dev.ndmf.fluent
{
public sealed partial class Sequence
Expand All @@ -15,10 +19,12 @@ private void OnNewPass(SolverPass pass)
{
dep(pass);
}

_pendingDependencies.Clear();
}

public Sequence BeforePlugin(string QualifiedName, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)

public Sequence BeforePlugin(string QualifiedName, [CallerFilePath] string sourceFile = "",
[CallerLineNumber] int sourceLine = 0)
{
_solverContext.Constraints.Add(new Constraint()
{
Expand All @@ -32,12 +38,14 @@ public Sequence BeforePlugin(string QualifiedName, [CallerFilePath] string sourc
return this;
}

public Sequence BeforePlugin<T>(T plugin, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : fluent.Plugin<T>, new()
public Sequence BeforePlugin<T>(T plugin, [CallerFilePath] string sourceFile = "",
[CallerLineNumber] int sourceLine = 0) where T : Plugin<T>, new()
{
return BeforePlugin(plugin.QualifiedName, sourceFile, sourceLine);
}

public Sequence AfterPlugin(string qualifiedName, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)
public Sequence AfterPlugin(string qualifiedName, [CallerFilePath] string sourceFile = "",
[CallerLineNumber] int sourceLine = 0)
{
_solverContext.Constraints.Add(new Constraint()
{
Expand All @@ -51,12 +59,14 @@ public Sequence AfterPlugin(string qualifiedName, [CallerFilePath] string source
return this;
}

public Sequence AfterPlugin<T>(T plugin, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : Plugin<T>, new()
public Sequence AfterPlugin<T>(T plugin, [CallerFilePath] string sourceFile = "",
[CallerLineNumber] int sourceLine = 0) where T : Plugin<T>, new()
{
return AfterPlugin(plugin.QualifiedName, sourceFile, sourceLine);
}

public Sequence WaitFor<T>(T pass, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : fluent.Pass<T>, new()

public Sequence WaitFor<T>(T pass, [CallerFilePath] string sourceFile = "",
[CallerLineNumber] int sourceLine = 0) where T : Pass<T>, new()
{
_pendingDependencies.Add(nextPass =>
{
Expand All @@ -73,7 +83,8 @@ public Sequence AfterPlugin(string qualifiedName, [CallerFilePath] string source
return this;
}

public Sequence AfterPass(string qualifiedName, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)
public Sequence AfterPass(string qualifiedName, [CallerFilePath] string sourceFile = "",
[CallerLineNumber] int sourceLine = 0)
{
_pendingDependencies.Add(nextPass =>
{
Expand All @@ -90,7 +101,8 @@ public Sequence AfterPass(string qualifiedName, [CallerFilePath] string sourceFi
return this;
}

public Sequence AfterPass<T>(T pass, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : Pass<T>, new()
public Sequence AfterPass<T>(T pass, [CallerFilePath] string sourceFile = "",
[CallerLineNumber] int sourceLine = 0) where T : Pass<T>, new()
{
return AfterPass(pass.QualifiedName, sourceFile, sourceLine);
}
Expand Down
Loading

0 comments on commit 6f37402

Please sign in to comment.