Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Game invite #40

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Backend/Apps/Game/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
from . import views

urlpatterns = [
path('<uuid:game_id>',views.index,name='index'),
path('<uuid:game_id>/',views.index,name='index'),
]
2 changes: 1 addition & 1 deletion Backend/static/scripts/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function handleGameAcceptedCallback(data)
game_id: response.game_id,
}
socket.send(JSON.stringify(sendBody));
console.log("redirected to game")
loadPage(`/game/${response.game_id}/`);
}
catch (error)
{
Expand Down
65 changes: 53 additions & 12 deletions Backend/static/scripts/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,51 @@ const routes = new Map([
auth_required: true,
url: [/game\/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})/],
html: `
<div class="container">
<div class="player">
<img src="/static/public/liked.svg" style="width: 20px" alt="Player 1">
<p>Player 1 &nbsp <br>Point: 2000&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp</p>
<p>Player 2 &nbsp <br>Point: 2000</p>
<img src="/static/public/liked.svg" style="width: 20px" alt="Player 2">
</div>
<canvas class="canvas-class" id="pongCanvas" width="800" height="400"></canvas>
</div>

<div
class="background container-fluid social-background"
style="padding: 0"
>
<div class="game-container">

<div class="game-wrapper">
<div class="game-data-wrapper">

<div class="game-player-data" id="player-one">
<div class="player-image">
<img src="https://picsum.photos/seed/picsum/200/300" alt="Player 2">
</div>
<div class="player-description" id="player-one-details">
<span class="player-name">Player 1</span>
<span class="player-points">Points?</span>
</div>
</div>
<div class="game-points">
<h1 id="game-points" class="skeleton">

</h1>
</div>
<div class="game-player-data" id="player-two">
<div class="player-image">
<img src="https://picsum.photos/seed/picsum/200/300" alt="Player 2">
</div>
<div class="player-description" id="player-two-details">
<span class="player-name">Player 2</span>
<span class="player-name">Points?</span>
</div>
</div>

</div>
<div class="" id="canvas-wrapper">
<div class="spectators-wrapper" id="spectators-wrapper">
</div>
<div class="canvas-wrapper">
<canvas class="canvas-class" id="pongCanvas" width="1368" height="600"></canvas>
</div>
</div>
</div>
</div>
</div>
`
}],
['error', {
Expand Down Expand Up @@ -596,7 +631,6 @@ export function loadPage(fileName) {
let data = findRouteFile(fileName);
const route = routes.get(data);
let isMatch = false;

if (Array.isArray(route.url)) {
isMatch = route.url.some(url => {
if (url instanceof RegExp) {
Expand All @@ -610,9 +644,16 @@ export function loadPage(fileName) {
} else {
isMatch = window.location.pathname.includes(route.url);
}

let split = fileName.split('/').filter(Boolean);
if (!isMatch) {
history.pushState({}, '', window.location.origin + route.url);
if(split.length > 1)
{
console.log("split",split)
history.pushState({}, '', window.location.origin + `/${split[0]}/${split[1]}/`);
}
else
history.pushState({}, '', window.location.origin + route.url);

}
let content = document.getElementById('main');
content.innerHTML = route.html;
Expand Down
Loading