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

Fix clientMain #4

Merged
merged 1 commit into from
Jan 8, 2021
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
25 changes: 5 additions & 20 deletions client/clientMain.js
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions client/runClient.js
Original file line number Diff line number Diff line change
@@ -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
13 changes: 10 additions & 3 deletions extension/src/js/inject.js
Original file line number Diff line number Diff line change
@@ -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");

Expand All @@ -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%';
Expand Down Expand Up @@ -44,8 +46,13 @@ function renderSecretKeyForm() {

function handleSecretKeyFormSubmit(e) {
const secretKey = document.getElementById('secret-key').value

const canvas = `<canvas id='main-canvas' style="height: 100%; width: 100%"></canvas>`;
container.innerText = "";
container.insertAdjacentHTML('beforeend', canvas);

main(secretKey);
alert(secretKey);

}

document.addEventListener('submit', function (e) {
Expand Down