| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Console.js is a tiny lib for creating Console (video game cli) popups in browser.
NEW: v2.0 is out 😺
Check the Live Demo, or Basic Usage / Advance Usage / API.
const cnsl = new Console({ hotkey: 192 })
cnsl.register('addbots', function (num) {
// Add some bots, then tell player:
return num + ' bots added.'
})var cnsl = new Console({
hotkey: 27, // <kbd>ESC</kbd>
welcome: 'Hello User.',
caseSensitive: true,
autoComplete: true,
defaultHandler: function () {},
onShow: function () {},
onHide: function () {}
}, {
'cmd1': function (args) {/*...*/},
'cmd2': function (args) {/*...*/}
});.register(commandName, commandHandler, commandConfig)
var cnsl = new Console()
cnsl.register('say', function () {
return player.name + ': "' + Array.prototype.join.call(arguments, ' ') + '"'
}, {
usage: 'SAY <message string>: Broadcast a message to other players in the game.'
})
cnsl.register('help', function () {
return Object.keys(cnsl.handlers).map(function (name) {
return ' - ' + cnsl.handlers[name].cfg.usage
}).join('\n')
}, {
usage: 'HELP: Show help messages.'
})var cnsl = new Console({
hotkey: 27,
autoComplete: customeAutoComplete
})
function customeAutoComplete (inputString) {
const availableCommands = Object.keys(cnsl.handlers)
cnsl.log(availableCommands.join(' '))
return inputString
}Note: Console instances on https://amio.github.io/console.js/ were exposed on window. You can fiddle with them(window.cnsl and window.smtc) in devtools.
MIT © Amio
| Back | FazBrowse Home | New Git URL |