1
1
var app = angular . module ( "site" ) ;
2
2
3
- app . controller ( "AbilitiesController" , function ( ) {
3
+ app . controller ( "AbilitiesController" , [ '$scope' , 'NgTableParams' , function ( $scope , NgTableParams ) {
4
4
5
5
this . getPriority = getPriority ;
6
6
this . getPriorityPts = getPriorityPts ;
7
7
this . selectAbility = selectAbility ;
8
+ this . priorityChange = priorityChange ;
8
9
this . abilitiesPage = "./abilities.html" ;
9
10
this . primaryPts = 13 ;
10
11
this . secondaryPts = 9 ;
@@ -20,9 +21,20 @@ app.controller("AbilitiesController", function(){
20
21
{ id : 1 , img : "./empty.png" } ,
21
22
{ id : 2 , img : "./empty.png" } ,
22
23
{ id : 3 , img : "./empty.png" } ,
23
- { id : 4 , img : "./empty.png" } , ] ;
24
+ { id : 4 , img : "./empty.png" } ] ;
25
+
26
+ this . reset = function ( ) {
27
+ this . points . forEach ( function ( ability ) {
28
+ ability . img = './empty.png' ;
29
+ } ) ;
30
+ this . pointCount = 0 ;
31
+ } ;
24
32
25
33
this . select = function ( index ) {
34
+ if ( index == - 1 ) {
35
+ this . reset ( ) ;
36
+ return ;
37
+ }
26
38
if ( this . points [ index ] . img == "./full.png" )
27
39
{
28
40
this . points . forEach ( function ( point ) {
@@ -48,36 +60,36 @@ app.controller("AbilitiesController", function(){
48
60
} ;
49
61
}
50
62
} ;
51
- this . alertness = new Ability ( "alertness " ) ;
52
- this . athletics = new Ability ( "athletics " ) ;
53
- this . awareness = new Ability ( "awareness " ) ;
54
- this . brawl = new Ability ( "brawl " ) ;
55
- this . empathy = new Ability ( "empathy " ) ;
56
- this . expression = new Ability ( "expression " ) ;
57
- this . intimidation = new Ability ( "intimidation " ) ;
58
- this . leadership = new Ability ( "leadership " ) ;
59
- this . streetwise = new Ability ( "streetwise " ) ;
60
- this . subterfuge = new Ability ( "subterfuge " ) ;
61
- this . animalken = new Ability ( "animalken " ) ;
62
- this . crafts = new Ability ( "crafts " ) ;
63
- this . drive = new Ability ( "drive " ) ;
64
- this . etiquette = new Ability ( "etiquette " ) ;
65
- this . firearms = new Ability ( "firearms " ) ;
66
- this . larceny = new Ability ( "larceny " ) ;
67
- this . melee = new Ability ( "melee " ) ;
68
- this . performance = new Ability ( "performance " ) ;
69
- this . stealth = new Ability ( "stealth " ) ;
70
- this . survival = new Ability ( "survival " ) ;
71
- this . academics = new Ability ( "academics " ) ;
72
- this . computer = new Ability ( "computer " ) ;
73
- this . finance = new Ability ( "finance " ) ;
74
- this . investigation = new Ability ( "investigation " ) ;
75
- this . law = new Ability ( "law " ) ;
76
- this . medicine = new Ability ( "medicine " ) ;
77
- this . occult = new Ability ( "occult " ) ;
78
- this . politics = new Ability ( "politics " ) ;
79
- this . science = new Ability ( "science " ) ;
80
- this . technology = new Ability ( "technology " ) ;
63
+ this . alertness = new Ability ( "Alertness " ) ;
64
+ this . athletics = new Ability ( "Athletics " ) ;
65
+ this . awareness = new Ability ( "Awareness " ) ;
66
+ this . brawl = new Ability ( "Brawl " ) ;
67
+ this . empathy = new Ability ( "Empathy " ) ;
68
+ this . expression = new Ability ( "Expression " ) ;
69
+ this . intimidation = new Ability ( "Intimidation " ) ;
70
+ this . leadership = new Ability ( "Leadership " ) ;
71
+ this . streetwise = new Ability ( "Streetwise " ) ;
72
+ this . subterfuge = new Ability ( "Subterfuge " ) ;
73
+ this . animalken = new Ability ( "Animal Ken " ) ;
74
+ this . crafts = new Ability ( "Crafts " ) ;
75
+ this . drive = new Ability ( "Drive " ) ;
76
+ this . etiquette = new Ability ( "Etiquette " ) ;
77
+ this . firearms = new Ability ( "Firearms " ) ;
78
+ this . larceny = new Ability ( "Larceny " ) ;
79
+ this . melee = new Ability ( "Melee " ) ;
80
+ this . performance = new Ability ( "Performance " ) ;
81
+ this . stealth = new Ability ( "Stealth " ) ;
82
+ this . survival = new Ability ( "Survival " ) ;
83
+ this . academics = new Ability ( "Academics " ) ;
84
+ this . computer = new Ability ( "Computer " ) ;
85
+ this . finance = new Ability ( "Finance " ) ;
86
+ this . investigation = new Ability ( "Investigation " ) ;
87
+ this . law = new Ability ( "Law " ) ;
88
+ this . medicine = new Ability ( "Medicine " ) ;
89
+ this . occult = new Ability ( "Occult " ) ;
90
+ this . politics = new Ability ( "Politics " ) ;
91
+ this . science = new Ability ( "Science " ) ;
92
+ this . technology = new Ability ( "Technology " ) ;
81
93
82
94
this . abilityCategories = [
83
95
{
@@ -131,21 +143,16 @@ app.controller("AbilitiesController", function(){
131
143
132
144
function selectAbility ( ability , index ) {
133
145
134
- //Keep in case a bug pops up, but I think this is fixed.
135
- // var catIndex = this.getCategoryIndex(ability.name);
136
- // var sumPointCount = -3;
137
- // this.abilityCategories[catIndex].abilitys.forEach(function(ability){
138
- // sumPointCount += ability.pointCount;
139
- // });
140
-
141
146
var priority = this . getPriority ( ability ) ;
142
147
if ( priority == null ) {
143
148
return null ;
144
149
}
145
150
var priorityPts = this . getPriorityPts ( priority ) ;
151
+
146
152
var pointDiff = ability . pointCount - ( index + 1 ) ;
147
153
148
- //Do math to make sure they can't spend points they don't have, even when priorityPts isn't equal to 0
154
+ //Do math to make sure they can't spend points they don't have,
155
+ //even when priorityPts isn't equal to 0.
149
156
//Case example: increase 3 pts when priorityPts = 2.
150
157
if ( ( priorityPts + pointDiff < 0 ) ) {
151
158
return null ;
@@ -157,8 +164,16 @@ app.controller("AbilitiesController", function(){
157
164
return null ;
158
165
}
159
166
160
- //Change the point count in the ability.
161
- ability . pointCount = ( index + 1 ) ;
167
+ if ( index == 0 && ability . pointCount == 1 ) {
168
+ ability . pointCount = 0 ;
169
+ pointDiff = 1 ;
170
+ index = - 1 ;
171
+ }
172
+ else {
173
+ //Change the point count in the ability.
174
+ ability . pointCount = ( index + 1 ) ;
175
+ }
176
+
162
177
163
178
//Change the total amount of points still available for that category.
164
179
switch ( priority ) {
@@ -177,51 +192,54 @@ app.controller("AbilitiesController", function(){
177
192
this . abilityPtsTotal += pointDiff ;
178
193
//Fill in the dots!
179
194
ability . select ( index ) ;
180
- }
181
- this . rowList = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ;
182
- } ) ;
183
-
184
- app . directive ( 'abilitygrid' , function ( ) {
185
- return {
186
- scope : { row : "@" } ,
187
- restrict : "E" ,
188
- controller : "AbilitiesController" ,
189
- controllerAs : "abCtrl" ,
190
- template : '<abilityrow ng-repeat="row in abCtrl.rowList"></abilityrow>' ,
191
- link : function ( scope , element , attrs ) {
192
- scope . row = attrs . row ;
195
+ } ;
196
+
197
+ function priorityChange ( changedPriority , id , prevPriority ) {
198
+ this . abilityCategories [ id ] . priority = changedPriority ;
199
+ for ( var i = 0 ; i < this . selectedPriorities . length ; i ++ ) {
200
+ if ( changedPriority == this . selectedPriorities [ i ] && id != i ) {
201
+ this . selectedPriorities [ i ] = null ;
202
+ this . abilityCategories [ i ] . abilities . forEach ( function ( abil ) {
203
+ abil . reset ( ) ;
204
+ } ) ;
205
+ }
193
206
}
207
+ //Reset the dots.
208
+ this . abilityCategories [ id ] . abilities . forEach ( function ( abil ) {
209
+ abil . reset ( ) ;
210
+
211
+ } ) ;
212
+ //Reset the point values.
213
+ if ( prevPriority == "Primary" ) {
214
+ this . primaryPts = 13 ;
215
+ }
216
+ if ( prevPriority == "Secondary" ) {
217
+ this . secondaryPts = 9 ;
218
+ }
219
+ if ( prevPriority == "Tertiary" ) {
220
+ this . tertiaryPts = 5 ;
221
+ }
222
+ if ( changedPriority == "Primary" ) {
223
+ this . primaryPts = 13 ;
224
+ }
225
+ if ( changedPriority == "Secondary" ) {
226
+ this . secondaryPts = 9 ;
227
+ }
228
+ if ( changedPriority == "Tertiary" ) {
229
+ this . tertiaryPts = 5 ;
230
+ }
231
+ } ;
232
+
233
+ this . dataSet = function ( ) {
234
+ var data = [ ] ;
235
+ for ( var i = 0 ; i < 10 ; i ++ ) {
236
+ data . push ( { col1 : this . abilityCategories [ 0 ] . abilities [ i ] ,
237
+ col2 : this . abilityCategories [ 1 ] . abilities [ i ] ,
238
+ col3 : this . abilityCategories [ 2 ] . abilities [ i ] } ) ;
239
+ }
240
+ return data ;
194
241
}
195
- } )
196
-
197
- app . directive ( 'abilityrow' , function ( ) {
198
- return {
199
- scope : { row : "@" } ,
200
- restrict : "E" ,
201
- controller : 'AbilitiesController' ,
202
- controllerAs : 'abCtrl' ,
203
- template : '<ability row="{{row}}">{{row}}</ability>' ,
204
- link : function ( scope , element , attrs ) {
205
- scope . row = attrs . row ;
206
- } ,
207
- }
208
- } ) ;
209
-
210
- app . directive ( 'ability' , function ( ) {
211
- return {
212
- scope : { row : "@" } ,
213
- restrict : 'E' ,
214
- controller : 'AbilitiesController' ,
215
- controllerAs : 'abCtrl' ,
216
- template : '<div class="abLabel">{{abCtrl.abilityCategories[row].abilities[row].name}}</div>' ,
217
- // template: '<td>'+
218
- // '<div class="abLabel">'+ability+'</div>'+
219
- // '</td>'+
220
- // '<td>'+
221
- // '<div ng-repeat="'+ability+'Pt in abCtrl.'+ability+'.points" style="display: inline-block;">'+
222
- // '<img ng-src="{{'+ability+'Pt.img}}" ng-click="abCtrl.selectAbility(abCtrl.'+ability+', $index)"'+
223
- // 'style="width:15px; height: 15px;" />'+
224
- // '</td>',
225
- link : function ( scope , element , attrs ) { }
226
- }
227
- } ) ;
242
+ this . tableParams1 = new NgTableParams ( { count : 10 } ,
243
+ { dataset : this . dataSet ( ) , counts : [ ] } ) ;
244
+
245
+ } ] ) ;
0 commit comments