Skip to content

Commit

Permalink
Migrate code to Godot 4
Browse files Browse the repository at this point in the history
- Improve code formatting using latest C# features now supported by the latest .NET version
- Update logic for Godot 4
  • Loading branch information
Inspiaaa committed Sep 4, 2024
1 parent 4267ea6 commit b8d4e62
Show file tree
Hide file tree
Showing 15 changed files with 572 additions and 652 deletions.
153 changes: 78 additions & 75 deletions src/Co.cs
Original file line number Diff line number Diff line change
@@ -1,126 +1,129 @@
using Godot;
using System;
using System.Collections;
using System.Threading.Tasks;
using Godot;

// Hierarchical Coroutines v1.0 for Godot
// by @Inspiaaa

namespace HCoroutines
namespace HCoroutines;

/// <summary>
/// Class that allows for easy access to the standard coroutine types.
/// </summary>
public static class Co
{
/// <summary>
/// Class that allows for easy access to the standard coroutine types.
/// </summary>
public static class Co
private static Coroutine[] GetCoroutines(IEnumerator[] enumerators)
{
private static Coroutine[] GetCoroutines(IEnumerator[] enumerators)
{
Coroutine[] coroutines = new Coroutine[enumerators.Length];

for (int i = 0; i < enumerators.Length; i++)
{
coroutines[i] = new Coroutine(enumerators[i]);
}
Coroutine[] coroutines = new Coroutine[enumerators.Length];

return coroutines;
for (int i = 0; i < enumerators.Length; i++)
{
coroutines[i] = new Coroutine(enumerators[i]);
}

public static float DeltaTime => CoroutineManager.Instance.DeltaTime;
return coroutines;
}

public static float DeltaTime => CoroutineManager.Instance.DeltaTime;
public static double DeltaTimeDouble => CoroutineManager.Instance.DeltaTimeDouble;

public static void Run(CoroutineBase coroutine)
=> CoroutineManager.Instance.StartCoroutine(coroutine);

public static Coroutine Run(IEnumerator coroutine)
{
Coroutine co = new Coroutine(coroutine);
CoroutineManager.Instance.StartCoroutine(co);
return co;
}
public static void Run(CoroutineBase coroutine)
=> CoroutineManager.Instance.StartCoroutine(coroutine);

public static Coroutine Run(Func<IEnumerator> creator)
=> Run(creator());
public static Coroutine Run(IEnumerator coroutine)
{
Coroutine co = new Coroutine(coroutine);
CoroutineManager.Instance.StartCoroutine(co);
return co;
}

public static Coroutine Run(Func<Coroutine, IEnumerator> creator)
{
Coroutine coroutine = new Coroutine(creator);
CoroutineManager.Instance.StartCoroutine(coroutine);
return coroutine;
}
public static Coroutine Run(Func<IEnumerator> creator)
=> Run(creator());

public static Coroutine Run(Func<Coroutine, IEnumerator> creator)
{
Coroutine coroutine = new Coroutine(creator);
CoroutineManager.Instance.StartCoroutine(coroutine);
return coroutine;
}

public static Coroutine Coroutine(IEnumerator enumerator)
=> new Coroutine(enumerator);

public static Coroutine Coroutine(Func<Coroutine, IEnumerator> creator)
=> new Coroutine(creator);
public static Coroutine Coroutine(IEnumerator enumerator)
=> new Coroutine(enumerator);

public static Coroutine Coroutine(Func<Coroutine, IEnumerator> creator)
=> new Coroutine(creator);

public static ParallelCoroutine Parallel(params IEnumerator[] enumerators)
=> new ParallelCoroutine(GetCoroutines(enumerators));

public static ParallelCoroutine Parallel(params CoroutineBase[] coroutines)
=> new ParallelCoroutine(coroutines);
public static ParallelCoroutine Parallel(params IEnumerator[] enumerators)
=> new ParallelCoroutine(GetCoroutines(enumerators));

public static ParallelCoroutine Parallel(params CoroutineBase[] coroutines)
=> new ParallelCoroutine(coroutines);

public static SequentialCoroutine Sequence(params IEnumerator[] enumerators)
=> new SequentialCoroutine(GetCoroutines(enumerators));

public static SequentialCoroutine Sequence(params CoroutineBase[] coroutines)
=> new SequentialCoroutine(coroutines);
public static SequentialCoroutine Sequence(params IEnumerator[] enumerators)
=> new SequentialCoroutine(GetCoroutines(enumerators));

public static SequentialCoroutine Sequence(params CoroutineBase[] coroutines)
=> new SequentialCoroutine(coroutines);

public static WaitDelayCoroutine Wait(float delay)
=> new WaitDelayCoroutine(delay);

public static WaitDelayCoroutine Wait(float delay)
=> new WaitDelayCoroutine(delay);

public static WaitWhileCoroutine WaitWhile(Func<Boolean> condition)
=> new WaitWhileCoroutine(condition);

public static WaitWhileCoroutine WaitWhile(Func<Boolean> condition)
=> new WaitWhileCoroutine(condition);

public static WaitUntilCoroutine WaitUntil(Func<Boolean> condition)
=> new WaitUntilCoroutine(condition);

public static WaitUntilCoroutine WaitUntil(Func<Boolean> condition)
=> new WaitUntilCoroutine(condition);

public static WaitForSignalCoroutine WaitForSignal(Godot.Object obj, string signal)
=> new WaitForSignalCoroutine(obj, signal);

public static WaitForSignalCoroutine WaitForSignal(GodotObject obj, string signal)
=> new WaitForSignalCoroutine(obj, signal);


public static RepeatCoroutine Repeat(int times, Func<RepeatCoroutine, CoroutineBase> creator)
=> new RepeatCoroutine(times, creator);

public static RepeatCoroutine Repeat(int times, Func<CoroutineBase> creator)
=> new RepeatCoroutine(times, coroutine => creator());
public static RepeatCoroutine Repeat(int times, Func<RepeatCoroutine, CoroutineBase> creator)
=> new RepeatCoroutine(times, creator);

public static RepeatCoroutine Repeat(int times, Func<RepeatCoroutine, IEnumerator> creator)
=> new RepeatCoroutine(times, coroutine => new Coroutine(creator(coroutine)));
public static RepeatCoroutine Repeat(int times, Func<CoroutineBase> creator)
=> new RepeatCoroutine(times, coroutine => creator());

public static RepeatCoroutine Repeat(int times, Func<IEnumerator> creator)
=> new RepeatCoroutine(times, coroutine => new Coroutine(creator()));
public static RepeatCoroutine Repeat(int times, Func<RepeatCoroutine, IEnumerator> creator)
=> new RepeatCoroutine(times, coroutine => new Coroutine(creator(coroutine)));

public static RepeatCoroutine Repeat(int times, Func<IEnumerator> creator)
=> new RepeatCoroutine(times, coroutine => new Coroutine(creator()));

public static RepeatCoroutine RepeatInfinitely(Func<RepeatCoroutine, CoroutineBase> creator)
=> new RepeatCoroutine(-1, creator);

public static RepeatCoroutine RepeatInfinitely(Func<CoroutineBase> creator)
=> new RepeatCoroutine(-1, coroutine => creator());
public static RepeatCoroutine RepeatInfinitely(Func<RepeatCoroutine, CoroutineBase> creator)
=> new RepeatCoroutine(-1, creator);

public static RepeatCoroutine RepeatInfinitely(Func<RepeatCoroutine, IEnumerator> creator)
=> new RepeatCoroutine(-1, coroutine => new Coroutine(creator(coroutine)));
public static RepeatCoroutine RepeatInfinitely(Func<CoroutineBase> creator)
=> new RepeatCoroutine(-1, coroutine => creator());

public static RepeatCoroutine RepeatInfinitely(Func<IEnumerator> creator)
=> new RepeatCoroutine(-1, coroutine => new Coroutine(creator()));
public static RepeatCoroutine RepeatInfinitely(Func<RepeatCoroutine, IEnumerator> creator)
=> new RepeatCoroutine(-1, coroutine => new Coroutine(creator(coroutine)));

public static RepeatCoroutine RepeatInfinitely(Func<IEnumerator> creator)
=> new RepeatCoroutine(-1, coroutine => new Coroutine(creator()));

public static TweenCoroutine Tween(Action<SceneTreeTween> setupTween)
=> new TweenCoroutine(setupTween);

public static TweenCoroutine Tween(Func<Tween> createTween)
=> new TweenCoroutine(createTween);

// TODO: Create additional methods for creating Tween Coroutines (e.g. create Tween on Manager, setup via Action,
// or bound to a node)

public static AwaitCoroutine<T> Await<T>(Task<T> task)
=> new AwaitCoroutine<T>(task);

public static AwaitCoroutine Await(Task task)
=> new AwaitCoroutine(task);
}
public static AwaitCoroutine<T> Await<T>(Task<T> task)
=> new AwaitCoroutine<T>(task);

public static AwaitCoroutine Await(Task task)
=> new AwaitCoroutine(task);
}
Loading

0 comments on commit b8d4e62

Please sign in to comment.