-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
97 lines (87 loc) · 2.44 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Multiplayer</title>
<script src='https://cdnjs.cloudflare.com/ajax/libs/peerjs/1.4.7/peerjs.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/phaser/3.55.0/phaser.min.js'></script>
<script src='build.js'></script>
<style>
* {
margin: 0;
padding: 0;
}
#link-container {
position: fixed;
font: 20px Arial, sans-serif;
box-sizing: border-box;
width: 768px;
z-index: 10;
padding: 0 16px 0 16px;
background-color: rgba(0, 0, 0, 0.5);
color: white;
}
#link-container > p {
padding: 8px 0 8px 0;
}
#link {
width: 100%;
height: 32px;
}
.hidden {
visibility: hidden;
}
</style>
</head>
<body>
<div id='link-container' class='hidden'>
<p>Have someone join your game with this link.</p>
<input id='link' type='text' placeholder='url here' value='what'/>
<p id='notice' class='hidden'>Text copied to clipboard.</p>
</div>
<script>
const linkContainer = document.getElementById('link-container');
const linkInput = document.getElementById('link');
const notice = document.getElementById('notice');
linkInput.addEventListener('click', (e) => {
if (e.currentTarget.value.startsWith('http')) {
e.currentTarget.select();
navigator.clipboard.writeText(e.currentTarget.value).then(() => {
notice.classList.remove('hidden');
});
}
});
let scene = null;
const isHost = !!!window.location.search;
if (isHost) {
scene = new GameScene({
onHosted: (id) => {
linkContainer.classList.remove('hidden');
linkInput.value = `${window.location.href}?${id}`;
},
onGameStarted: () => {
linkContainer.classList.add('hidden');
},
});
}
else {
const hostId = window.location.search.slice(1);
if (!hostId) {
throw Error('No peer id found in query string to connect to.');
}
scene = new GameScene({
remoteHostId: hostId,
});
}
const config = {
type: Phaser.AUTO,
width: SCREEN_WIDTH,
height: SCREEN_HEIGHT,
scene: [scene],
backgroundColor: '#ffffff',
};
const game = new Phaser.Game(config);
</script>
</body>
</html>