Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[-] Added notification that another user choosing the set now
  • Loading branch information
Igor Kobylin committed Jul 31, 2011
1 parent a7a77c4 commit 070dcad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions setwithme/apps/game/models.py
Expand Up @@ -111,12 +111,14 @@ class GameSessionState:
NORMAL = "NORMAL"
SET_PRESSED = "SET_PRESSED"
SET_PENALTY = "SET_PENALTY"
SET_ANOTHER_USER = "SET_ANOTHER_USER"


GameSessionStateChoices = (
(GameSessionState.NORMAL, 'Normal'),
(GameSessionState.SET_PRESSED, 'Set pressed'),
(GameSessionState.SET_PENALTY, 'Set penalty'),
(GameSessionState.SET_ANOTHER_USER, 'Set another user'),
)


Expand Down Expand Up @@ -181,6 +183,9 @@ def _fix_game_state(self):
if state_pressed:
if not self.set_pressed_dt or (self.set_pressed_dt and\
((now > self.set_pressed_dt + constants.PRESSED_SET_TIMEOUT))):
for gs in self.game.gamesession_set.filter(state=GameSessionState.SET_ANOTHER_USER):
gs.state = GameSessionState.NORMAL
gs.save()
self.state = GameSessionState.SET_PENALTY
self.save()

Expand Down
2 changes: 1 addition & 1 deletion setwithme/apps/game/views.py
Expand Up @@ -94,7 +94,7 @@ def put_set_mark(request, game_id):
gs = game.gamesession_set.get(user=request.user)
gs.press_set()
for g in game.gamesession_set.exclude(user=request.user).all():
g.state = GameSessionState.NORMAL
g.state = GameSessionState.SET_ANOTHER_USER
g.save()
return {'success': True}
return {'success': False}
Expand Down
19 changes: 17 additions & 2 deletions setwithme/static/js/base.js
Expand Up @@ -139,7 +139,13 @@ SetWithMe.getCookie = function(name) {


SetWithMe.Game = {
statuses: {'NORMAL': 'normal', 'SET_CHOOSE': 'set_choose', 'PENALTY': 'penalty', 'GAME_END': 'gameend'},
statuses: {
'NORMAL': 'normal',
'SET_CHOOSE': 'set_choose',
'PENALTY': 'penalty',
'GAME_END': 'gameend',
SET_ANOTHER_USER: 'set_another_user'
},
_status: null,
_statusChangedAt: null,

Expand Down Expand Up @@ -189,6 +195,11 @@ SetWithMe.Game = {
this.uninit();
$('.winner_plate').show();
}

if (newStatus == this.statuses.SET_ANOTHER_USER) {
this._setButtonLabel.text('Another user choosing the set...');
this._setButton.addClass('disabled');
}
},

_updateStatus: function() {
Expand Down Expand Up @@ -286,7 +297,8 @@ SetWithMe.Game = {

_onPutSet: function(data) {
if (data.success === false) {
this._changeStatus(this.statuses.PENALTY);
this._stopCountDown();
this._changeStatus(this.statuses.SET_ANOTHER_USER);
}
},

Expand Down Expand Up @@ -452,6 +464,9 @@ SetWithMe.Game = {
if (this._user.state == 'SET_PRESSED') {
this._changeStatus(this.statuses.SET_CHOOSE);
}
if (this._user.state == 'SET_ANOTHER_USER') {
this._changeStatus(this.statuses.SET_ANOTHER_USER);
}
if (data.game.is_finished) {
this._changeStatus(this.statuses.GAME_END);
}
Expand Down

0 comments on commit 070dcad

Please sign in to comment.