feat(ui): added js routing for create game

added js routing for create game, removed the form and button
This commit is contained in:
LQ63
2025-11-11 14:10:37 +01:00
parent 33989efedc
commit b508d2f428
6 changed files with 107 additions and 34 deletions

View File

@@ -77,4 +77,47 @@
})
})
})
})()
})()
function createGameJS() {
let lobbyName = document.getElementById("lobbyname").value;
if (lobbyName === "") {
lobbyName = "DefaultLobby"
}
const playerAmount = document.getElementById("playeramount").value;
const jsonObj = {
lobbyname: lobbyName,
playeramount: playerAmount
}
sendGameCreationRequest(jsonObj);
}
function sendGameCreationRequest(dataObject) {
const route = jsRoutes.controllers.MainMenuController.createGame();
fetch(route.url, {
method: route.type,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(dataObject)
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
if (data.status === 'success') {
// Redirect the user
window.location.href = data.redirectUrl;
} else {
console.error("Game creation failed:", data.message);
}
})
.catch(error => {
console.error('Fetch error:', error);
alert('Could not create game. Please try again.');
});
}