forked from lieuzhenghong/discord-spatial-layer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from juxd/backup
Update Chrome extension
- Loading branch information
Showing
6 changed files
with
83 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,11 @@ | ||
import GameClient from './GameClient' | ||
import instantiateClient from './instantiateClient' | ||
|
||
const SECRET_KEY_FORM_ID = 'secret-key-form' | ||
import UI from './runClient'; | ||
|
||
window.onload = function () { | ||
const container = document.getElementById('container') | ||
container.style.height = '100%' | ||
container.style.width = '100%' | ||
container.style.position = 'absolute' | ||
|
||
container.insertAdjacentHTML('beforeend', renderSecretKeyForm()) | ||
} | ||
|
||
function renderSecretKeyForm() { | ||
return ` | ||
<form id="${SECRET_KEY_FORM_ID}"> | ||
<label for="secret-key">Secret Key:</label><br> | ||
<input type="text" id="secret-key" name="secret-key"><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
` | ||
} | ||
|
||
let gameClient | ||
|
||
function handleSecretKeyFormSubmit(e) { | ||
const secretKey = document.getElementById('secret-key').value | ||
|
||
instantiateClient(secretKey) | ||
.then(client => { | ||
const canvas = '<canvas id=\'main-canvas\' style="height: 100%; width: 100%"></canvas>' | ||
container.innerText = '' | ||
container.insertAdjacentHTML('beforeend', canvas) | ||
gameClient = new GameClient(client) | ||
let tick = 0 | ||
let previous = performance.now() | ||
const loop = function () { | ||
window.requestAnimationFrame(loop) | ||
const now = performance.now() | ||
const delta = (now - previous) / 1000 | ||
previous = now | ||
tick++ | ||
|
||
gameClient.update(delta, tick, now) | ||
} | ||
|
||
loop() | ||
}) | ||
.catch(res => { | ||
alert('shit secret key') | ||
}) | ||
const ui = new UI(container); | ||
ui.start(); | ||
} | ||
|
||
document.addEventListener('submit', e => { | ||
e.preventDefault() | ||
|
||
const form = e.target | ||
const formId = form.getAttribute('id') | ||
|
||
if (formId === SECRET_KEY_FORM_ID) { | ||
handleSecretKeyFormSubmit(e) | ||
} | ||
}, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import GameClient from './GameClient' | ||
import instantiateClient from './instantiateClient' | ||
|
||
const SECRET_KEY_FORM_ID = 'secret-key-form' | ||
|
||
class UI { | ||
constructor(container) { | ||
this.container = container; | ||
} | ||
|
||
start() { | ||
this.container.innerText = ''; | ||
this.container.insertAdjacentHTML('beforeend', this.renderSecretKeyForm()); | ||
document.addEventListener('submit', e => { | ||
e.preventDefault() | ||
|
||
const form = e.target | ||
const formId = form.getAttribute('id') | ||
|
||
if (formId === SECRET_KEY_FORM_ID) { | ||
this.handleSecretKeyFormSubmit(e) | ||
} | ||
}, false) | ||
} | ||
|
||
renderSecretKeyForm() { | ||
return ` | ||
<form id="${SECRET_KEY_FORM_ID}"> | ||
<label for="secret-key">Secret Key:</label><br> | ||
<input type="text" id="secret-key" name="secret-key"><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
` | ||
} | ||
|
||
handleSecretKeyFormSubmit(e) { | ||
const secretKey = document.getElementById('secret-key').value; | ||
|
||
instantiateClient(secretKey) | ||
.then(client => { | ||
console.log("success"); | ||
const canvas = '<canvas id=\'main-canvas\' style="height: 100%; width: 100%"></canvas>' | ||
this.container.innerText = '' | ||
this.container.insertAdjacentHTML('beforeend', canvas) | ||
const gameClient = new GameClient(client) | ||
let tick = 0 | ||
let previous = performance.now() | ||
const loop = function () { | ||
window.requestAnimationFrame(loop) | ||
const now = performance.now() | ||
const delta = (now - previous) / 1000 | ||
previous = now | ||
tick++ | ||
|
||
gameClient.update(delta, tick, now) | ||
} | ||
|
||
loop() | ||
}) | ||
.catch(err => { | ||
console.log(`error: ${err}`); | ||
alert('shit secret key') | ||
}) | ||
} | ||
} | ||
|
||
export default UI; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters