-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameModel.js
79 lines (65 loc) · 1.89 KB
/
gameModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
Manages all gameModels.
All gameModels elsewhere in the app should point to objects in this manager.
*/
var gameModelManager = new manager();
/*
Holds information about a game.
*/
function gameModel(id, name, logo, storeLink) {
model.call(this);
this.id = id;
this.name = name;
this.logo = logo;
this.storeLink = storeLink;
/*
Users who own this game - managed userModels.
*/
this.users = new manager();
/*
Users who own this game and are selected.
*/
this.selectedUsers = new manager();
//listen for changes in selectedUsers so we can keep track of length
this.selectedUsers.listen(this);
/*
The length of this.selectedUsers.
*/
this.selectedUsersLength = 0;
/*
Users who are selected but don't own this game.
*/
this.selectedUsersLacking = new manager();
this.selectedUsersLacking.listen(this);
/*
The length of this.selectedUsersLacking.
*/
this.selectedUsersLackingLength = 0;
}
gameModel.prototype = {
//Override
equals: function(other) {
return model.prototype.equals(other) || other.id == this.id;
},
onModelAdd: function(source, model) {
if(source == this.selectedUsers) {
//a user was added to this.selectedUsers - increment length
this.change({selectedUsersLength: this.selectedUsersLength+1});
}
else if(source == this.selectedUsersLacking) {
//a user was added to this.selectedUsersLacking - increment length
this.change({selectedUsersLackingLength: this.selectedUsersLackingLength+1});
}
},
onModelRemove: function(source, model) {
if(source == this.selectedUsers) {
//a user was removed from this.selectedUsers - decrement length
this.change({selectedUsersLength: this.selectedUsersLength-1});
}
else if(source == this.selectedUsersLacking) {
//a user was removed from this.selectedUsersLacking - decrement length
this.change({selectedUsersLackingLength: this.selectedUsersLackingLength-1});
}
}
}
extend(gameModel, model);