1
0
Fork 0

[client] Add number keyboard shortcuts to tools

This commit is contained in:
Starbeamrainbowlabs 2017-06-26 18:04:42 +01:00
parent 1845e38613
commit 75641b4f30
2 changed files with 21 additions and 14 deletions

View File

@ -85,16 +85,6 @@ class BoardWindow extends EventEmitter
this.canvas = canvas; this.canvas = canvas;
this.context = canvas.getContext("2d"); this.context = canvas.getContext("2d");
// Grab a reference to the sidebar and wrap it in an Interface class instance
this.interface = new Interface(
document.getElementById("sidebar"),
document.getElementById("debuginfo")
);
this.interface.on("toolchange", (function({oldTool, newTool}) {
this.canvas.classList.remove(oldTool);
this.canvas.classList.add(newTool);
}).bind(this));
// Create a map to store information about other clients in // Create a map to store information about other clients in
this.otherClients = new Map(); this.otherClients = new Map();
@ -124,6 +114,17 @@ class BoardWindow extends EventEmitter
this.chunkCache.showRenderedChunks = !this.chunkCache.showRenderedChunks; this.chunkCache.showRenderedChunks = !this.chunkCache.showRenderedChunks;
}).bind(this)); }).bind(this));
// Grab a reference to the sidebar and wrap it in an Interface class instance
this.interface = new Interface(
this,
document.getElementById("sidebar"),
document.getElementById("debuginfo")
);
this.interface.on("toolchange", (function({oldTool, newTool}) {
this.canvas.classList.remove(oldTool);
this.canvas.classList.add(newTool);
}).bind(this));
// --~~~-- // --~~~--
// Setup the favicon thingy // Setup the favicon thingy
@ -227,7 +228,7 @@ class BoardWindow extends EventEmitter
if(typeof this.chunkCache != "undefined" && this.gridSize != -1) if(typeof this.chunkCache != "undefined" && this.gridSize != -1)
this.chunkCache.update(dt, this.viewport); this.chunkCache.update(dt, this.viewport);
this.interface.updateDebugInfo(dt, this); this.interface.updateDebugInfo(dt);
} }
/** /**

View File

@ -4,10 +4,11 @@ window.EventEmitter = require("event-emitter-es6");
class Interface extends EventEmitter class Interface extends EventEmitter
{ {
constructor(inSidebar, inDebugDisplay) constructor(inBoardWindow, inSidebar, inDebugDisplay)
{ {
super(); super();
this.boardWindow = inBoardWindow;
this.sidebar = inSidebar; this.sidebar = inSidebar;
this.debugDisplay = inDebugDisplay; this.debugDisplay = inDebugDisplay;
@ -33,6 +34,11 @@ class Interface extends EventEmitter
{ {
toolSelectors[i].addEventListener("mouseup", this.handleSelectTool.bind(this)); toolSelectors[i].addEventListener("mouseup", this.handleSelectTool.bind(this));
toolSelectors[i].addEventListener("touchend", this.handleSelectTool.bind(this)); toolSelectors[i].addEventListener("touchend", this.handleSelectTool.bind(this));
this.boardWindow.keyboard.on(`keyup-${i + 1}`, (function(toolId, event) {
this.handleSelectTool({
target: this.sidebar.querySelector(`.tools .tool-selector:nth-child(${toolId})`)
});
}).bind(this, i + 1));
} }
this.emit("toolchange", { this.emit("toolchange", {
@ -197,10 +203,10 @@ class Interface extends EventEmitter
this.sidebar.querySelector(".name").innerHTML = newName; this.sidebar.querySelector(".name").innerHTML = newName;
} }
updateDebugInfo(dt, boardWindow) updateDebugInfo(dt)
{ {
this.debugDisplay.querySelector("#debug-framespacing").value = `${dt}ms`; this.debugDisplay.querySelector("#debug-framespacing").value = `${dt}ms`;
this.debugDisplay.querySelector("#debug-viewport").value = boardWindow.viewport; this.debugDisplay.querySelector("#debug-viewport").value = this.boardWindow.viewport;
} }
} }