refactor: listen to app node for events

This commit is contained in:
cha0s 2019-03-28 17:55:09 -05:00
parent 9324fd26ee
commit 5b133038b2
2 changed files with 6 additions and 3 deletions

View File

@ -25,6 +25,9 @@
</style>
</head>
<body>
<div class="app"></div>
<div
class="app"
tabindex="0"
></div>
</body>
</html>

View File

@ -35,6 +35,7 @@ room.on('entityAdded', (entity) => {
}
}
});
const appNode = document.querySelector('.app');
// Accept input.
const actionRegistry = new ActionRegistry();
actionRegistry.mapKeysToActions({
@ -43,12 +44,11 @@ actionRegistry.mapKeysToActions({
's': 'MoveDown',
'd': 'MoveRight',
});
actionRegistry.listen();
actionRegistry.listen(appNode);
let actionState = actionRegistry.state();
// Create the socket connection.
const socket = createClient(window.location.href);
// Create the graphics canvas.
const appNode = document.querySelector('.app');
appNode.appendChild(renderer.element);
// Input messages.
const messageHandle = setInterval(() => {