Skip to content

Commit

Permalink
Finishing up the 1.0 release -- Added captured stones.
Browse files Browse the repository at this point in the history
  • Loading branch information
artasparks committed Oct 3, 2014
1 parent 91ee251 commit 92409fd
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 44 deletions.
26 changes: 13 additions & 13 deletions src/compiled/glift.js

Large diffs are not rendered by default.

56 changes: 41 additions & 15 deletions src/compiled/glift_combined.js
Original file line number Diff line number Diff line change
Expand Up @@ -5172,7 +5172,7 @@ glift.displays.statusbar._StatusBar.prototype = {
*
* Note: Key bindings are set in the base_widget.
*/
gameInfo: function(gameInfoArr) {
gameInfo: function(gameInfoArr, captureCount) {
var wrapperDivId = this.widget.wrapperDiv,
suffix = '_gameinfo',
newDivId = wrapperDivId + suffix + '_wrapper',
Expand Down Expand Up @@ -5214,13 +5214,19 @@ glift.displays.statusbar._StatusBar.prototype = {
textDiv.on('click', function() { newDiv.remove(); });
}

// This is a hack until a better solution for captures can be crafted.
var captureArr = [
{displayName: 'Captured White Stones', value: captureCount.WHITE},
{displayName: 'Captured Black Stones', value: captureCount.BLACK}
];
gameInfoArr = captureArr.concat(gameInfoArr);

var textArray = [];
for (var i = 0; i < gameInfoArr.length; i++) {
var obj = gameInfoArr[i];
textArray.push('<strong>' + obj.displayName + ': </strong>' + obj.value);
}


textDiv
.append(glift.dom.newElem('h3')
.appendText('Game Info')
Expand Down Expand Up @@ -7287,18 +7293,18 @@ Properties.prototype = {
var gameInfoArr = [];
// Probably should live in a more canonical place (properties.js).
var propNameMap = {
GN: 'Game Name',
PW: 'White Player',
PB: 'Black Player',
RE: 'Result',
AN: 'Commenter',
SO: 'Source',
RU: 'Ruleset',
KM: 'Komi',
PC: 'Place Name',
DT: 'Date',
GN: 'Game Name',
EV: 'Event',
RO: 'Round'
RO: 'Round',
PC: 'Place Name',
DT: 'Date'
};
for (var key in propNameMap) {
if (this.contains(key)) {
Expand Down Expand Up @@ -8092,25 +8098,41 @@ BaseController.prototype = {
this.movetree, this.goban, this.problemConditions);
},

/**
* Return only the necessary information to update the board
*/
/** Return only the necessary information to update the board. */
// TODO(kashomon): Rename to getCurrentBoardState
getNextBoardState: function() {
return glift.bridge.intersections.nextBoardData(
this.movetree, this.getCaptures(), this.problemConditions);
},

/**
* Get the captures that occured for the current move.
*/
/** Get the captures that occured for the current move. */
getCaptures: function() {
if (this.captureHistory.length === 0) {
return { BLACK: [], WHITE: [] };
}
return this.captureHistory[this.currentMoveNumber() - 1];
},

/**
* Get the captures count. Returns an object of the form
* {
* BLACK: <number>
* WHITE: <number>
* }
*/
// TODO(kashomon): Add tests
getCaptureCount: function() {
var countObj = { BLACK: 0, WHITE: 0 };
for (var i = 0; i < this.captureHistory.length; i++ ) {
var obj = this.captureHistory[i];
console.log(obj);
for (var color in obj) {
countObj[color] += obj[color].length;
}
}
return countObj;
},

/**
* Return true if a Stone can (probably) be added to the board and false
* otherwise.
Expand Down Expand Up @@ -10697,8 +10719,9 @@ glift.widgets.options.baseOptions = {
* requests.
*
* Examples:
* 'images/kaya.jpg'
* 'http://www.mywebbie.com/images/kaya.jpg'
* 'images/kaya.jpg'
* 'http://www.mywebbie.com/images/kaya.jpg'
*
* @api(1.0)
*/
goBoardBackground: '',
Expand Down Expand Up @@ -10767,6 +10790,7 @@ glift.widgets.options.baseOptions = {
/**
* Actions for stones. If the user specifies his own actions, then the
* actions specified by the user will take precedence.
* @api(1.0)
*/
stoneActions: {
/**
Expand Down Expand Up @@ -10975,7 +10999,9 @@ glift.widgets.options.baseOptions = {
'game-info': {
click: function(event, widget, icon, iconBar) {
widget.statusBar &&
widget.statusBar.gameInfo(widget.controller.getGameInfo());
widget.statusBar.gameInfo(
widget.controller.getGameInfo(),
widget.controller.getCaptureCount());
},
tooltip: 'Show the game info'
},
Expand Down
28 changes: 22 additions & 6 deletions src/controllers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,41 @@ BaseController.prototype = {
this.movetree, this.goban, this.problemConditions);
},

/**
* Return only the necessary information to update the board
*/
/** Return only the necessary information to update the board. */
// TODO(kashomon): Rename to getCurrentBoardState
getNextBoardState: function() {
return glift.bridge.intersections.nextBoardData(
this.movetree, this.getCaptures(), this.problemConditions);
},

/**
* Get the captures that occured for the current move.
*/
/** Get the captures that occured for the current move. */
getCaptures: function() {
if (this.captureHistory.length === 0) {
return { BLACK: [], WHITE: [] };
}
return this.captureHistory[this.currentMoveNumber() - 1];
},

/**
* Get the captures count. Returns an object of the form
* {
* BLACK: <number>
* WHITE: <number>
* }
*/
// TODO(kashomon): Add tests
getCaptureCount: function() {
var countObj = { BLACK: 0, WHITE: 0 };
for (var i = 0; i < this.captureHistory.length; i++ ) {
var obj = this.captureHistory[i];
console.log(obj);
for (var color in obj) {
countObj[color] += obj[color].length;
}
}
return countObj;
},

/**
* Return true if a Stone can (probably) be added to the board and false
* otherwise.
Expand Down
10 changes: 8 additions & 2 deletions src/displays/statusbar/statusbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ glift.displays.statusbar._StatusBar.prototype = {
*
* Note: Key bindings are set in the base_widget.
*/
gameInfo: function(gameInfoArr) {
gameInfo: function(gameInfoArr, captureCount) {
var wrapperDivId = this.widget.wrapperDiv,
suffix = '_gameinfo',
newDivId = wrapperDivId + suffix + '_wrapper',
Expand Down Expand Up @@ -87,13 +87,19 @@ glift.displays.statusbar._StatusBar.prototype = {
textDiv.on('click', function() { newDiv.remove(); });
}

// This is a hack until a better solution for captures can be crafted.
var captureArr = [
{displayName: 'Captured White Stones', value: captureCount.WHITE},
{displayName: 'Captured Black Stones', value: captureCount.BLACK}
];
gameInfoArr = captureArr.concat(gameInfoArr);

var textArray = [];
for (var i = 0; i < gameInfoArr.length; i++) {
var obj = gameInfoArr[i];
textArray.push('<strong>' + obj.displayName + ': </strong>' + obj.value);
}


textDiv
.append(glift.dom.newElem('h3')
.appendText('Game Info')
Expand Down
8 changes: 4 additions & 4 deletions src/rules/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,18 @@ Properties.prototype = {
var gameInfoArr = [];
// Probably should live in a more canonical place (properties.js).
var propNameMap = {
GN: 'Game Name',
PW: 'White Player',
PB: 'Black Player',
RE: 'Result',
AN: 'Commenter',
SO: 'Source',
RU: 'Ruleset',
KM: 'Komi',
PC: 'Place Name',
DT: 'Date',
GN: 'Game Name',
EV: 'Event',
RO: 'Round'
RO: 'Round',
PC: 'Place Name',
DT: 'Date'
};
for (var key in propNameMap) {
if (this.contains(key)) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/properties_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ glift.rules.propertiesTest = function() {
var props = properties();
props.add('GN', 'Zod').add('PW', 'Rod').add('PB', 'Zod');
deepEqual(props.getGameInfo(), [
{ prop: 'GN', displayName: 'Game Name', value: 'Zod'},
{ prop: 'PW', displayName: 'White Player', value: 'Rod'},
{ prop: 'PB', displayName: 'Black Player', value: 'Zod'},
{ prop: 'GN', displayName: 'Game Name', value: 'Zod'}
]);
});

Expand Down
10 changes: 7 additions & 3 deletions src/widgets/options/base_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ glift.widgets.options.baseOptions = {
* requests.
*
* Examples:
* 'images/kaya.jpg'
* 'http://www.mywebbie.com/images/kaya.jpg'
* 'images/kaya.jpg'
* 'http://www.mywebbie.com/images/kaya.jpg'
*
* @api(1.0)
*/
goBoardBackground: '',
Expand Down Expand Up @@ -331,6 +332,7 @@ glift.widgets.options.baseOptions = {
/**
* Actions for stones. If the user specifies his own actions, then the
* actions specified by the user will take precedence.
* @api(1.0)
*/
stoneActions: {
/**
Expand Down Expand Up @@ -539,7 +541,9 @@ glift.widgets.options.baseOptions = {
'game-info': {
click: function(event, widget, icon, iconBar) {
widget.statusBar &&
widget.statusBar.gameInfo(widget.controller.getGameInfo());
widget.statusBar.gameInfo(
widget.controller.getGameInfo(),
widget.controller.getCaptureCount());
},
tooltip: 'Show the game info'
},
Expand Down

0 comments on commit 92409fd

Please sign in to comment.