Skip to content

Commit

Permalink
Prelim: Work on tutor experience payout when health is 0.
Browse files Browse the repository at this point in the history
Affix tutor and student avatars.
- Restructure page a little.

Tutor health.
- Use health as experience for students.

Bug fixes.
- Prevent tutor from sending question without filling up all fields.
  • Loading branch information
glutSolidSphere committed Apr 11, 2017
1 parent 78089cf commit a06ea7b
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 166 deletions.
5 changes: 5 additions & 0 deletions public/css/lobby.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ h3 {

.chatWhiteSpace {
white-space: pre-wrap;
}

.users-active-list {
max-height:250px;
overflow-y:auto;
}
107 changes: 59 additions & 48 deletions public/javascripts/Lobby/lobby-angular-student-controller.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,73 @@
angular.module('lobbyApp').controller ('studentCtrl', function($scope, socket) {
$scope.socket = socket;
$scope.health = 100;
$scope.maxHealth = 100;
$scope.questions = {};

//Socket events

//Receives questions composed and sent by tutor.
socket.on ('add question', function (data) {
var answers = [];
var tutors = [];
//Extract the students and tutors in the groupmates list and create separate lists of their data.
data.groupmates.forEach (function (groupmate, i) {
if (groupmate.userType == 'tutor') {
tutors.push (groupmate);
} else if (groupmate.userType == 'student') {
var owned = false;
if (groupmate.socketId == socket.socketId()) {
owned = true;
}
answers.push ({
'student' : groupmate,
'description' : '',
'selected' : false,
'owned' : owned,
'selectedCount' : 0
});
}
});
socket.on ( 'login', function (data) {

if (data.userType == 'student') {
//Receives questions composed and sent by tutor
socket.on ('add question', function (data) {
var answers = [];
var tutors = [];
//Extract the students and tutors in the groupmates list and create separate lists of their data.
data.groupmates.forEach (function (groupmate, i) {
if (groupmate.userType == 'tutor') {
tutors.push (groupmate);
} else if (groupmate.userType == 'student') {
var owned = false;
if (groupmate.socketId == socket.socketId()) {
owned = true;
}
answers.push ({
'student' : groupmate,
'description' : '',
'selected' : false,
'owned' : owned,
'selectedCount' : 0
});
}
});

if (!$scope.questions[data.question.uuid]) {
$scope.questions[data.question.uuid] = {
'description' : data.question.description,
'answers' : answers,
'tutors' : tutors,
'uuid' : data.question.uuid,
'submitted' : false
};
}
});

if (!$scope.questions[data.question.uuid]) {
$scope.questions[data.question.uuid] = {
'description' : data.question.description,
'answers' : answers,
'tutors' : tutors,
'uuid' : data.question.uuid,
'submitted' : false
};
}
});
//Update answers composed by other users.
socket.on ('update answer', function (data) {
updateAnswerCounts (data.questionUuid, data.selectedCount);
updateOtherAnswer (data.questionUuid, data.socketId, data.answer);
});

//Update answers composed by other users.
socket.on ('update answer', function (data) {
updateAnswerCounts (data.questionUuid, data.selectedCount);
updateOtherAnswer (data.questionUuid, data.socketId, data.answer);
});
//Someone has submitted the answer.
socket.on ('submit answer', function (data) {
$scope.questions[data.uuid].submitted = true;
});

//Someone has submitted the answer.
socket.on ('submit answer', function (data) {
$scope.questions[data.uuid].submitted = true;
});
//Someone has submitted the answer.
socket.on ('grade question', function (data) {
var question = $scope.questions[data.questionUuid];

//Someone has submitted the answer.
socket.on ('grade question', function (data) {
var question = $scope.questions[data.questionUuid];
question.graded = true;
question.groupNames = data.groupNames;
question.groupAnswers = data.gradedAnswers;
question.selectedGroup = data.groupNames[0];
});

question.graded = true;
question.groupNames = data.groupNames;
question.groupAnswers = data.gradedAnswers;
question.selectedGroup = data.groupNames[0];
socket.on ('update health', function (data) {
$scope.health = data;
});
}
});

//Scope functions.
Expand Down
99 changes: 66 additions & 33 deletions public/javascripts/Lobby/lobby-angular-tutor-controller.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
angular.module('lobbyApp').controller ('tutorCtrl', function($scope, socket) {
$scope.socket = socket;
$scope.health = 100;
$scope.maxHealth = 100;
$scope.selectedGroups = [];
$scope.composerQuestion = {
'description' : ''
};
$scope.questions = {};

socket.on ('submit answer', function (data) {
var question = $scope.questions[data.uuid];
if (question) {
var groupAnswer = question.groupAnswers[data.answer.groupName];
if (groupAnswer) {
groupAnswer.answered = true;
groupAnswer.student = data.answer.student.username;
groupAnswer.description = data.answer.description;
}
}
});
socket.on ('login', function (data) {
if (data.userType == 'tutor') {
socket.on ('submit answer', function (data) {
var question = $scope.questions[data.uuid];
if (question) {
var groupAnswer = question.groupAnswers[data.answer.groupName];
if (groupAnswer) {
groupAnswer.answered = true;
groupAnswer.student = data.answer.student.username;
groupAnswer.description = data.answer.description;
}
}
});

socket.on ('log question', function (data) {
//Object to store the answers receieved from students later.
var groupAnswers = {};
data.question.groups.forEach (function (value) {
groupAnswers[value] = {
'student' : '',
'description' : '',
'explanation' : '',
'experience' : 0,
'answered' : false
};
});

socket.on ('log question', function (data) {
//Object to store the answers receieved from students later.
var groupAnswers = {};
data.question.groups.forEach (function (value) {
groupAnswers[value] = {
'student' : '',
'description' : '',
'explanation' : '',
'experience' : 0,
'answered' : false
};
});

$scope.questions[data.question.uuid] = {
'uuid' : data.question.uuid,
'description' : data.question.description,
'graded' : false,
'groupNames' : data.question.groups,
'groupAnswers' : groupAnswers,
'selectedGroup' : data.question.groups[0]
};
$scope.questions[data.question.uuid] = {
'uuid' : data.question.uuid,
'description' : data.question.description,
'graded' : false,
'groupNames' : data.question.groups,
'groupAnswers' : groupAnswers,
'selectedGroup' : data.question.groups[0]
};
});

socket.on ('reset health', function (data) {
$scope.health = $scope.maxHealth;
});
}
});

$scope.inSelectedGroups = function (index) {
Expand Down Expand Up @@ -102,6 +112,29 @@ angular.module('lobbyApp').controller ('tutorCtrl', function($scope, socket) {
};

$scope.gradeQuestion = function (uuid) {
socket.emit ('grade question', $scope.questions[uuid]);
var question = $scope.questions[uuid];
question.graded = true;

healthLeft = $scope.health;
for (var group in question.groupAnswers) {
if (question.groupAnswers.hasOwnProperty (group)) {
healthLeft = $scope.health - question.groupAnswers[group].experience;
socket.emit ('damage shoutout', {
'group' : group,
'experience' : question.groupAnswers[group].experience
});
}
}

if (healthLeft > 0) {
$scope.health = healthLeft;
} else {
$scope.health = 0;
socket.emit ('experience payout');
}

socket.emit ('update health', $scope.health);

socket.emit ('grade question', question);
};
});
20 changes: 20 additions & 0 deletions source/model/lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,26 @@ lobbyio.on ('connection', function (socket) {
});
}
});

socket.on ('damage shoutout', function (data) {
console.log ("Damage shoutout");
console.log (data);
console.log ("\n");
});

socket.on ('experience payout', function () {
console.log ("Experience payout");
console.log ("\n");
});

socket.on ('update health', function (data) {
var lobby = lobbyList.getLobby(socket.moduleGroup, socket.tutorialGroup);
console.log ("Update health");

lobby.broadcastToLobby (socket, 'update health', data);
console.log (data);
console.log ("\n");
});
}
});

Expand Down
Loading

0 comments on commit a06ea7b

Please sign in to comment.