1
0
Fork 0
fgdata/Phi/topics/Simulator/Config.js

81 lines
2.8 KiB
JavaScript
Raw Normal View History

define([
'jquery', 'knockout', 'text!./Config.html', 'fgcommand', 'props', 'kojqui/button', 'kojqui/buttonset', 'kojqui/selectmenu',
], function(jquery, ko, htmlString, fgCommand, SGPropertyNode) {
function ViewModel(params) {
var self = this;
self.asa = ko.observable('');
self.aiEnabled = ko.observable().extend({
fgPropertyGetSet : "/sim/traffic-manager/enabled"
});
self.multiplayerHideReplay = ko.observable().extend({
fgPropertyGetSet : "/sim/traffic-manager/enabled"
});
self.callsign = ko.observable().extend({
fgPropertyGetSet : "/sim/multiplay/callsign"
});
self.online = ko.observable().extend({
fgprop : "/sim/multiplay/online"
});
self.offline = ko.pureComputed(function() {
return !self.online();
});
self.selectedServer = ko.observable().extend({
fgPropertyGetSet : "/sim/multiplay/selected-server"
});
self.gotServers = ko.observable().extend({
fgprop: "/sim/multiplay/got-servers"
}).subscribe(function(newValue) {
if( newValue ) {
self.serverList.removeAll();
jquery.get('/json/sim/multiplay/server-list?d=3', null, function(data) {
var root = new SGPropertyNode(data);
root.getChildren('server').forEach(function(server){
if( !server.getNode('online').getValue() )
return;
self.serverList.push( {
name: server.getNode('name').getValue(),
host: server.getNode('hostname').getValue(),
location: server.getNode('location').getValue(),
port: server.getNode('port').getValue(),
longname: server.getNode('hostname').getValue() + ' - ' + server.getNode('location').getValue(),
})
});
});
}
});
self.serverList = ko.observableArray([]);
self.toggleConnect = function() {
if( self.online() ) {
2015-03-12 08:50:16 +00:00
fgCommand.multiplayerDisconnect();
} else {
2015-03-12 08:50:16 +00:00
fgCommand.multiplayerConnect({
'servername': self.selectedServer(),
'rxport': 5000,
'txport': 5000
2015-03-12 08:50:16 +00:00
});
}
}
self.serverListVisible = ko.observable(true);
2015-03-12 08:50:16 +00:00
fgCommand.multiplayerRefreshserverlist();
}
// Return component definition
return {
viewModel : ViewModel,
template : htmlString
};
});