diff --git a/login/login.css b/cardshifter.css similarity index 100% rename from login/login.css rename to cardshifter.css diff --git a/cardshifter.html b/cardshifter.html index cd16a52..92a56bc 100644 --- a/cardshifter.html +++ b/cardshifter.html @@ -3,17 +3,26 @@ Cardshifter + + + + + + + + +
\ No newline at end of file diff --git a/cardshifter.js b/cardshifter.js index 0bf5216..ec3a389 100644 --- a/cardshifter.js +++ b/cardshifter.js @@ -4,9 +4,10 @@ CardshifterApp.config(function($routeProvider) { $routeProvider .when("/", { // default page is Login controller: "LoginController", - // file name might change templateUrl: "login/login.html", - css: "login/login.css" }) - + .when("/lobby", { + controller: "LobbyController", + templateUrl: "lobby/lobby.html", + }) }); \ No newline at end of file diff --git a/lobby/lobby.html b/lobby/lobby.html new file mode 100644 index 0000000..60c1b47 --- /dev/null +++ b/lobby/lobby.html @@ -0,0 +1,20 @@ +
+
+

Online users:

+ +

Chat:

+ +
+ + +
+
+
\ No newline at end of file diff --git a/lobby/lobby_controller.js b/lobby/lobby_controller.js new file mode 100644 index 0000000..216dca0 --- /dev/null +++ b/lobby/lobby_controller.js @@ -0,0 +1,50 @@ +CardshifterApp.controller("LobbyController", function($scope, $interval, $timeout) { + var CHAT_FEED_LIMIT = 10; + var POLL_FREQ = 2000; + var MESSAGE_DELAY = 3000; + + $scope.users = []; + $scope.chatMessages = []; + + var getUsersMessage = new CardshifterServerAPI.messageTypes.ServerQueryMessage("USERS", ""); + CardshifterServerAPI.sendMessage(getUsersMessage); + + $interval(function() { // update chat and users + while(message = CardshifterServerAPI.getMessage()) { + switch(message.command) { + case "userstatus": + // do conditional checking if user is offline + if(message.status === "OFFLINE") { + for(var i = 0, length = $scope.users.length; i < length; i++) { + // if the user described in the message is the user in this iteration + if($scope.users[i].name === message.name) { + $scope.users.splice(i, 1); // remove that user from the array + } + } + } else { + $scope.users.push(message); + } + + break; + case "chat": + if($scope.chatMessages.length === CHAT_FEED_LIMIT) { + // remove the latest (opposite of earliest) chat message + $scope.chatMessages.shift(); + } + $scope.chatMessages.push(message); + break; + } + } + }, POLL_FREQ); + + $scope.sendMessage = function() { + $scope.sending = true; + var chatMessage = new CardshifterServerAPI.messageTypes.ChatMessage($scope.user_chat_message); + CardshifterServerAPI.sendMessage(chatMessage); + + $scope.user_chat_message = ""; // clear the input box + $timeout(function() { // allow another message to be sent in 3 seconds + $scope.sending = false; + }, MESSAGE_DELAY); + } +}); \ No newline at end of file diff --git a/login/login.html b/login/login.html index ac3aa67..a7c9989 100644 --- a/login/login.html +++ b/login/login.html @@ -1,4 +1,4 @@ -
+

Cardshifter login