Created
November 18, 2013 22:23
-
-
Save selahlynch/7536450 to your computer and use it in GitHub Desktop.
gameBoard controller definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('simulateApp') | |
.controller('InstructorGameBoardCtrl', ['$scope', '$rootScope', 'NEWS', '$timeout', 'GameCharacter', 'Chat', 'gameBoardData', 'Data', 'players', '$location', 'DecisionsDataAnalyzer', 'Timer', 'GameStateManagement', '$route', function ($scope, $rootScope, NEWS, $timeout, GameCharacter, Chat, gameBoardData, Data, players, $location, DecisionsDataAnalyzer, Timer, GameStateManagement, $route) { | |
$rootScope._pageTitle = 'Gameboard'; | |
var newsToMerge; | |
var newestFirst = function (a, b) { | |
return b.date - a.date; | |
}; | |
(function gameTimer () { | |
var now = (new Date).getTime(); | |
var t = new Timer(gameBoardData.gameData.gameEndTime - now, function (m, s) { | |
$scope.timeRemaining = m + ":" + s; | |
}, function () { | |
$scope.timeRemaining = "Game Over"; | |
}); | |
t.start(); | |
})(); | |
(function gameStats() { | |
var Stat = function (name, singularName, val) { | |
this.name = (val === 1 ? singularName : name); | |
this.val = val; | |
}; | |
$timeout((function updateStats (origin) { | |
return function () { | |
if ($location.path() === origin) { | |
Data.getGameData(gameBoardData.playerRunId).then(function (d) { | |
if ($location.path() === origin) { | |
$scope.gameStats = []; | |
var dataAdapter = DecisionsDataAnalyzer(d); | |
$scope.gameStats.push(new Stat("NEW HIRES", "NEW HIRE", dataAdapter.getAllHiredEmployees().length)); | |
$scope.gameStats.push(new Stat("INVESTMENTS", "INVESTMENT", dataAdapter.getInvestmentCount())); | |
$timeout(updateStats($location.path()), 5000); | |
} | |
}); | |
} | |
}; | |
})($location.path()), 10); | |
})(); | |
(function newsFeedNoDecisions() { | |
var gameStart = gameBoardData.gameStartTime; | |
var now = (new Date).getTime(); | |
var intervalLength = 68 * 1000; | |
var intervalCount = Math.floor((now - gameStart) / intervalLength); | |
var numItemsToShow = Math.min(intervalCount, NEWS.length); | |
newsToMerge = NEWS.slice(0, numItemsToShow); | |
_.each(newsToMerge, function (n, i) { | |
n.date = gameStart + (intervalLength * i); | |
}); | |
if (numItemsToShow < NEWS.length) { | |
var firstIntervalLength = (gameStart + (intervalLength * (intervalCount + 1))) - now; | |
$timeout((function displayNewsItem(origin) { | |
return function () { | |
if ($location.path() === origin) { | |
$scope.news.unshift(NEWS[intervalCount]); | |
intervalCount++; | |
if (intervalCount < NEWS.length) { | |
$timeout(displayNewsItem($location.path()), intervalLength); | |
} | |
} | |
}; | |
})($location.path()), firstIntervalLength); | |
} | |
})(); | |
(function newsFeedDecisions() { | |
var extendChatMessage = function (msgObj) { | |
var character = GameCharacter.getInfo(msgObj.fromNickname); | |
msgObj.avatar = character.avatar; | |
msgObj.displayName = character.name; | |
msgObj.content = Chat.getChatMessageContent(msgObj.message); | |
return msgObj; | |
}; | |
$scope.$on("pushChannel-chatMessageReceived", function (e, data) { | |
$scope.$apply(function (scope) { | |
scope.news.unshift(extendChatMessage(data)); | |
}); | |
}); | |
_.each(gameBoardData.eventBasedNews, function (m) { | |
extendChatMessage(m); | |
}); | |
})(); | |
$scope.news = newsToMerge.concat(gameBoardData.eventBasedNews).sort(newestFirst); | |
$scope.resetGame = function () { | |
GameStateManagement.startGame().then(function () { | |
$route.reload(); | |
}); | |
}; | |
$scope.startDebrief = function () { | |
GameStateManagement.startDebrief().then(function () { | |
$location.path("/instructorResultsDashboard"); | |
}); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment