LethalCompanyCommunity / LethalAPI.Core

A core modding library for Lethal Company
GNU Lesser General Public License v3.0
24 stars 6 forks source link

Add MEC Coroutines and Timings API #11

Closed Redforce04 closed 10 months ago

Redforce04 commented 10 months ago

Note: This is the free version, and we have permission to use it in the api.

KrayOristine commented 10 months ago

What would this pr have use for?

Redforce04 commented 10 months ago

What would this pr have use for?

Its an "asynchronous" Timing API without using Asynchronous. This can be used by us and other developers to make more effective coroutines, and do various functions.

For Instance:

public static void RunThings()
{
    Timing.CallDelayed(5f, () => {
        Log.Debug("This will be called after 5 seconds.");
    });
}

Or you can use the custom coroutines.

private CoroutineHandle _coolCoroutine;
public static void DoCoolCoroutine()
{
    _coolCoroutine = Timing.RunCoroutine(DoCoroutine, "My Cool Coroutine");
}

public static void StopCoroutine()
{
    // Kill a coroutine by the handle.
    Timing.KillAllCoroutines(_coolCoroutine);

    // Kill a coroutine by the tag.
    Timing.KillAllCoroutine("My Cool Coroutine");

    // Kill all running coroutines.
    Timing.KillAllCoroutine();
}

public static IEnumerator<float> DoCoroutine()
{
    while(true)
    {
         Log.Debug("1 seconds waited.");
         yield return Timing.WaitForSeconds(1f);
         yield return Timing.WaitOneFrame(); // waits one frame.
    }
    CouroutineHandle handle = Timing.WaitForSeconds(12f, () => {
        Log.Debug("Wait for me!");
    });
    // Won't continue until the "Wait for me!" is displayed. - Like Thread.Join
    yield return Timing.WaitUntilDone(handle);
}
Redforce04 commented 10 months ago

I didn't mean to close this lol

KrayOristine commented 10 months ago

Look goods. Let hold it for now until it is needed.

Redforce04 commented 10 months ago

Not all developers will use this, but some would find it very helpful. I personally would like to use it, and I feel like it's best to add it to the api, so all our modders have access to the tool.

It's in the MEC namespace, so modders who have previously used this tool, can use it normally.

Redforce04 commented 10 months ago

Look goods. Let hold it for now until it is needed.

I need it for the main api for some other features

KrayOristine commented 10 months ago

Look goods. Let hold it for now until it is needed.

I need it for the main api for some other features

I think we might need to put it in ./MEC/**

KrayOristine commented 10 months ago

ok, every seem so good so far, approved