From 964bb4992295243deb34eaa06adeeec04a227071 Mon Sep 17 00:00:00 2001 From: Dexter Leng Date: Fri, 8 Jan 2021 23:05:23 +0800 Subject: [PATCH] Fix clientMain --- client/clientMain.js | 25 +++++-------------------- client/runClient.js | 22 ++++++++++++++++++++++ extension/src/js/inject.js | 13 ++++++++++--- 3 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 client/runClient.js diff --git a/client/clientMain.js b/client/clientMain.js index 4f00b23..4adf8ad 100644 --- a/client/clientMain.js +++ b/client/clientMain.js @@ -1,22 +1,7 @@ -import GameClient from './GameClient' +import main from './runClient'; -function main(secret) { - - // TODO: const secret = document.getElementById('secret-input').value - const gameClient = new GameClient(secret) - 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() +window.onload = function() { + console.log('window loaded') + const secret = 'MAGIC_VALUE'; + main(secret); } - -export default main diff --git a/client/runClient.js b/client/runClient.js new file mode 100644 index 0000000..4f00b23 --- /dev/null +++ b/client/runClient.js @@ -0,0 +1,22 @@ +import GameClient from './GameClient' + +function main(secret) { + + // TODO: const secret = document.getElementById('secret-input').value + const gameClient = new GameClient(secret) + 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() +} + +export default main diff --git a/extension/src/js/inject.js b/extension/src/js/inject.js index fc588f4..a7272bc 100644 --- a/extension/src/js/inject.js +++ b/extension/src/js/inject.js @@ -1,9 +1,11 @@ import nengiConfig from '../../../common/nengiConfig'; -import main from '../../../client/clientMain'; +import main from '../../../client/runClient'; console.log(nengiConfig); const SECRET_KEY_FORM_ID = 'secret-key-form'; +let container; + (function() { const discordElement = document.getElementById("app-mount"); @@ -12,7 +14,7 @@ const SECRET_KEY_FORM_ID = 'secret-key-form'; discordElement.style.height = '60%'; discordElement.style.float = 'top'; - const container = document.createElement("div"); + container = document.createElement("div"); container.id = "game-container"; container.style.height = '40%'; container.style.width = '100%'; @@ -44,8 +46,13 @@ function renderSecretKeyForm() { function handleSecretKeyFormSubmit(e) { const secretKey = document.getElementById('secret-key').value + + const canvas = ``; + container.innerText = ""; + container.insertAdjacentHTML('beforeend', canvas); + main(secretKey); - alert(secretKey); + } document.addEventListener('submit', function (e) {