-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsole.js
75 lines (57 loc) · 1.83 KB
/
console.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
const Modal = require('voxel-modal');
const ConsoleWidget = require('console-widget');
module.exports = (game, opts) => new Console(game, opts);
module.exports.pluginInfo = {
loadAfter: ['voxel-keys']
};
class Console extends Modal {
constructor(game, opts) {
if (!game.isClient) return;
// options for ConsoleWidget
const widgetOpts = opts; // pass through voxel-console opts (no need to copy)
// nothing closes the widget, hide/show is handled by voxel-modal
widgetOpts.closeKeys = [];
const widget = ConsoleWidget(widgetOpts);
super(game, {element: widget.containerNode});
this.game = game;
this.opts = opts;
if (!opts.includeTextBindings) {
opts.includeTextBindings = {
'console': undefined,
console2: '/',
console3: '.'};
}
this.widget = widget;
//this.widget.on 'input', (text) => # TODO: handle events, pass up?
// this.widget.log "You said: #{text}"
this.keys = game.plugins.get('voxel-keys');
if (!this.keys) throw new Error('voxel-console requires voxel-keys plugin');
this.bindKeys();
}
bindKeys() {
//this.game.buttons.bindings.console ?= 'T' # TODO: bind these keys ourselves?
//this.game.buttons.bindings.console2 ?= '/' # maybe with game-shell, game.shell.bind()
//this.game.buttons.bindings.console3 ?= '.'
['console', 'console2', 'console3'].forEach((binding) => {
this.keys.down.on(binding, () => {
const initialText = this.opts.includeTextBindings[binding];
this.open(initialText);
});
});
}
open(initialText) {
super.open();
this.widget.open(initialText);
}
close() {
super.close();
//this.widget.close(); // modal hides everything
}
log(text) {
this.widget.log(text);
}
logNode(node) {
this.widget.logNode(node);
}
}