Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix context switch workflow and pipeline calls order #703

Merged
merged 12 commits into from
Mar 26, 2025

Conversation

DevNatan
Copy link
Owner

@DevNatan DevNatan commented Mar 21, 2025

I noticed that in samples, debugs we're displaying the wrong values for "Viewer added to..." and "Viewer removed from...", when switching contexts the context shown in "Viewer added" and "Viewer removed" debugs were the same (which is wrong);

  • Added a constraint to require that calls to getPreviousContext must ensure that isSwitching to true in Viewer API
  • Fixed PlatformView#onViewerAdded and pipeline VIEWER_ADDED/VIEWER_REMOVED calls order.
  • Fixed the target context when switching from a context to another. Now "current context" is correctly set to the previous context when switching from a context to another and only set to the next one when it is fully rendered and ready to use.
  • Introduced Viewer API getCurrentContext that ensures context consistency when switching from a context to another.
  • Fixed isSwitching reset once a player is switched successfully to the next context.
  • Now onViewerAdded is also called when switching back to a context (onViewerAdded -> onResume).

With all the changes, when switching back to a context (context.back()) state values of that context will be kept. I'll address it in the next PR. For now you need to manually reset (if you want) via onResume.

Fixes #696; Fixes #658; Fixes #657; Fixes #649; Fixes #647; Fixes #383

@DevNatan DevNatan changed the title Fix context switch by changing how Fix context switch workflow Mar 21, 2025
@DevNatan DevNatan changed the title Fix context switch workflow Fix context switch workflow and pipeline calls order Mar 21, 2025
Comment on lines +88 to +94
for (final Viewer viewer : renderContext.getIndexedViewers().values()) {
setupViewer(viewer, renderContext, root);
}

final Viewer viewer = renderContext.getViewer();
if (viewer != null) setupViewer(viewer, renderContext, root);

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code opens support to include players in the context of another player without needing to added then through open(...).

@DevNatan DevNatan self-assigned this Mar 21, 2025
@DevNatan DevNatan added the bug Something isn't working label Mar 21, 2025

@Override
public void onFirstRender(@NotNull RenderContext render) {
render.slot(1, new ItemStack(Material.DIAMOND)).onClick(click -> click.openForPlayer(SimplePagination.class));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we also should test the other way around, when this view is opened by another without using back.

@DevNatan DevNatan merged commit ce5a84e into main Mar 26, 2025
5 of 6 checks passed
@DevNatan DevNatan deleted the fix/register-pipeline branch March 26, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment