From c8f57d1fa9f2d8b82900cd5ec900da736f81c3db Mon Sep 17 00:00:00 2001 From: ov Date: Sun, 23 Jul 2023 12:29:11 +0530 Subject: [PATCH] fetch asset done --- src/pages/drag/index.astro | 97 +++++++++++++------------------------- 1 file changed, 32 insertions(+), 65 deletions(-) diff --git a/src/pages/drag/index.astro b/src/pages/drag/index.astro index 5f8e207..8c001a5 100644 --- a/src/pages/drag/index.astro +++ b/src/pages/drag/index.astro @@ -97,11 +97,17 @@ const params = new URLSearchParams(window.location.search); const data = fetch(`https://management.beanstalkedu.com/items/game_drag/${encodeURIComponent(paramsID)}`) .then(response => response.json()) .then(({data}) => { - console.log("finding:: data",data) - const {left_image1, right_image1} = data + // console.log("finding:: data",data) + const {left_image1, left_image2, left_image3, left_image4, right_image1, right_image2, right_image3, right_image4} = data assetsList.left_image1 = "https://management.beanstalkedu.com/assets/" + left_image1 + assetsList.left_image2 = "https://management.beanstalkedu.com/assets/" + left_image2 + assetsList.left_image3 = "https://management.beanstalkedu.com/assets/" + left_image3 + assetsList.left_image4 = "https://management.beanstalkedu.com/assets/" + left_image4 assetsList.right_image1 = "https://management.beanstalkedu.com/assets/" + right_image1 + assetsList.right_image2 = "https://management.beanstalkedu.com/assets/" + right_image2 + assetsList.right_image3 = "https://management.beanstalkedu.com/assets/" + right_image3 + assetsList.right_image4 = "https://management.beanstalkedu.com/assets/" + right_image4 const config = { type: Phaser.AUTO, @@ -127,62 +133,6 @@ class MyGame extends Phaser.Scene { super(); } preload() { - // const params = new URLSearchParams(window.location.search); - // const paramsID = params.get('id'); - // fetch(`https://management.beanstalkedu.com/items/game_drag/${encodeURIComponent(paramsID)}`) - // .then(response => response.json()) - // .then(data => { - // console.log(data.data); - // // let ttt="ttt"; - - // }) - // .catch(error => { - // console.error('Error fetching initial data:', error); - // }); - - async function getAssetDetails(){ - const params = new URLSearchParams(window.location.search); - const paramsID = params.get('id'); - try { - const response = await fetch(`https://management.beanstalkedu.com/items/game_drag/${encodeURIComponent(paramsID)}`, { - // method: "POST", // or 'PUT' - // headers: { - // "Content-Type": "application/json", - // }, - body: JSON.stringify(data), - }); - - const result = await response.json(); - console.log("Success:", result); - // this.load.image("bg", '/assets/background.jpg'); - } catch (error) { - console.error("Error:", error); - } - } -// console.log(getAssetDetails()); -// getAssetDetails(); - -// async function postJSON(data) { -// try { -// const response = await fetch(`https://management.beanstalkedu.com/items/game_drag/${encodeURIComponent(paramsID)}`, { -// method: "POST", // or 'PUT' -// headers: { -// "Content-Type": "application/json", -// }, -// body: JSON.stringify(data), -// }); - -// const result = await response.json(); -// console.log("Success:", result); -// } catch (error) { -// console.error("Error:", error); -// } -// } - -// const data = { username: "example" }; -// postJSON(data); - - var progressBar = this.add.graphics(); var progressBox = this.add.graphics(); @@ -249,25 +199,42 @@ class MyGame extends Phaser.Scene { this.load.image("tick", '/assets/tick.png'); this.load.image("bg", '/assets/background.jpg'); - this.load.image("target1", assetsList.right_image1); - this.load.image("target2", '/assets/hay.png'); - this.load.image("target3", '/assets/mat.png'); - this.load.image("target4", '/assets/star.png'); + // this.load.image("target1", assetsList.right_image1); + // this.load.image("target2", '/assets/hay.png'); + // this.load.image("target3", '/assets/mat.png'); + // this.load.image("target4", '/assets/star.png'); this.load.image("border", '/assets/squar.png'); + this.load.spritesheet("target1", assetsList.right_image1,{ + frameWidth: 100, + frameHeight: 100, + }); + this.load.spritesheet("target2", assetsList.right_image2,{ + frameWidth: 100, + frameHeight: 100, + }); + this.load.spritesheet("target3", assetsList.right_image3,{ + frameWidth: 100, + frameHeight: 100, + }); + this.load.spritesheet("target4", assetsList.right_image4,{ + frameWidth: 100, + frameHeight: 100, + }); + this.load.spritesheet("blocks1", assetsList.left_image1,{ frameWidth: 100, frameHeight: 100, }); - this.load.spritesheet("blocks2", '/assets/jar.png', { + this.load.spritesheet("blocks2", assetsList.left_image2, { frameWidth: 100, frameHeight: 100, }); - this.load.spritesheet("blocks3", '/assets/jam.png', { + this.load.spritesheet("blocks3", assetsList.left_image3, { frameWidth: 100, frameHeight: 100, }); - this.load.spritesheet("blocks4", '/assets/day.png', { + this.load.spritesheet("blocks4", assetsList.left_image4, { frameWidth: 100, frameHeight: 100, });