64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
const queryString = window.location.search;
|
|
const urlParams = new URLSearchParams(queryString);
|
|
const userId = urlParams.get('userid');
|
|
const gameId = urlParams.get('id');
|
|
|
|
|
|
const url = window.location.href;
|
|
const gameName = url.split('/');
|
|
const gameType = gameName[3].split('?id=');
|
|
const gameVersion = gameType[0] + '-' + gameName[4];
|
|
|
|
|
|
function submitUserData(drawingZone) {
|
|
let imageCode;
|
|
// console.log(drawingZone);
|
|
drawingZone.renderer.snapshot((image) => {
|
|
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 = 'my_drawing.png';
|
|
link.click();
|
|
document.body.removeChild(image);
|
|
imageCode = image.src;
|
|
|
|
|
|
let userData = {
|
|
'gameType': gameVersion,
|
|
'gameID': gameId,
|
|
'screenShot': imageCode,
|
|
'userId' : userId
|
|
// 'starts': formattedDateTime,
|
|
// 'game_start' : gameStartTime,
|
|
};
|
|
console.log(userData);
|
|
|
|
fetch(`https://save-game-data.teachertrainingchennai.in/saveGameData`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type' : 'application/json'
|
|
},
|
|
body: JSON.stringify(userData)
|
|
})
|
|
.then(response => {
|
|
if(response.ok){
|
|
console.log('Data Saved', response)
|
|
} else{
|
|
// console.log('Something Wrong', response)
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('An error occured', error)
|
|
});
|
|
|
|
// Clear the drawing
|
|
// graphics.clear();
|
|
});
|
|
}; |