From 6ae95ea10a89765431cdb2d10539d9ed833c6c2d Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Thu, 12 Mar 2015 09:50:16 +0100 Subject: [PATCH] Use new multiplayer commands in gui --- gui/dialogs/multiplayer.xml | 34 +++------------- webgui/lib/fgcommand.js | 68 ++++++++++++++++++------------- webgui/topics/Simulator/Config.js | 10 ++--- 3 files changed, 50 insertions(+), 62 deletions(-) diff --git a/gui/dialogs/multiplayer.xml b/gui/dialogs/multiplayer.xml index f753abfbe..3ed40af7c 100644 --- a/gui/dialogs/multiplayer.xml +++ b/gui/dialogs/multiplayer.xml @@ -76,16 +76,10 @@ gui.dialog_update("multiplayer", "host"); } - # listen for results arriving + # listen for results arriving setlistener("/sim/multiplay/got-servers", updateServers); setlistener("/sim/multiplay/get-servers-failure", updateServersFailed); - - fgcommand("xmlhttprequest", props.Node.new({ - "url" : "http://liveries.flightgear.org/mpstatus/mpservers.xml", - "targetnode" : "/sim/multiplay/server-list", - "complete" : "/sim/multiplay/got-servers", - "failure" : "/sim/multiplay/get-servers-failure" - })); + fgcommand("multiplayer-refreshserverlist"); ]]> @@ -235,21 +229,11 @@ nasal - - reinit - mp - diff --git a/webgui/lib/fgcommand.js b/webgui/lib/fgcommand.js index ff0256b6c..5d25e1938 100644 --- a/webgui/lib/fgcommand.js +++ b/webgui/lib/fgcommand.js @@ -2,11 +2,14 @@ * */ (function(factory) { - if (typeof define === "function" && define.amd)// AMD. Register as an anonymous module. - define([ - 'jquery' - ], factory); else // Browser globals - factory(jQuery); + if (typeof define === "function" && define.amd)// AMD. Register as an + // anonymous module. + define([ + 'jquery' + ], factory); + else + // Browser globals + factory(jQuery); }(function(jquery) { fgCommand = { @@ -79,11 +82,13 @@ name : '', children : [] }; - if (typeof (subsys) === 'string')arg.children.push({ - name : 'subsystem', - index : 0, - value : subsys - });else + if (typeof (subsys) === 'string') + arg.children.push({ + name : 'subsystem', + index : 0, + value : subsys + }); + else subsys.forEach(function(s, i) { arg.children.push({ name : 'subsystem', @@ -114,34 +119,39 @@ this.sendCommand("request-metar", this.twoArgs("station", id, "path", path)); }, - multiplayer : function(cmd) { + multiplayerConnect : function(cmd) { cmd = cmd || {}; var arg = { 'name' : '', - 'children' : [ - { - 'name' : 'command', - 'value' : '', - 'index' : 0, - } - ], + 'children' : [], }; - if (cmd.connect) { - arg.children[0].value = 'connect'; + arg.children.push({ + 'name' : 'servername', + 'value' : cmd.servername + }); + if (cmd.rxport) arg.children.push({ - 'name' : 'servername', - 'value' : cmd.connect.servername - }); - if (cmd.connect.rxport)arg.children.push({ 'name' : 'rxport', - 'value' : Number(cmd.connect.rxport) + 'value' : Number(cmd.rxport) }); - if (cmd.connect.txport)arg.children.push({ + if (cmd.txport) + arg.children.push({ 'name' : 'txport', - 'value' : Number(cmd.connect.txport) + 'value' : Number(cmd.txport) }); - } else if (cmd.disconnect)arg.children[0].value = 'disconnect';else if (cmd.refreshserverlist)arg.children[0].value = 'refreshserverlist'; - this.sendCommand("multiplayer", arg); + this.sendCommand("multiplayer-connect", arg); + }, + + multiplayerDisconnect : function() { + var arg = { + 'name' : '', + 'children' : [], + }; + this.sendCommand("multiplayer-disconnect"); + }, + + multiplayerRefreshserverlist : function() { + this.sendCommand('multiplayer-refreshserverlist'); }, clearMetar : function(path) { diff --git a/webgui/topics/Simulator/Config.js b/webgui/topics/Simulator/Config.js index 73a750671..8b65e425a 100644 --- a/webgui/topics/Simulator/Config.js +++ b/webgui/topics/Simulator/Config.js @@ -57,17 +57,17 @@ define([ self.toggleConnect = function() { if( self.online() ) { - fgCommand.multiplayer({ disconnect: {} }); + fgCommand.multiplayerDisconnect(); } else { - fgCommand.multiplayer({ connect: { - 'servername': self.selectedServer(), - } }); + fgCommand.multiplayerConnect({ + 'servername': self.selectedServer(), + }); } } self.serverListVisible = ko.observable(true); - fgCommand.multiplayer({ refreshserverlist: {} }); + fgCommand.multiplayerRefreshserverlist(); } // Return component definition