A Game Console for Browsers.
Check the live demo, or Usage / Advance Usage / API.
Include console.min.js
in your page:
<script src="http://amio.github.io/console.js/lib/console.min.js"></script>
then:
new Console({
"addbots": function (num) {
// add some bots,
// then tell player:
return num + ' bots added.'
}
});
var cnsl = new Console({}, {
hotkey: 27, // <kbd>ESC</kbd> ('~' for default)
welcome: 'Hello User.',
caseSensitive: true,
defaultHandler: function(){}
onShow: function(){},
onHide: function(){}
});
hotkey
: {Number|boolean} The keyCode of hotkey. Hint: If you want to manually put up console(cnsl.toggle("on")
), set to a falsy value.192
by default, the "~".welcome
: {String} The welcome message.''
by default.caseSensitive
: {Boolean} If you want to.false
by default.defaultHandler
: {Function} the default handler for any unspecified command.null
by default.onShow
: {Function} On show callback.null
by default.onHide
: {Function} On hide callback.null
by default.
new Console({
"add": "addbots",
"addbots": function (num) {
// add some bots,
// then tell player:
return num + ' bots added.'
}
});
.register(command, commandHandler)
var playerName = 'Player';
var cnsl = new Console();
cnsl.register('setname',function(name){
playerName = name;
return 'Player name is' + playerName + ' now.';
});
.register(command, commandHandler, commandConfig)
var playerName = 'Player';
var cnsl = new Console();
cnsl.register('setname',function(name){
playerName = name;
return 'Player name is' + playerName + ' now.';
}, {
usage: 'SETNAME <newname> || NAME <newname>',
desc: 'Change your name (works in network play too).'
})
.register('help', function () {
var cmds = cnsl.commands;
for (var name in cmds) {
if (cmds.hasOwnProperty(name)) {
cmds[name].desc && cnsl.log(' -', cmds[name].usage + ':', cmds[name].desc);
}
}
},{
usage: 'HELP',
desc: 'Show help messages.'
});
new Console()
Create a console (with default options).new Console(cmdObj)
Create a console with command handlers.new Console({}, optionObj)
Create a console with options. (see Init console with options)
.register(cmd, fn)
Register afn
tocmd
.register(cmd, fn, config)
Register afn
tocmd
with a config object
.toggle()
Toggle the console.toggle("on")
Show the console.toggle("off")
Hide the console
.destroy()
Suicide.