Skip to content

Commit d21e3e1

Browse files
committed
Add duel flow debug logging
1 parent d42ed28 commit d21e3e1

4 files changed

Lines changed: 87 additions & 3 deletions

File tree

app/js/blockchain/broadcast.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,33 @@ var VizBroadcast = (function() {
9898
d: actionData.d || {}
9999
};
100100

101-
custom(cfg.PROTOCOLS.VM, object, callback);
101+
if (object.t === cfg.ACTION_TYPES.CHALLENGE ||
102+
object.t === cfg.ACTION_TYPES.ACCEPT ||
103+
object.t === cfg.ACTION_TYPES.COMMIT ||
104+
object.t === cfg.ACTION_TYPES.REVEAL ||
105+
object.t === cfg.ACTION_TYPES.FORFEIT) {
106+
console.log('VizBroadcast.gameAction duel', {
107+
user: user,
108+
previous: previous,
109+
type: object.t,
110+
data: object.d
111+
});
112+
}
113+
114+
custom(cfg.PROTOCOLS.VM, object, function(customErr, result) {
115+
if (object.t === cfg.ACTION_TYPES.CHALLENGE ||
116+
object.t === cfg.ACTION_TYPES.ACCEPT ||
117+
object.t === cfg.ACTION_TYPES.COMMIT ||
118+
object.t === cfg.ACTION_TYPES.REVEAL ||
119+
object.t === cfg.ACTION_TYPES.FORFEIT) {
120+
console.log('VizBroadcast.gameAction duel result', {
121+
type: object.t,
122+
err: customErr ? (customErr.message || String(customErr)) : null,
123+
ok: !customErr
124+
});
125+
}
126+
callback(customErr, result);
127+
});
102128
});
103129
}
104130

app/js/engine/state-engine.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ var StateEngine = (function() {
220220
// Validate the action
221221
var validation = ActionValidator.validate(action, worldState, sender, blockNum);
222222
if (!validation.valid) {
223-
console.log('StateEngine: Invalid action from', sender, ':', validation.error);
223+
console.log('StateEngine: Invalid action from', sender, {
224+
type: action.type,
225+
error: validation.error,
226+
data: action.data || {}
227+
});
224228
return events;
225229
}
226230

app/js/ui/screens/arena.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ var ArenaScreen = (function() {
341341
var state = StateEngine.getState();
342342
var playerDuels = DuelStateManager.getPlayerDuels(user || '', state);
343343

344+
console.log('ArenaScreen: render history', {
345+
user: user,
346+
pending: playerDuels.pending.length,
347+
active: playerDuels.active.length,
348+
history: playerDuels.history.length,
349+
headBlock: state && state.headBlock
350+
});
351+
344352
var html = '';
345353

346354
// Active duels

app/js/ui/screens/duel.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,26 @@ var DuelScreen = (function() {
287287
}
288288

289289
function _onIntentSelect() {
290-
if (duelState.selectedIntent) return;
290+
if (duelState.selectedIntent) {
291+
console.log('DuelScreen: intent select ignored because selectedIntent already set', {
292+
selectedIntent: duelState.selectedIntent,
293+
combatRef: duelState.combatRef,
294+
opponent: duelState.opponent,
295+
pendingAction: duelState.pendingAction,
296+
currentRound: duelState.currentRound
297+
});
298+
return;
299+
}
291300

292301
var intent = this.getAttribute('data-intent');
293302
duelState.selectedIntent = intent;
303+
console.log('DuelScreen: intent selected', {
304+
intent: intent,
305+
combatRef: duelState.combatRef,
306+
opponent: duelState.opponent,
307+
pendingAction: duelState.pendingAction,
308+
currentRound: duelState.currentRound
309+
});
294310

295311
var cards = document.querySelectorAll('.spell-card');
296312
for (var i = 0; i < cards.length; i++) {
@@ -324,6 +340,14 @@ var DuelScreen = (function() {
324340
}
325341

326342
function _commitStrategy(intent) {
343+
console.log('DuelScreen: _commitStrategy start', {
344+
intent: intent,
345+
combatRef: duelState.combatRef,
346+
opponent: duelState.opponent,
347+
pendingAction: duelState.pendingAction,
348+
currentRound: duelState.currentRound
349+
});
350+
327351
var salt = DuelSystem.generateSalt();
328352
var strategy = {
329353
intent: intent,
@@ -357,6 +381,11 @@ var DuelScreen = (function() {
357381

358382
// Accept flow: broadcast accept with strategy hash
359383
if (duelState.pendingAction === 'accept' && duelState.combatRef) {
384+
console.log('DuelScreen: broadcasting accept', {
385+
combatRef: duelState.combatRef,
386+
round: duelState.currentRound,
387+
hash: hash
388+
});
360389
DuelProtocol.acceptChallenge(
361390
duelState.combatRef,
362391
hash,
@@ -375,6 +404,11 @@ var DuelScreen = (function() {
375404
);
376405
} else if (duelState.combatRef && duelState.currentRound > 1) {
377406
duelState.pendingAction = 'commit';
407+
console.log('DuelScreen: broadcasting commit', {
408+
combatRef: duelState.combatRef,
409+
round: duelState.currentRound,
410+
hash: hash
411+
});
378412
DuelProtocol.commitStrategy(
379413
duelState.combatRef,
380414
duelState.currentRound,
@@ -394,6 +428,12 @@ var DuelScreen = (function() {
394428
duelState.pendingAction = 'challenge';
395429
var currentBlock = StateEngine.getState().headBlock || 0;
396430
var deadline = currentBlock + VizMagicConfig.BLOCK.DUEL_ACCEPT_WINDOW;
431+
console.log('DuelScreen: broadcasting challenge', {
432+
opponent: duelState.opponent,
433+
currentBlock: currentBlock,
434+
deadline: deadline,
435+
hash: hash
436+
});
397437
DuelProtocol.createChallenge(
398438
duelState.opponent,
399439
'best_of_3', 3, 100, hash, deadline,
@@ -410,6 +450,12 @@ var DuelScreen = (function() {
410450
);
411451
} else if (duelState.combatRef && _canRevealCurrentRound()) {
412452
duelState.pendingAction = 'reveal';
453+
console.log('DuelScreen: broadcasting reveal', {
454+
combatRef: duelState.combatRef,
455+
round: duelState.currentRound,
456+
hash: hash,
457+
intent: intent
458+
});
413459
DuelProtocol.revealStrategy(
414460
duelState.combatRef,
415461
duelState.currentRound,

0 commit comments

Comments
 (0)