Skip to content

Commit 92409fd

Browse files
committed
Finishing up the 1.0 release -- Added captured stones.
1 parent 91ee251 commit 92409fd

7 files changed

Lines changed: 96 additions & 44 deletions

File tree

src/compiled/glift.js

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiled/glift_combined.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5172,7 +5172,7 @@ glift.displays.statusbar._StatusBar.prototype = {
51725172
*
51735173
* Note: Key bindings are set in the base_widget.
51745174
*/
5175-
gameInfo: function(gameInfoArr) {
5175+
gameInfo: function(gameInfoArr, captureCount) {
51765176
var wrapperDivId = this.widget.wrapperDiv,
51775177
suffix = '_gameinfo',
51785178
newDivId = wrapperDivId + suffix + '_wrapper',
@@ -5214,13 +5214,19 @@ glift.displays.statusbar._StatusBar.prototype = {
52145214
textDiv.on('click', function() { newDiv.remove(); });
52155215
}
52165216

5217+
// This is a hack until a better solution for captures can be crafted.
5218+
var captureArr = [
5219+
{displayName: 'Captured White Stones', value: captureCount.WHITE},
5220+
{displayName: 'Captured Black Stones', value: captureCount.BLACK}
5221+
];
5222+
gameInfoArr = captureArr.concat(gameInfoArr);
5223+
52175224
var textArray = [];
52185225
for (var i = 0; i < gameInfoArr.length; i++) {
52195226
var obj = gameInfoArr[i];
52205227
textArray.push('<strong>' + obj.displayName + ': </strong>' + obj.value);
52215228
}
52225229

5223-
52245230
textDiv
52255231
.append(glift.dom.newElem('h3')
52265232
.appendText('Game Info')
@@ -7287,18 +7293,18 @@ Properties.prototype = {
72877293
var gameInfoArr = [];
72887294
// Probably should live in a more canonical place (properties.js).
72897295
var propNameMap = {
7290-
GN: 'Game Name',
72917296
PW: 'White Player',
72927297
PB: 'Black Player',
72937298
RE: 'Result',
72947299
AN: 'Commenter',
72957300
SO: 'Source',
72967301
RU: 'Ruleset',
72977302
KM: 'Komi',
7298-
PC: 'Place Name',
7299-
DT: 'Date',
7303+
GN: 'Game Name',
73007304
EV: 'Event',
7301-
RO: 'Round'
7305+
RO: 'Round',
7306+
PC: 'Place Name',
7307+
DT: 'Date'
73027308
};
73037309
for (var key in propNameMap) {
73047310
if (this.contains(key)) {
@@ -8092,25 +8098,41 @@ BaseController.prototype = {
80928098
this.movetree, this.goban, this.problemConditions);
80938099
},
80948100

8095-
/**
8096-
* Return only the necessary information to update the board
8097-
*/
8101+
/** Return only the necessary information to update the board. */
80988102
// TODO(kashomon): Rename to getCurrentBoardState
80998103
getNextBoardState: function() {
81008104
return glift.bridge.intersections.nextBoardData(
81018105
this.movetree, this.getCaptures(), this.problemConditions);
81028106
},
81038107

8104-
/**
8105-
* Get the captures that occured for the current move.
8106-
*/
8108+
/** Get the captures that occured for the current move. */
81078109
getCaptures: function() {
81088110
if (this.captureHistory.length === 0) {
81098111
return { BLACK: [], WHITE: [] };
81108112
}
81118113
return this.captureHistory[this.currentMoveNumber() - 1];
81128114
},
81138115

8116+
/**
8117+
* Get the captures count. Returns an object of the form
8118+
* {
8119+
* BLACK: <number>
8120+
* WHITE: <number>
8121+
* }
8122+
*/
8123+
// TODO(kashomon): Add tests
8124+
getCaptureCount: function() {
8125+
var countObj = { BLACK: 0, WHITE: 0 };
8126+
for (var i = 0; i < this.captureHistory.length; i++ ) {
8127+
var obj = this.captureHistory[i];
8128+
console.log(obj);
8129+
for (var color in obj) {
8130+
countObj[color] += obj[color].length;
8131+
}
8132+
}
8133+
return countObj;
8134+
},
8135+
81148136
/**
81158137
* Return true if a Stone can (probably) be added to the board and false
81168138
* otherwise.
@@ -10697,8 +10719,9 @@ glift.widgets.options.baseOptions = {
1069710719
* requests.
1069810720
*
1069910721
* Examples:
10700-
* 'images/kaya.jpg'
10701-
* 'http://www.mywebbie.com/images/kaya.jpg'
10722+
* 'images/kaya.jpg'
10723+
* 'http://www.mywebbie.com/images/kaya.jpg'
10724+
*
1070210725
* @api(1.0)
1070310726
*/
1070410727
goBoardBackground: '',
@@ -10767,6 +10790,7 @@ glift.widgets.options.baseOptions = {
1076710790
/**
1076810791
* Actions for stones. If the user specifies his own actions, then the
1076910792
* actions specified by the user will take precedence.
10793+
* @api(1.0)
1077010794
*/
1077110795
stoneActions: {
1077210796
/**
@@ -10975,7 +10999,9 @@ glift.widgets.options.baseOptions = {
1097510999
'game-info': {
1097611000
click: function(event, widget, icon, iconBar) {
1097711001
widget.statusBar &&
10978-
widget.statusBar.gameInfo(widget.controller.getGameInfo());
11002+
widget.statusBar.gameInfo(
11003+
widget.controller.getGameInfo(),
11004+
widget.controller.getCaptureCount());
1097911005
},
1098011006
tooltip: 'Show the game info'
1098111007
},

src/controllers/base.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,41 @@ BaseController.prototype = {
134134
this.movetree, this.goban, this.problemConditions);
135135
},
136136

137-
/**
138-
* Return only the necessary information to update the board
139-
*/
137+
/** Return only the necessary information to update the board. */
140138
// TODO(kashomon): Rename to getCurrentBoardState
141139
getNextBoardState: function() {
142140
return glift.bridge.intersections.nextBoardData(
143141
this.movetree, this.getCaptures(), this.problemConditions);
144142
},
145143

146-
/**
147-
* Get the captures that occured for the current move.
148-
*/
144+
/** Get the captures that occured for the current move. */
149145
getCaptures: function() {
150146
if (this.captureHistory.length === 0) {
151147
return { BLACK: [], WHITE: [] };
152148
}
153149
return this.captureHistory[this.currentMoveNumber() - 1];
154150
},
155151

152+
/**
153+
* Get the captures count. Returns an object of the form
154+
* {
155+
* BLACK: <number>
156+
* WHITE: <number>
157+
* }
158+
*/
159+
// TODO(kashomon): Add tests
160+
getCaptureCount: function() {
161+
var countObj = { BLACK: 0, WHITE: 0 };
162+
for (var i = 0; i < this.captureHistory.length; i++ ) {
163+
var obj = this.captureHistory[i];
164+
console.log(obj);
165+
for (var color in obj) {
166+
countObj[color] += obj[color].length;
167+
}
168+
}
169+
return countObj;
170+
},
171+
156172
/**
157173
* Return true if a Stone can (probably) be added to the board and false
158174
* otherwise.

src/displays/statusbar/statusbar.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ glift.displays.statusbar._StatusBar.prototype = {
4545
*
4646
* Note: Key bindings are set in the base_widget.
4747
*/
48-
gameInfo: function(gameInfoArr) {
48+
gameInfo: function(gameInfoArr, captureCount) {
4949
var wrapperDivId = this.widget.wrapperDiv,
5050
suffix = '_gameinfo',
5151
newDivId = wrapperDivId + suffix + '_wrapper',
@@ -87,13 +87,19 @@ glift.displays.statusbar._StatusBar.prototype = {
8787
textDiv.on('click', function() { newDiv.remove(); });
8888
}
8989

90+
// This is a hack until a better solution for captures can be crafted.
91+
var captureArr = [
92+
{displayName: 'Captured White Stones', value: captureCount.WHITE},
93+
{displayName: 'Captured Black Stones', value: captureCount.BLACK}
94+
];
95+
gameInfoArr = captureArr.concat(gameInfoArr);
96+
9097
var textArray = [];
9198
for (var i = 0; i < gameInfoArr.length; i++) {
9299
var obj = gameInfoArr[i];
93100
textArray.push('<strong>' + obj.displayName + ': </strong>' + obj.value);
94101
}
95102

96-
97103
textDiv
98104
.append(glift.dom.newElem('h3')
99105
.appendText('Game Info')

src/rules/properties.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,18 @@ Properties.prototype = {
327327
var gameInfoArr = [];
328328
// Probably should live in a more canonical place (properties.js).
329329
var propNameMap = {
330-
GN: 'Game Name',
331330
PW: 'White Player',
332331
PB: 'Black Player',
333332
RE: 'Result',
334333
AN: 'Commenter',
335334
SO: 'Source',
336335
RU: 'Ruleset',
337336
KM: 'Komi',
338-
PC: 'Place Name',
339-
DT: 'Date',
337+
GN: 'Game Name',
340338
EV: 'Event',
341-
RO: 'Round'
339+
RO: 'Round',
340+
PC: 'Place Name',
341+
DT: 'Date'
342342
};
343343
for (var key in propNameMap) {
344344
if (this.contains(key)) {

src/rules/properties_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ glift.rules.propertiesTest = function() {
7878
var props = properties();
7979
props.add('GN', 'Zod').add('PW', 'Rod').add('PB', 'Zod');
8080
deepEqual(props.getGameInfo(), [
81-
{ prop: 'GN', displayName: 'Game Name', value: 'Zod'},
8281
{ prop: 'PW', displayName: 'White Player', value: 'Rod'},
8382
{ prop: 'PB', displayName: 'Black Player', value: 'Zod'},
83+
{ prop: 'GN', displayName: 'Game Name', value: 'Zod'}
8484
]);
8585
});
8686

src/widgets/options/base_options.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,9 @@ glift.widgets.options.baseOptions = {
261261
* requests.
262262
*
263263
* Examples:
264-
* 'images/kaya.jpg'
265-
* 'http://www.mywebbie.com/images/kaya.jpg'
264+
* 'images/kaya.jpg'
265+
* 'http://www.mywebbie.com/images/kaya.jpg'
266+
*
266267
* @api(1.0)
267268
*/
268269
goBoardBackground: '',
@@ -331,6 +332,7 @@ glift.widgets.options.baseOptions = {
331332
/**
332333
* Actions for stones. If the user specifies his own actions, then the
333334
* actions specified by the user will take precedence.
335+
* @api(1.0)
334336
*/
335337
stoneActions: {
336338
/**
@@ -539,7 +541,9 @@ glift.widgets.options.baseOptions = {
539541
'game-info': {
540542
click: function(event, widget, icon, iconBar) {
541543
widget.statusBar &&
542-
widget.statusBar.gameInfo(widget.controller.getGameInfo());
544+
widget.statusBar.gameInfo(
545+
widget.controller.getGameInfo(),
546+
widget.controller.getCaptureCount());
543547
},
544548
tooltip: 'Show the game info'
545549
},

0 commit comments

Comments
 (0)