+ var commands = {
+ tell : function(msg) {
+ console.log(msg);
+ var parts = msg.match(/^(\w+)\s(.*)/);
+ if (!parts[1]) return;
+ var dest = parts[1];
+ msg = parts[2];
+// $.ajax({
+// url: endpoint,
+// data: { 'cmd' : 'tell', 'dest' : dest, 'msg' : msg },
+// success: function() {
+ writeToLog('You told ' + dest + ': ', 'tell', msg);
+// },
+// });
+ },
+ yell : function(msg) {
+ $.ajax({
+ url: endpoint,
+ data: { 'cmd' : 'yell', 'msg' : msg },
+ success: function() {
+ writeToLog('You yelled: ', 'yell', msg);
+ },
+ });
+ },
+ say : function(msg) {
+// $.ajax({
+// url: endpoint,
+// data: { 'cmd' : 'yell', 'msg' : msg },
+// success: function() {
+ writeToLog('You said: ', 'say', msg);
+// },
+// });
+ },
+ move : function(direction) {
+ this.player.move(direction);
+ },
+ }
+ function writeToLog(action, style, msg) {
+ $('#log').append(
+ $('<div>').addClass('logline').append(
+ $('<span>').addClass(style).text(action),
+ $('<span>').addClass('msg').text(msg)
+ )
+ )
+ }
+ $('#submit').click(function() {
+ var text = $('#chat').val();
+ var parts = text.match(/^(\w+)\s(.*)/);
+ if (parts) {
+ var cmd = parts[1];
+ text = parts[2];
+ if (commands[cmd] != undefined) {
+ commands[cmd](text);
+ $('#chat').val('');
+ }
+ }
+ });
+ $('#chat').keydown(function(e) {
+ if (e.which == '13') {
+ $('#submit').click();
+ } else if (e.which >= 37 && e.which <= 40)
+ e.stopPropagation();
+ });
+ $('#join').click(function() {
+ mud.join();
+ $(this).fadeOut('slow');
+ });
+