Skip to content
Permalink
Browse files

Add Descent 3 path setting, get communication going.

  • Loading branch information...
roncli committed Jun 28, 2015
1 parent 8d8e43e commit c6c2cf443eb339a3e0c1393608e2daf9d50c6bf9
@@ -30,4 +30,7 @@ node_modules
test.js

# PHP Storm
.idea
.idea

# DDSN settings
settings.json
@@ -1,19 +1,24 @@
<html ng-app="ddsn">
<html ng-app="ddsn" ng-controller="ddsn">
<head>
<script src="/js/jquery-2.1.4.min.js"></script>
<script src="/js/bootstrap-3.3.5.min.js"></script>
<script src="/js/angular-1.3.16.min.js"></script>
<script src="/js/ddsn.js"></script>
<link rel="stylesheet" href="/css/bootstrap-slate-3.3.5.min.css" />
</head>
<body ng-controller="ddsn">
<body>
<div class="jumbotron text-center">
<h1>Descent DSN</h1>
</div>
<div id="content">
<server-tabs></server-tabs>
<ul id="menu-tabs" class="nav nav-pills"></ul>
<div id="feature"></div>
<div class="container-fluid">
<div class="col-xs-12">
<offline ng-if="data.offline"></offline>
<error ng-if="data.error"></error>
<div ng-if="!data.offline && !data.error">
<server-tabs></server-tabs><br />
<content></content>
</div>
</div>
</div>
</body>
</html>
@@ -1,68 +1,163 @@
/*jslint browser: true*/
/*global $, WebSocket, angular*/

var createWebsocketClient = function() {
var app = angular.module("ddsn", []),
data = {
serverTab: "news",
settingsMenuTab: "descent3",
settings: {
descent3: {
pathValid: false
}
}
};

(function() {
"use strict";

var ws = new WebSocket("ws://localhost:20921"),
connected = false;
var ws, scope;

ws.onopen = function() {
ws.send(JSON.stringify({
message: "initialize"
}));
connected = true;
};
app.directive("offline", function() {
return {
restrict: "E",
templateUrl: "/templates/offline.htm"
};
});

ws.onclose = function() {
// If the server shut down, attempt to reconnect once.
console.log("Closed.");
if (connected) {
setTimeout(function() {
createWebsocketClient();
}, 1000);
}
};
app.directive("error", function() {
return {
restrict: "E",
templateUrl: "/templates/error.htm"
};
});

ws.onmessage = function(ev) {
// TODO: Handle message.
};
app.directive("serverTabs", function() {
return {
restrict: "E",
templateUrl: "/templates/server-tabs.htm"
};
});

ws.onerror = function(ev) {
// TODO: Display error and shut down the web page.
console.log("An error occurred.", ev);
};
};
app.directive("content", function() {
return {
restrict: "E",
templateUrl: "/templates/content.htm"
};
});

$(document).ready(function() {
"use strict";
app.directive("news", function() {
return {
restrict: "E",
templateUrl: "/templates/news.htm"
};
});

createWebsocketClient();
});
app.directive("dashboard", function() {
return {
restrict: "E",
templateUrl: "/templates/dashboard.htm"
};
});

// Set up Angular application.
var app = angular.module("ddsn", []);
app.directive("addServer", function() {
return {
restrict: "E",
templateUrl: "/templates/add-server.htm"
};
});

app.directive("serverTabs", function() {
"use strict";
app.directive("settings", function() {
return {
restrict: "E",
templateUrl: "/templates/settings.htm"
};
});

return {
restrict: "E",
templateUrl: "/templates/server-tabs.htm"
};
});
app.directive("settingsDescent3", function() {
return {
restrict: "E",
templateUrl: "/templates/settings-descent3.htm"
};
});

app.controller("ddsn", ["$scope", function($scope) {
"use strict";
app.directive("settingsModifications", function() {
return {
restrict: "E",
templateUrl: "/templates/settings-modifications.htm"
};
});

$scope.servers = [
{
gameName: "Descent 3 Dedicated Server",
port: 2092
},
{
gameName: "Descent 3 Dedicated Server",
port: 2093
}
];
}]);
app.controller("ddsn", ["$scope", function($scope) {
$scope.data = data;

$scope.openMenu = function(ev, screen) {
$("button.server-tab").removeClass("btn-success").addClass("btn-primary");
$(ev.currentTarget).removeClass("btn-primary").addClass("btn-success");
data.serverTab = screen;
//scope.$apply();
};

$scope.openSettings = function(ev, screen) {
$("button.settings-menu-tab").removeClass("btn-success").addClass("btn-primary");
$(ev.currentTarget).removeClass("btn-primary").addClass("btn-success");
data.settingsMenuTab = screen;
//scope.$apply();
};

$scope.updateSettingsDescent3Path = function() {
ws.send(JSON.stringify({
message: "settings.descent3.path",
path: data.settings.descent3.path
}));
};
}]);

$(document).ready(function() {
var createWebsocketClient = function() {
var connected = false;
ws = new WebSocket("ws://localhost:20921");

ws.onopen = function() {
ws.send(JSON.stringify({
message: "initialize"
}));
connected = true;
};

ws.onclose = function() {
if (connected) {
// If the server shut down, attempt to reconnect once.
setTimeout(function() {
createWebsocketClient();
}, 1000);
} else {
data.offline = true;
scope.$apply();
}
};

ws.onmessage = function(ev) {
var message = JSON.parse(ev.data),
key;

switch (message.message) {
case "settings":
for (key in message.settings) {
if (message.settings.hasOwnProperty(key)) {
data.settings[key] = message.settings[key];
}
}
scope.$apply();
break;
case "settings.descent3.pathValid":
data.settings.descent3.pathValid = message.valid;
scope.$apply();
break;
}
};
};

scope = angular.element("html").scope();
createWebsocketClient();
});
}());
@@ -0,0 +1,20 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="btn btn-success"><span class="glyphicon glyphicon-hdd"></span> Saved Servers</button>
</li>
<li role="presentation">
<button class="btn btn-primary"><span class="glyphicon glyphicon-wrench"></span> Server Options</button>
</li>
<li role="presentation">
<button class="btn btn-primary"><span class="glyphicon glyphicon-th-list"></span> Game Options</button>
</li>
<li role="presentation">
<button class="btn btn-primary"><span class="glyphicon glyphicon-ok"></span> Allowed Objects</button>
</li>
<li role="presentation">
<button class="btn btn-primary"><span class="glyphicon glyphicon-tasks"></span> Modifications</button>
</li>
<li role="presentation">
<button class="btn btn-primary"><span class="glyphicon glyphicon-share"></span> Launch Server</button>
</li>
</ul>
@@ -0,0 +1,15 @@
<div ng-if="data.serverTab === 'news'">
<news></news>
</div>
<div ng-if="data.serverTab === 'dashboard'">
<dashboard></dashboard>
</div>
<div ng-if="data.serverTab === 'server'">
<server></server>
</div>
<div ng-if="data.serverTab === 'addServer'">
<add-server></add-server>
</div>
<div ng-if="data.serverTab === 'settings'">
<settings></settings>
</div>
@@ -0,0 +1,8 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="btn btn-success"><span class="glyphicon glyphicon-play"></span> Current Games</button>
</li>
<li role="presentation">
<button class="btn btn-primary"><span class="glyphicon glyphicon-list-alt"></span> Past Games</button>
</li>
</ul>
File renamed without changes.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
@@ -1,17 +1,17 @@
<ul class="nav nav-pills">
<li role="presentation">
<button id="news" class="btn btn-primary"><span class="glyphicon glyphicon-home"></span> News</button>
<button class="server-tab btn btn-success" ng-click="openMenu($event, 'news')"><span class="glyphicon glyphicon-home"></span> News</button>
</li>
<li role="presentation">
<button id="dashboard" class="btn btn-primary"><span class="glyphicon glyphicon-dashboard"></span> Dashboard</button>
<li role="presentation" ng-if="data.settings.descent3.pathValid">
<button class="server-tab btn btn-primary" ng-click="openMenu($event, 'dashboard')"><span class="glyphicon glyphicon-dashboard"></span> Dashboard</button>
</li>
<li role="presentation" ng-repeat="server in servers">
<button class="btn btn-primary server" data-id="{{server.port}}">{{server.gameName}} <span class="glyphicon glyphicon-arrow-right"></span> {{server.port}}</button>
<li role="presentation" ng-if="data.settings.descent3.pathValid" ng-repeat="server in data.servers">
<button class="server-tab btn btn-primary server" ng-click="openServer($event, server.port)">{{server.gameName}} <span class="glyphicon glyphicon-arrow-right"></span> {{server.port}}</button>
</li>
<li role="presentation">
<button id="addserver" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> Add Server</button>
<li role="presentation" ng-if="data.settings.descent3.pathValid">
<button class="server-tab btn btn-primary" ng-click="openMenu($event, 'addServer')"><span class="glyphicon glyphicon-plus"></span> Add Server</button>
</li>
<li role="presentation">
<button id="settings" class="btn btn-primary"><span class="glyphicon glyphicon-cog"></span> Settings</button>
<button class="server-tab btn btn-primary" ng-click="openMenu($event, 'settings')"><span class="glyphicon glyphicon-cog"></span> Settings</button>
</li>
</ul>
@@ -0,0 +1,14 @@
<ul class="nav nav-pills">
<li role="presentation">
<button class="server-menu-tab btn btn-success"><span class="glyphicon glyphicon-dashboard"></span> Scoreboard</button>
</li>
<li role="presentation">
<button class="server-menu-tab btn btn-primary"><span class="glyphicon glyphicon-list-alt"></span> Log</button>
</li>
<li role="presentation">
<button class="server-menu-tab btn btn-primary"><span class="glyphicon glyphicon-console"></span> Console</button>
</li>
<li role="presentation">
<button class="server-menu-tab btn btn-primary"><span class="glyphicon glyphicon-cog"></span> Settings</button>
</li>
</ul>
@@ -0,0 +1,5 @@
<div ng-class="{true: 'input-group', false: 'input-group has-error'}[data.settings.descent3.pathValid]">
<span class="input-group-addon">Enter the path to your Descent 3 folder:</span>
<input class="form-control" placeholder="Your Descent 3 folder" type="text" ng-model="data.settings.descent3.path" ng-blur="updateSettingsDescent3Path()" />
</div>
<div class="alert alert-danger" role="alert" ng-if="!data.settings.descent3.pathValid"><span class="glyphicon glyphicon-alert"></span> Could not find Descent 3 in the directory specified.</div>
No changes.

0 comments on commit c6c2cf4

Please sign in to comment.
You can’t perform that action at this time.