Skip to content

Commit

Permalink
Add register button
Browse files Browse the repository at this point in the history
  • Loading branch information
gparant committed Dec 6, 2022
1 parent 26b5081 commit f05ce26
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 22 additions & 6 deletions src/onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
/// <reference types="@workadventure/iframe-api-typings/iframe_api" />

console.log('Onboarding Script started successfully');
console.info('Onboarding Script started successfully');

WA.onInit().then(() => {

if(canRegister()){
addRegisterButton();
}

if(!WA.player.state.tutorialDone){
openTutorial();
}
else if(canRegister()){
console.info('Open the funnel');
openFunnel(0);
}
WA.player.state.onVariableChange('tutorialDone').subscribe((tutorialDone) => {
/*WA.player.state.onVariableChange('tutorialDone').subscribe(() => {
console.info('Tutorial is done, open the funnel');
if(!canRegister(tutorialDone as boolean)) return;
if(!canRegister()) return;
openFunnel();
});*/

WA.player.state.onVariableChange('isRegistered').subscribe(() => {
WA.ui.actionBar.removeButton('register-btn');
});
}).catch((err) => {
console.error('Onboarding Script initialisation error => ', err);
})

const canRegister = (tutorialDone = false) => {
return (!WA.player.state.tutorialDone || tutorialDone) && !WA.player.isLogged && !WA.player.state.isRegistered;
const canRegister = () => {
return !WA.player.isLogged && !WA.player.state.isRegistered;
}

const openTutorial = () => {
console.info('Open the tutorial');
// @ts-ignore
WA.ui.modal.openModal({
title: "Tutorial",
src: 'https://workadventure.github.io/scripting-api-extra/tutorialv1.html',
allow: "fullscreen; clipboard-read; clipboard-write",
allowApi: true,
Expand All @@ -41,11 +51,17 @@ export const openFunnel = (TIME_TO_OPEN_FUNNEL = 20000) => {
WA.ui.modal.openModal({
src: `https://workadventu.re/funnel/connection?roomUrl=${encodeURI(WA.room.id)}`,
allow: "fullscreen",
tiltle: "Subscription",
title: "Subscription",
allowApi: true,
position: "center"
});
}, TIME_TO_OPEN_FUNNEL);
}

const addRegisterButton = () => {
WA.ui.actionBar.addButton('register-btn', 'Register', () => {
openFunnel();
});
}

export {}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@
"tailwindcss" "^3.1.8"

"@workadventure/iframe-api-typings@^1.11.2":
"integrity" "sha512-j911YkR4qfIV+5xug1j6Xxfw2KSiR4MtubS4r0fYVbfPmr0xQeLw9xtmSJXfDldLpO19g2DLRvK5mbVHXIH57g=="
"resolved" "https://registry.npmjs.org/@workadventure/iframe-api-typings/-/iframe-api-typings-1.14.3.tgz"
"version" "1.14.3"
"integrity" "sha512-pWLgLViLMsf3YJoBOB17To/YLPSI/rlrB2pfInaWP7tdNniutxBePJURRVvgLNHFuEBHcjbGyxmiwwPT62XzJg=="
"resolved" "https://registry.npmjs.org/@workadventure/iframe-api-typings/-/iframe-api-typings-1.14.7.tgz"
"version" "1.14.7"
dependencies:
"rxjs" "^6.6.3"
"zod" "^3.14.3"
Expand Down

0 comments on commit f05ce26

Please sign in to comment.