startgame in js
This commit is contained in:
parent
86ee9c3863
commit
1addd381a3
17
truthseeker/static/js/api.js
Normal file
17
truthseeker/static/js/api.js
Normal file
@ -0,0 +1,17 @@
|
||||
async function makeAPIRequest(endpoint, body){
|
||||
return new Promise((resolve, reject)=>{
|
||||
const fetchOptions = {
|
||||
method: "POST",
|
||||
body: new URLSearchParams(body)
|
||||
}
|
||||
fetch("/api/v1/"+endpoint, fetchOptions).then(resp => {
|
||||
resp.json().then(jsonResp=>{
|
||||
if(jsonResp["error"] == 0){
|
||||
resolve(jsonResp)
|
||||
}else{
|
||||
reject(endpoint+": "+jsonResp["msg"])
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
@ -125,7 +125,7 @@ function createMultiPlayerRoom() {
|
||||
|
||||
hideInvalidInputErrorMessage();
|
||||
|
||||
//TODO: code to create multi player game
|
||||
startGame()
|
||||
}
|
||||
|
||||
function joinMultiPlayerRoom() {
|
||||
@ -208,6 +208,16 @@ function changeTheme() {
|
||||
}
|
||||
}
|
||||
|
||||
async function startGame(){
|
||||
username = document.getElementById("game_username").value;
|
||||
let data = {}
|
||||
data["username"] = username
|
||||
await makeAPIRequest("createGame",data);
|
||||
}
|
||||
async function joinGame(){
|
||||
username = document.getElementById("game_username").value();
|
||||
gameid = document.getElementById("game_room_code").value();
|
||||
}
|
||||
// Set event listeners
|
||||
|
||||
document.getElementById("play_button").addEventListener("click", showGameModeSelection);
|
||||
|
@ -72,6 +72,8 @@
|
||||
<a href="/legal" class="footer_link link" target="_blank" title="Consulter les mentions légales de Truth Inquiry (ouverture dans un nouvel onglet)">Mentions légales</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="/static/js/api.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
|
||||
<script src="/static/js/game_common.js"></script>
|
||||
<script src="/static/js/game_start_page.js"></script>
|
||||
</body>
|
||||
|
@ -61,7 +61,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
<script src="/static/js/api.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.4.1/socket.io.min.js"></script>
|
||||
<script src="/static/js/game_common.js"></script>
|
||||
<script src="/static/js/game_lobby.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user