Scirra / Construct-feature-requests

A place to submit feature requests and suggestions for Construct.
https://www.construct.net
11 stars 1 forks source link

[SDK 2.0] Support Event sheet classes #270

Open armandoalonso opened 4 months ago

armandoalonso commented 4 months ago

Reviewed guidelines

Checked for duplicate suggestions

Summary

Currently on the SDK v1.0 api Event sheet API is supported and accessible https://www.construct.net/en/make-games/manuals/addon-sdk/runtime-reference/event-sheet-classes/eventblock https://www.construct.net/en/make-games/manuals/addon-sdk/runtime-reference/event-sheet-classes/eventsheetmanager https://www.construct.net/en/make-games/manuals/addon-sdk/runtime-reference/event-sheet-classes/eventstack https://www.construct.net/en/make-games/manuals/addon-sdk/runtime-reference/event-sheet-classes/eventstackframe

Possible workarounds or alternatives

with the new sdk being limited by encapsulation, i don't think there is a workaround with bypassing encapsulation

Proposed solution

expose the event sheet api in the IRuntime

IRuntime.GetEventSheetManager() Return the EventSheetManager that handles the event system.

IRuntime.GetEventStack() Return the EventStack. This is a shorthand for GetEventSheetManager().GetEventStack().

IRuntime.GetCurrentEventStackFrame() Return the current EventStackFrame. This is a shorthand for GetEventSheetManager().GetCurrentEventStackFrame().

IRuntime.GetCurrentEvent() Return the current EventBlock. This is a shorthand for GetEventSheetManager().GetCurrentEvent().

Why is this idea important?

Addons need this information to properly implemtent thier own loops detailed here:

https://www.construct.net/en/make-games/manuals/addon-sdk/runtime-reference/event-sheet-classes/eventblock

MyLoopingCondition()
{
    // Get necessary references
    const runtime = this._runtime;
    const eventSheetManager = runtime.GetEventSheetManager();
    const currentEvent = runtime.GetCurrentEvent();
    const solModifiers = currentEvent.GetSolModifiers();
    const eventStack = runtime.GetEventStack();

    // Get current stack frame and push new one
    const oldFrame = eventStack.GetCurrentStackFrame();
    const newFrame = eventStack.Push(currentEvent);

    for (const item of myArray)
    {
        // optionally update state here 

        // Push a copy of the current SOL
        eventSheetManager.PushCopySol(solModifiers);

        // Retrigger the current event, running a single loop iteration
        currentEvent.Retrigger(oldFrame, newFrame);

        // Pop the current SOL
        eventSheetManager.PopSol(solModifiers);
    }

    // Pop the event stack frame
    eventStack.Pop();

    // Return false since event already executed
    return false;
}

Additional remarks

No response

armandoalonso commented 4 months ago

if this also becomes available from the scripting api as a consequence of the runtime being shared that would also be pretty neat. it would allow the scripting api to mess with the flow of events.

LuanHimmlisch commented 4 months ago

@armandoalonso yeah, in theory any of the "SDK v2.0" feature request are actually scripting interface feature requests

skymen commented 4 months ago

if this also becomes available from the scripting api as a consequence of the runtime being shared that would also be pretty neat. it would allow the scripting api to mess with the flow of events.

Agreed, this would be very sick IMO