improve handling of positions of players and drawing their stats

This commit is contained in:
Maximilian Keßler 2022-10-21 17:30:07 +02:00
parent 2d2843f128
commit 23c26422e6
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -210,11 +210,11 @@ function injectCounter() {
playerMyLevel = document.createElement('div'); playerMyLevel = document.createElement('div');
playerMyLevel.id = direction + 'PlayerMyLevel'; playerMyLevel.id = direction + 'PlayerMyLevel';
playerMyLevel.innerText = 'L A'; playerMyLevel.innerText = '';
playerTichuCoefficient = document.createElement('div'); playerTichuCoefficient = document.createElement('div');
playerTichuCoefficient.id = direction + 'PlayerTichuCoefficient'; playerTichuCoefficient.id = direction + 'PlayerTichuCoefficient';
playerTichuCoefficient.innerText = 'T O'; playerTichuCoefficient.innerText = '';
playerDiv.insertBefore(playerTichuCoefficient, playerTichu); playerDiv.insertBefore(playerTichuCoefficient, playerTichu);
playerDiv.insertBefore(playerMyLevel, playerTichu); playerDiv.insertBefore(playerMyLevel, playerTichu);
@ -467,6 +467,8 @@ function injectCounter() {
} }
otc.totalPlayed = []; otc.totalPlayed = [];
otc.handCardShuffle = []; otc.handCardShuffle = [];
otc.playerNames = {};
otc.stats = {};
}, },
drawPlayedCards: function() { drawPlayedCards: function() {
@ -495,6 +497,9 @@ function injectCounter() {
t = 'T ' + stats.custom.tichuCoefficient + ' O ' + stats.custom.oneTwoCoefficient; t = 'T ' + stats.custom.tichuCoefficient + ' O ' + stats.custom.oneTwoCoefficient;
otc.$playerTichuCoefficient[dirs[i]].text(t); otc.$playerTichuCoefficient[dirs[i]].text(t);
} else {
otc.$playerMyLevel[dirs[i]].text('');
otc.$playerTichuCoefficient[dirs[i]].text('');
} }
} }
console.log('updated shown stats'); console.log('updated shown stats');
@ -605,8 +610,10 @@ function injectCounter() {
message = arguments[0]; message = arguments[0];
// console.log(message);
// console.log('detected table state change event'); // console.log('detected table state change event');
// console.log(message.Table.Status); console.log(message.Table.Players);
// reset played cards at start of round // reset played cards at start of round
if(message.Table.Status == 'WaitForNextCards' && otc.totalPlayed.length != 0) { if(message.Table.Status == 'WaitForNextCards' && otc.totalPlayed.length != 0) {
@ -621,6 +628,10 @@ function injectCounter() {
// console.log('reached smartFold point'); // console.log('reached smartFold point');
spectator = true; spectator = true;
// reset player names as they might have changed
otc.playerNames = {};
$(message.Table.Players).each(function () { $(message.Table.Players).each(function () {
if (this.Username == ot.$Username.val()) { if (this.Username == ot.$Username.val()) {
spectator = false; 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) // get stats of player if we don't have them yet)
if (otc.stats[this.Username] === undefined) { if (otc.stats[this.Username] === undefined) {
otc.util.getStats(this.Username); otc.util.getStats(this.Username);
@ -647,15 +670,14 @@ function injectCounter() {
}); });
// store usernames of players for display of stats // 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) { if (spectator) {
otc.playerNames['south'] = message.Table.Players[0].Username; otc.playerNames['south'] = message.Table.Players[0].Username;
} else { } else {
otc.playerNames['south'] = ot.$Username.val(); otc.playerNames['south'] = ot.$Username.val();
} }
otc.action.updateDisplayStats();
return result; return result;
} }