diff --git a/Scripts/modules/clicktest.js b/Scripts/modules/clicktest.js new file mode 100644 index 0000000..856fa63 --- /dev/null +++ b/Scripts/modules/clicktest.js @@ -0,0 +1,82 @@ +document.addEventListener('DOMContentLoaded', () => { + const gameTemplate = document.getElementById('test').content; + const gameContainer = document.querySelector('.click-test-content'); + + // Static mapping of game names and universe IDs + const gamesData = [ + { universeId: '4922186765', name: 'Game Name 1' }, + { universeId: 'anotherUniverseId', name: 'Another Game' }, + { universeId: 'anotherUniverseId2', name: 'Yet Another Game' } + ]; + + const fetchAndDisplayGame = (game) => { + const apiUrl = `https://games.roproxy.com/v1/games?universeIds=${game.universeId}`; + + fetch(apiUrl) + .then(response => { + if (!response.ok) { + throw new Error(`Network response was not ok: ${response.statusText}`); + } + return response.json(); + }) + .then(data => { + if (!data.data || !Array.isArray(data.data)) { + throw new Error('Invalid data format received from API'); + } + + data.data.forEach(gameData => { + const gameClone = document.importNode(gameTemplate, true); + + // Fetch game icon (image) + const imgUrl = `https://thumbnails.roproxy.com/v1/games/icons?universeIds=${game.universeId}&returnPolicy=PlaceHolder&size=256x256&format=Png&isCircular=false`; + + fetch(imgUrl) + .then(response => { + if (!response.ok) { + throw new Error(`Network response was not ok: ${response.statusText}`); + } + return response.json(); + }) + .then(data => { + if (data && data.data && data.data[0] && data.data[0].imageUrl) { + const imageUrl = data.data[0].imageUrl; + gameClone.querySelector('.icon').src = imageUrl; + } else { + console.error('Invalid image data received from API'); + } + + // Add click event listener to the game element + gameClone.addEventListener('click', () => { + const customPageUrl = `../games/game.html?gameName=${encodeURIComponent(game.name)}`; + window.location.href = customPageUrl; + }); + + // Append the clone to the container + gameContainer.appendChild(gameClone); + }) + .catch(error => { + console.error('Error fetching the thumbnail:', error); + }); + + // Set other game details + gameClone.querySelector('.game-title').textContent = gameData.name || 'No title available'; + gameClone.querySelector('.game-desc').textContent = gameData.description || 'No description available'; + + // Use static text for other details if needed + gameClone.querySelector('.active').textContent = `Active: ${gameData.playing || 'N/A'}`; + gameClone.querySelector('.owner').textContent = `Owner: ${gameData.creator && gameData.creator.name ? gameData.creator.name : 'N/A'}`; + gameClone.querySelector('.likes').textContent = `Likes: ${gameData.likes || 'N/A'}`; + }); + }) + .catch(error => { + console.error('Error fetching the game data:', error); + const errorMessage = document.createElement('p'); + errorMessage.textContent = 'Error fetching the game data. Please try again later.'; + gameContainer.appendChild(errorMessage); + }); + }; + + gamesData.forEach(game => { + fetchAndDisplayGame(game); + }); +}); \ No newline at end of file diff --git a/Scripts/modules/test.js b/Scripts/modules/test.js index 0e1e647..5bc5eec 100644 --- a/Scripts/modules/test.js +++ b/Scripts/modules/test.js @@ -8,6 +8,7 @@ document.addEventListener('DOMContentLoaded', () => { // Function to fetch and display game data for a single universe ID const fetchAndDisplayGame = (universeId) => { const apiUrl = `https://games.roproxy.com/v1/games?universeIds=${universeId}`; + console.log('Fetching data from API URL:', apiUrl); fetch(apiUrl) @@ -27,14 +28,41 @@ document.addEventListener('DOMContentLoaded', () => { data.data.forEach(game => { const gameClone = document.importNode(gameTemplate, true); + // Fetch game icon (image) + const imgUrl = `https://thumbnails.roproxy.com/v1/games/icons?universeIds=${universeId}&returnPolicy=PlaceHolder&size=256x256&format=Png&isCircular=false`; + + fetch(imgUrl) + .then(response => { + if (!response.ok) { + throw new Error(`Network response was not ok: ${response.statusText}`); + } + return response.json(); // Parse JSON only if response is OK + }) + .then(data => { + console.log('thumb API response data:', data); + + if (data && data.data && data.data[0] && data.data[0].imageUrl) { + const imageUrl = data.data[0].imageUrl; + // Set the image source here, after fetching the image data + gameClone.querySelector('.icon').src = imageUrl; + } else { + console.error('Invalid image data received from API'); + } + + // After setting the image, append the clone to the container + gameContainer.appendChild(gameClone); + }) + .catch(error => { + console.error('Error fetching the thumbnail:', error); + }); + + // Set other game details here gameClone.querySelector('.game-title').textContent = game.name || 'No title available'; - gameClone.querySelector('.icon').src = `https://thumbnails.roblox.com/v1/games/icons?universeIds=${universeId}&returnPolicy=PlaceHolder&size=256x256&format=Png&isCircular=false`; gameClone.querySelector('.game-desc').textContent = game.description || 'No description available'; gameClone.querySelector('.active').textContent = `active: ${game.playing || 'N/A'}`; gameClone.querySelector('.owner').textContent = `owner: ${game.creator && game.creator.name ? game.creator.name : 'N/A'}`; gameClone.querySelector('.likes').textContent = `likes: ${game.likes || 'N/A'}`; - gameContainer.appendChild(gameClone); }); }) .catch(error => { diff --git a/games.html b/games.html index 90e359c..564c610 100644 --- a/games.html +++ b/games.html @@ -231,7 +231,7 @@

likes: ?

- +


@@ -270,8 +270,33 @@

+
+

auto load

+

click to other page test

+
+ + + +
+
+ +
+ +
+ + + +
+
+
+
+ +
+ + + diff --git a/games/game.html b/games/game.html index 949eb49..f9715f8 100644 --- a/games/game.html +++ b/games/game.html @@ -1,22 +1,84 @@ - - + - - + + Game Details - -
-

- Game Icon -

-

-

-
+

Game Title

+ Game Icon +

Game Description

+

Active Players

+

Owner

+

Likes

- - + + \ No newline at end of file