1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

[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.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
this.otherClients = new Map();
@ -124,6 +114,17 @@ class BoardWindow extends EventEmitter
this.chunkCache.showRenderedChunks = !this.chunkCache.showRenderedChunks;
}).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
@ -227,7 +228,7 @@ class BoardWindow extends EventEmitter
if(typeof this.chunkCache != "undefined" && this.gridSize != -1)
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
{
constructor(inSidebar, inDebugDisplay)
constructor(inBoardWindow, inSidebar, inDebugDisplay)
{
super();
this.boardWindow = inBoardWindow;
this.sidebar = inSidebar;
this.debugDisplay = inDebugDisplay;
@ -33,6 +34,11 @@ class Interface extends EventEmitter
{
toolSelectors[i].addEventListener("mouseup", 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", {
@ -197,10 +203,10 @@ class Interface extends EventEmitter
this.sidebar.querySelector(".name").innerHTML = newName;
}
updateDebugInfo(dt, boardWindow)
updateDebugInfo(dt)
{
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;
}
}