Skip to content

Commit

Permalink
Add option to set run/process mode in Co
Browse files Browse the repository at this point in the history
  • Loading branch information
Inspiaaa committed Sep 5, 2024
1 parent 237eb4f commit a07da65
Showing 1 changed file with 115 additions and 41 deletions.
156 changes: 115 additions & 41 deletions src/Co.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,98 +36,172 @@ private static Coroutine[] GetCoroutines(IEnumerator[] enumerators)
public static void Run(CoroutineBase coroutine)
=> CoroutineManager.Instance.StartCoroutine(coroutine);

public static Coroutine Run(IEnumerator coroutine)
public static Coroutine Run(
IEnumerator coroutine,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
{
Coroutine co = new Coroutine(coroutine);
Coroutine co = new Coroutine(coroutine, processMode, runMode);
CoroutineManager.Instance.StartCoroutine(co);
return co;
}

public static Coroutine Run(Func<IEnumerator> creator)
=> Run(creator());
public static Coroutine Run(
Func<IEnumerator> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
{
Coroutine co = new Coroutine(creator(), processMode, runMode);
CoroutineManager.Instance.StartCoroutine(co);
return co;
}

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


public static Coroutine Coroutine(IEnumerator enumerator)
=> new Coroutine(enumerator);
public static Coroutine Coroutine(
IEnumerator enumerator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new Coroutine(enumerator, processMode, runMode);

public static Coroutine Coroutine(Func<Coroutine, IEnumerator> creator)
=> new Coroutine(creator);
public static Coroutine Coroutine(
Func<Coroutine, IEnumerator> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new Coroutine(creator, processMode, runMode);


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

public static ParallelCoroutine Parallel(
CoProcessMode processMode,
CoRunMode runMode,
params IEnumerator[] enumerators)
=> new ParallelCoroutine(processMode, runMode, GetCoroutines(enumerators));

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

public static ParallelCoroutine Parallel(
CoProcessMode processMode,
CoRunMode runMode,
params CoroutineBase[] coroutines)
=> new ParallelCoroutine(processMode, runMode, coroutines);


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

public static SequentialCoroutine Sequence(
CoProcessMode processMode,
CoRunMode runMode,
params IEnumerator[] enumerators)
=> new SequentialCoroutine(processMode, runMode, GetCoroutines(enumerators));

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

public static SequentialCoroutine Sequence(
CoProcessMode processMode,
CoRunMode runMode,
params CoroutineBase[] coroutines)
=> new SequentialCoroutine(processMode, runMode, coroutines);


public static WaitDelayCoroutine Wait(float delay)
=> new WaitDelayCoroutine(delay);
public static WaitDelayCoroutine Wait(float delay, CoRunMode runMode = CoRunMode.Inherit)
=> new WaitDelayCoroutine(delay, runMode);


public static WaitWhileCoroutine WaitWhile(Func<Boolean> condition)
=> new WaitWhileCoroutine(condition);
public static WaitWhileCoroutine WaitWhile(
Func<Boolean> condition,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new WaitWhileCoroutine(condition, processMode, runMode);


public static WaitUntilCoroutine WaitUntil(Func<Boolean> condition)
=> new WaitUntilCoroutine(condition);
public static WaitUntilCoroutine WaitUntil(
Func<Boolean> condition,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new WaitUntilCoroutine(condition, processMode, runMode);


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<RepeatCoroutine, CoroutineBase> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(times, creator, processMode, runMode);

public static RepeatCoroutine Repeat(int times, Func<CoroutineBase> creator)
=> new RepeatCoroutine(times, coroutine => creator());
public static RepeatCoroutine Repeat(
int times,
Func<CoroutineBase> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(times, creator, processMode, runMode);

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<RepeatCoroutine, IEnumerator> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(times, coroutine => new Coroutine(creator(coroutine)), processMode, runMode);

public static RepeatCoroutine Repeat(int times, Func<IEnumerator> creator)
=> new RepeatCoroutine(times, coroutine => new Coroutine(creator()));
public static RepeatCoroutine Repeat(
int times,
Func<IEnumerator> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(times, () => new Coroutine(creator()), processMode, runMode);


public static RepeatCoroutine RepeatInfinitely(Func<RepeatCoroutine, CoroutineBase> creator)
=> new RepeatCoroutine(-1, creator);
public static RepeatCoroutine RepeatInfinitely(
Func<RepeatCoroutine, CoroutineBase> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(-1, creator, processMode, runMode);

public static RepeatCoroutine RepeatInfinitely(Func<CoroutineBase> creator)
=> new RepeatCoroutine(-1, coroutine => creator());
public static RepeatCoroutine RepeatInfinitely(
Func<CoroutineBase> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(-1, creator, processMode, runMode);

public static RepeatCoroutine RepeatInfinitely(Func<RepeatCoroutine, IEnumerator> creator)
=> new RepeatCoroutine(-1, coroutine => new Coroutine(creator(coroutine)));
public static RepeatCoroutine RepeatInfinitely(
Func<RepeatCoroutine, IEnumerator> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(-1, coroutine => new Coroutine(creator(coroutine)), processMode, runMode);

public static RepeatCoroutine RepeatInfinitely(Func<IEnumerator> creator)
=> new RepeatCoroutine(-1, coroutine => new Coroutine(creator()));
public static RepeatCoroutine RepeatInfinitely(
Func<IEnumerator> creator,
CoProcessMode processMode = CoProcessMode.Inherit,
CoRunMode runMode = CoRunMode.Inherit)
=> new RepeatCoroutine(-1, () => new Coroutine(creator()), processMode, runMode);


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 TweenCoroutine Tween(Action<Tween> setupTween)
=> new TweenCoroutine(setupTween);


public static AwaitCoroutine<T> Await<T>(Task<T> task)
=> new AwaitCoroutine<T>(task);
public static AwaitCoroutine<T> Await<T>(Task<T> task, CoRunMode runMode = CoRunMode.Inherit)
=> new AwaitCoroutine<T>(task, runMode);

public static AwaitCoroutine Await(Task task)
=> new AwaitCoroutine(task);
public static AwaitCoroutine Await(Task task, CoRunMode runMode = CoRunMode.Inherit)
=> new AwaitCoroutine(task, runMode);
}

0 comments on commit a07da65

Please sign in to comment.