diff --git a/public/saveGameData.js b/public/saveGameData.js index 6c17ece..fa0c9ef 100644 --- a/public/saveGameData.js +++ b/public/saveGameData.js @@ -1,7 +1,7 @@ const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const userId = urlParams.get('userid'); -const gameId = urlParams.get('id'); +let gameId; let startTime = Date.now(); @@ -9,9 +9,20 @@ let startTime = Date.now(); const url = window.location.href; const gameName = url.split('/'); const gameType = gameName[3].split('?id='); -const gameVersion = gameType[0] + '-' + gameName[4]; +let gameVersion; +if(gameType[0] == "guided-tracing"){ + gameVersion = gameType[0].split('?')[0]; + gameId = gameName[4]; +} else if(gameName.length == 5){ + gameVersion = gameName[3]; + gameId = urlParams.get('id'); +}else if(gameName.length == 6){ + gameVersion = gameType[0] + '-' + gameName[4]; + gameId = urlParams.get('id'); +} + function submitUserData(drawingZone) { @@ -22,7 +33,7 @@ function submitUserData(drawingZone) { let imageCode; let gameScore; - let scoreTotal=0; + if(scoreTotal){ gameScore = scoreTotal; }else{ @@ -45,6 +56,21 @@ function submitUserData(drawingZone) { link.click(); document.body.removeChild(image); imageCode = image.src; + }else if( gameType[0] == "guided-tracing"){ + // submitButton.setVisible(true); + // snapshotButton.setVisible(true); + // customCursor.setVisible(true); + image.style.width = '160px'; + image.style.height = '120px'; + image.style.paddingLeft = '2px'; + document.body.appendChild(image); + // Download the snapshot as an image + const link = document.createElement('a'); + link.href = image.src; + link.download = `guided-tracing-${gameId}.png`; + link.click(); + document.body.removeChild(image); + imageCode = image.src; } @@ -59,7 +85,7 @@ function submitUserData(drawingZone) { // 'starts': formattedDateTime, // 'game_start' : gameStartTime, }; - // console.log(userData); + console.log(userData); fetch(`https://phaser-game-api.s38.siliconpin.com/save-data`, { method: 'POST', diff --git a/src/pages/cross/cross_phonics_v1.astro b/src/pages/cross/cross_phonics_v1.astro index 32c8bee..4200d40 100644 --- a/src/pages/cross/cross_phonics_v1.astro +++ b/src/pages/cross/cross_phonics_v1.astro @@ -79,10 +79,12 @@ import Layout from "../../layouts/Layout.astro"; + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -