First version of working, simple webclient with new infrastructure (backend + frontend).

This commit is contained in:
Griatch 2016-02-12 12:53:56 +01:00
parent d48691e121
commit 5c7067ddce
3 changed files with 21 additions and 19 deletions

View file

@ -110,9 +110,9 @@ An "emitter" object must have a function
if (typeof callback === 'function') {
cmdmap[cmdid] = callback;
}
log('client msg sending: ', data);
this.connection.msg(data);
log('client msg sending: ', cmdname, args, outargs, outkwargs);
},
// Evennia -> Client.
@ -219,9 +219,9 @@ An "emitter" object must have a function
log("incoming " + data);
Evennia.emit(data[0], data[1], data[2]);
};
websocket.msg = function(cmdname, args, kwargs) {
// send
websocket.send(JSON.stringify([cmdname, args, kwargs]));
websocket.msg = function(data) {
// send data across the wire. Make sure to json it.
websocket.send(JSON.stringify(data));
};
return websocket;

View file

@ -27,17 +27,17 @@ var inputlog = function() {
history[0] = ''; // the very latest input is empty for new entry.
function history_back() {
var back = function () {
// step backwards in history stack
history_pos = Math.min(++history_pos, history.length - 1);
return history[history.length - 1 - history_pos];
}
function history_fwd() {
};
var fwd = function () {
// step forwards in history stack
history_pos = Math.max(--history_pos, 0);
return history[history.length -1 - history_pos];
}
function history_add(input) {
};
var add = function (input) {
// add a new entry to history, don't repeat latest
if (input != history[history.length-1]) {
if (history.length >= history_max) {
@ -45,12 +45,12 @@ var inputlog = function() {
}
history[history.length-1] = input;
history[history.length] = '';
}
}
return {back: history_back,
fwd: history_fwd,
add: history_add}
};
};
};
return {back: back,
fwd: fwd,
add: add}
}();
$.fn.appendCaret = function() {
/* jQuery extension that will forward the caret to the end of the input, and
@ -100,10 +100,12 @@ $(document).keydown( function(event) {
inputfield.focus();
if (code === 13) { // Enter key sends text
outtext = inputfield.val()
inputlog.add(outtext)
outtext = inputfield.val();
inputlog.add(outtext);
inputfield.val("");
log("sending outtext", outtext);
Evennia.msg("text", [outtext], {});
event.prevetDefault()
event.preventDefault()
}
else if (code === 38) { // Arrow up
inputfield.val(inputlog.back()).appendCaret();

View file

@ -12,7 +12,7 @@
<div id="client">
<div id="messagewindow"></div>
<div id="inputform">
<textarea name="inputfield" type="text"> </textarea>
<textarea id="inputfield" type="text"> </textarea>
</div>
</div>