Skip to content

Commit 958d334

Browse files
committed
minor fixes with styles, pages aso
1 parent 8fe77f1 commit 958d334

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

src/app/features/game/game.controller.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ export default class GameController {
4646
} else if (message.type === 'phase') {
4747
this.client.setDeadStones(message.deadStones);
4848
} else if (message.type === 'move') {
49-
debug('got move ' + message.move.n + ' and try to do move no ' + this.client.moveNumber() + '/' + this.Game.currentGame.moves.length);
50-
for(let i=this.client.moveNumber(); (typeof this.Game.currentGame.moves[this.client.moveNumber()] !== 'undefined')
51-
&& (i <= (this.Game.currentGame.moves.length-1))
52-
&& ( this.Game.currentGame.moves[this.client.moveNumber()].pk === this.Game.currentGame.players.one
53-
|| this.Game.currentGame.moves[this.client.moveNumber()].pk === this.Game.currentGame.players.two)
49+
let moveNo = this.client.moveNumber();
50+
let moves = this.Game.currentGame.moves;
51+
debug('got move ' + message.move.n + ' and try to do move no ' + moveNo + '/' + moves.length);
52+
for(let i=moves; (typeof moves[moveNo] !== 'undefined')
53+
&& (i <= (moves.length-1))
54+
&& ( move.pk === this.Game.currentGame.players.one
55+
|| move.pk === this.Game.currentGame.players.two)
5456
;i++) {
55-
debug('do move no ' + this.client.moveNumber(), this.Game.currentGame.moves[this.client.moveNumber()]);
56-
this.client._game.playAt(this.Game.currentGame.moves[this.client.moveNumber()].y, this.Game.currentGame.moves[this.client.moveNumber()].x);
57+
debug('do move no ' + moveNo, moves[moveNo]);
58+
this.client._game.playAt(moves[moveNo].y, moves[moveNo].x);
5759
}
5860
}
5961
}

src/app/services/bitcoinNode.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class BitcoinNode extends EventEmitter {
4040
}
4141
];
4242

43+
let latestBlock = localStorage.getItem('block');
44+
if (latestBlock !== null) {
45+
//params.blockchain.checkpoints = localStorage.getItem('block');
46+
}
47+
4348
this.lastBlock = params.blockchain.checkpoints[0].height;
4449

4550
let opts = {

src/app/services/game.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,56 +128,57 @@ class Game {
128128

129129
tx.outs.forEach((out) => {
130130
try {
131-
this.games[gameAddress] = this.games[gameAddress] || angular.copy(this.gameInitState);
131+
let game = this.games[gameAddress] || angular.copy(this.gameInitState);
132132

133133
const chunks = bitcoinjs.script.decompile(out.script);
134134
if(chunks.shift() === bitcoinjs.opcodes.OP_RETURN) {
135135
const message = chunks.toString();
136136
debug('OP_RETURN Message: '+message);
137137

138138
if(message === this.commands.new) {
139-
this.games[gameAddress].state = 'open';
140-
this.games[gameAddress].address.value = tx.outs[1].value;
141-
this.games[gameAddress].address.public = gameAddress;
142-
this.games[gameAddress].players.one = pubKeyIn;
139+
game.state = 'open';
140+
game.address.value = tx.outs[1].value;
141+
game.address.public = gameAddress;
142+
game.players.one = pubKeyIn;
143143
}else if(message === this.commands.pass) {
144-
if(pubKeyIn === this.games[gameAddress].players.one || pubKeyIn === this.games[gameAddress].players.two) {
145-
if (this.games[gameAddress].state !== 'pass') {
146-
this.games[gameAddress].state = 'pass';
144+
if(pubKeyIn === game.players.one || pubKeyIn === game.players.two) {
145+
if (game.state !== 'pass') {
146+
game.state = 'pass';
147147
} else {
148-
this.games[gameAddress].state = 'end';
148+
game.state = 'end';
149149
}
150150
}
151151
}else if(message === this.commands.join) {
152-
this.games[gameAddress].state = 'running';
153-
this.games[gameAddress].players.two = pubKeyIn;
154-
this.games[gameAddress].address.paymentFromTwo = tx.outs[2].pubKey;
152+
game.state = 'running';
153+
game.players.two = pubKeyIn;
154+
game.address.paymentFromTwo = tx.outs[2].pubKey;
155155

156156
if(this.wallet.isOwnAddress(this.currentGame.players.one)) {
157157
const pubKeys = [];
158158
pubKeys[0] = new Buffer(this.masterAddress);
159-
pubKeys[1] = new Buffer(this.games[gameAddress].players.one);
160-
pubKeys[2] = new Buffer(this.games[gameAddress].players.two);
161-
pubKeys[3] = new Buffer(this.games[gameAddress].address.public);
159+
pubKeys[1] = new Buffer(game.players.one);
160+
pubKeys[2] = new Buffer(game.players.two);
161+
pubKeys[3] = new Buffer(game.address.public);
162162

163163
const redeemScript = bitcoinjs.script.multisigOutput(3, pubKeys); // 3 of 4
164164
const scriptPubKey = bitcoinjs.script.scriptHashOutput(bitcoinjs.crypto.hash160(redeemScript));
165-
const payAddress = bitcoinjs.address.fromOutputScript(scriptPubKey, bitcoinjs.networks.testnet);
165+
const payAddress = bitcoinjs.address.fromOutputScript(scriptPubKey, bitcoinjs.networks.testnet);
166166

167-
if(this.games[gameAddress].address.paymentFromTwo === payAddress) {
168-
this.games[gameAddress].address.payment = payAddress;
167+
if(game.address.paymentFromTwo === payAddress) {
168+
game.address.payment = payAddress;
169169
this.wallet.spendOpenGame(gameAddress, payAddress);
170170
}
171171
}
172172
}else{
173173
const data = JSON.parse(message);
174174
const move = {y: data.y, x: data.x, n: data.n, p: data.p, pk: pubKeyIn};
175-
this.games[gameAddress].moves[move.n] = move;
175+
game.moves[move.n] = move;
176176
if (this.currentGame && this.currentGame.state === 'running' && this.currentGame.address.public === gameAddress) this.notifyMove(move);
177177
}
178178
this.tx.count++;
179179
this.tx[this.tx.count] = message;
180180
}
181+
this.games[gameAddress] = game;
181182
}catch(e){
182183
debug('Error with transaction: ', tx, tx.getId());
183184
debug('gameAddress: ', gameAddress);

0 commit comments

Comments
 (0)