fetch asset done

pull/1/head
ov 2023-07-23 12:29:11 +05:30
parent f350ede7ea
commit c8f57d1fa9
1 changed files with 32 additions and 65 deletions

View File

@ -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,
});