Mercurial > web-gnusto
changeset 32:3a85b5915ea6
Added bad implementation of character input. The 'info' command in Troll no longer crashes the Z-Machine, but because we don't currently support multiple windows and the the 'info' command uses the top window as an interface, it still looks like it's hanging.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 12 May 2008 11:23:47 -0700 |
parents | 5d7bf3684fc3 |
children | 8d34fb3e9108 |
files | engine-runner.js trivial-zui.js |
diffstat | 2 files changed, 46 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/engine-runner.js Mon May 12 10:43:51 2008 -0700 +++ b/engine-runner.js Mon May 12 11:23:47 2008 -0700 @@ -77,6 +77,16 @@ } }, + _receiveCharacterInput: function(input) { + self._isWaitingForCallback = false; + self._engine.answer(0, input); + if (!self._isInLoop) { + self._continueRunning(); + } else { + /* We're still inside _loop(), so just return. */ + } + }, + _loop: function() { if (self._isInLoop) throw Error("Already in loop!"); @@ -93,6 +103,9 @@ self._zui.onLineInput(self._receiveLineInput); break; case GNUSTO_EFFECT_INPUT_CHAR: + self._isWaitingForCallback = true; + self._zui.onCharacterInput(self._receiveCharacterInput); + break; case GNUSTO_EFFECT_SAVE: case GNUSTO_EFFECT_RESTORE: throw Error("Unimplemented effect: " + effect);
--- a/trivial-zui.js Mon May 12 10:43:51 2008 -0700 +++ b/trivial-zui.js Mon May 12 11:23:47 2008 -0700 @@ -9,8 +9,36 @@ this.__proto__ = { _windowKeypress: function(event) { - if (!$("#current-input")) + if ($("#current-input").length == 0) { + // We're not waiting for a line of input, but we may + // be waiting for a character of input. + + // Note that we have to return a ZSCII keycode here. + // + // For more information, see: + // + // http://www.gnelson.demon.co.uk/zspec/sect03.html + if (self._currentCallback) { + var keyCode = 0; + if (event.charCode) { + keyCode = event.charCode; + } else { + // TODO: Deal w/ arrow keys, etc. + switch (event.keyCode) { + case RETURN_KEYCODE: + keyCode = event.keyCode; + break; + } + } + if (keyCode != 0) { + var callback = self._currentCallback; + + self._currentCallback = null; + callback(keyCode); + } + } return; + } var oldInputString = self._inputString; @@ -59,6 +87,10 @@ ); }, + onCharacterInput: function(callback) { + self._currentCallback = callback; + }, + onQuit: function() { },