diff --git a/onlinetichu-counter.js b/onlinetichu-counter.js index d581225..ef81919 100644 --- a/onlinetichu-counter.js +++ b/onlinetichu-counter.js @@ -210,11 +210,11 @@ function injectCounter() { playerMyLevel = document.createElement('div'); playerMyLevel.id = direction + 'PlayerMyLevel'; - playerMyLevel.innerText = 'L A'; + playerMyLevel.innerText = ''; playerTichuCoefficient = document.createElement('div'); playerTichuCoefficient.id = direction + 'PlayerTichuCoefficient'; - playerTichuCoefficient.innerText = 'T O'; + playerTichuCoefficient.innerText = ''; playerDiv.insertBefore(playerTichuCoefficient, playerTichu); playerDiv.insertBefore(playerMyLevel, playerTichu); @@ -467,6 +467,8 @@ function injectCounter() { } otc.totalPlayed = []; otc.handCardShuffle = []; + otc.playerNames = {}; + otc.stats = {}; }, drawPlayedCards: function() { @@ -495,6 +497,9 @@ function injectCounter() { t = 'T ' + stats.custom.tichuCoefficient + ' O ' + stats.custom.oneTwoCoefficient; otc.$playerTichuCoefficient[dirs[i]].text(t); + } else { + otc.$playerMyLevel[dirs[i]].text(''); + otc.$playerTichuCoefficient[dirs[i]].text(''); } } console.log('updated shown stats'); @@ -605,8 +610,10 @@ function injectCounter() { message = arguments[0]; +// console.log(message); + // console.log('detected table state change event'); -// console.log(message.Table.Status); + console.log(message.Table.Players); // reset played cards at start of round if(message.Table.Status == 'WaitForNextCards' && otc.totalPlayed.length != 0) { @@ -621,6 +628,10 @@ function injectCounter() { // console.log('reached smartFold point'); spectator = true; + + // reset player names as they might have changed + otc.playerNames = {}; + $(message.Table.Players).each(function () { if (this.Username == ot.$Username.val()) { spectator = false; @@ -640,6 +651,18 @@ function injectCounter() { } } + console.log('position of iterated player is: ' + this.Position) + if (ot.eastPlayer != null && ot.eastPlayer == this.Position) { + otc.playerNames['east'] = this.Username; + console.log('found east player'); + } + if (ot.southPlayer != null && ot.southPlayer == this.Position) { + otc.playerNames['south'] = this.Username; + } + if (ot.westPlayer != null && ot.westPlayer == this.Position) { + otc.playerNames['west'] = this.Username; + } + // get stats of player if we don't have them yet) if (otc.stats[this.Username] === undefined) { otc.util.getStats(this.Username); @@ -647,15 +670,14 @@ function injectCounter() { }); // store usernames of players for display of stats - otc.playerNames['east'] = message.Table.Players[ot.eastPlayer - 1].Username; - otc.playerNames['north'] = message.Table.Players[ot.northPlayer - 1].Username; - otc.playerNames['west'] = message.Table.Players[ot.westPlayer - 1].Username; if (spectator) { otc.playerNames['south'] = message.Table.Players[0].Username; } else { otc.playerNames['south'] = ot.$Username.val(); } + otc.action.updateDisplayStats(); + return result; }