fix some more bugs. add button to show/hide counted cards

This commit is contained in:
Maximilian Keßler 2022-09-16 13:05:25 +02:00
parent b7ac1ddaaa
commit 11dda66088

View File

@ -51,16 +51,21 @@ console.log(styleSheet);
document.head.appendChild(styleSheet);
// add an extra field where we will put down the played cards
var cardsField = document.createElement('div');
cardsField.id = 'cardsField';
cardsField.style.marginLeft = '25px';
var playedHigh = document.createElement('div');
playedHigh.id = 'playedHigh';
playedHigh.style.marginLEft = '25px';
playedHigh.style.marginLeft = '25px';
playedHigh.className = 'row';
playedHigh.hidden = true;
var playedLow = document.createElement('div');
playedLow.id = 'playedLow';
playedLow.style.marginLEft = '25px';
playedLow.style.marginLeft = '25px';
playedLow.className = 'row';
playedLow.hidden = true;
tableIG = document.getElementById('gameField').parentNode;
tableIG.appendChild(playedHigh);
@ -74,7 +79,7 @@ var createCardPlace = function(value, shift, node) {
playedCards.className = 'playedCardsLayout list-unstyled';
playedCards.style.width = '160px';
playedCards.style.marginLeft = '25px';
playedCards.style.left = shift*135 + 'px';
playedCards.style.left = shift*129 + 'px';
node.appendChild(playedCards);
}
@ -88,18 +93,44 @@ for(let i = 8; i > 1; i--) {
createCardPlace(i, 8 - i, document.getElementById('playedLow'));
}
var smartFoldButton = document.createElement('button');
smartFoldButton.className = "btn btn-danger btn-xs";
smartFoldButton.id = "smartFold";
smartFoldButton.type = "button";
smartFoldButton.innerHTML = 'Smart fold: <span id="smartFoldValue" data-on="Yes" data-off="No">Yes</span>';
var showPlayedButton = document.createElement('button');
showPlayedButton.className = "btn btn-warning btn-xs";
showPlayedButton.id = "showPlayed";
showPlayedButton.type = "button";
showPlayedButton.innerHTML = 'Show counted cards: <span id="showPlayedValue" data-on="Yes" data-off="No">No</span>';
buttons = document.getElementById('statusButtons');
buttons.insertBefore(showPlayedButton, document.getElementById('autoFold'));
buttons.insertBefore(smartFoldButton, document.getElementById('autoFold'));
// playedCards.
// ot.$gameField.insertAfter(playedCards, ot.$gameField.lastChild);
// set up counting of played cards
var OnlineTichuCounter = {
$playedCards: {},
$smartFold: $('#smartFold'),
$smartFoldValue: $('#smartFoldValue'),
$showPlayed: $('#showPlayed'),
$showPlayedValue: $('#showPlayedValue'),
$playedHigh: $('#playedHigh'),
$playedLow: $('#playedLow'),
allCards: {},
playedCards: {},
totalPlayed: [],
exchangedTo: {},
exchangedFrom: {},
smartFold: false,
smartFold: true,
showPlayed: false,
bombAfterFold: null,
util: {
displayCardsHtmlString: function(cards) {
@ -205,6 +236,30 @@ if (!window.otc) {
window.otc = OnlineTichuCounter;
}
// add functionality to smartFold button
otc.$smartFold.click(function () {
otc.smartFold = !otc.smartFold;
if (otc.smartFold) {
otc.$smartFoldValue.text(otc.$smartFoldValue.data('on'));
} else {
otc.$smartFoldValue.text(otc.$smartFoldValue.data('off'));
}
});
// add functionality to show button
otc.$showPlayed.click(function () {
otc.showPlayed = !otc.showPlayed;
if (otc.showPlayed) {
otc.$showPlayedValue.text(otc.$showPlayedValue.data('on'));
otc.$playedHigh.show();
otc.$playedLow.show();
} else {
otc.$showPlayedValue.text(otc.$showPlayedValue.data('off'));
otc.$playedHigh.hide();
otc.$playedLow.hide();
}
});
for(let i = 1; i < 15; i++) {
otc.$playedCards[i] = $('#playedCards' + i);
}
@ -221,7 +276,7 @@ MyTableState = (function() {
message = arguments[0];
// console.log('detected table state change event');
console.log(message.Table.Status);
// console.log(message.Table.Status);
// reset played cards at start of round
if(message.Table.Status == 'WaitForNextCards') {
@ -233,14 +288,26 @@ MyTableState = (function() {
}
otc.action.drawPlayedCards();
// otc.$playedCardsQ.html(displayCardsHtmlString);
// $('.horizontalLayouta .card').css('margin-left', '-64px');
// $('#playedCards').css('margin-left', '32px');
// ot.HorizontalAlign(otc.$playedCards);
}
console.log('reached smartFold point');
$(message.Table.Players).each(function () {
if (this.Username == ot.$Username.val()) {
console.log('found player');
if (message.Table.Turn == this.Position) {
console.log('my turn!');
if (this.Cards.length < 4 && this.Cards.length < message.Table.TableCards.length) {
console.log('obvious that have to fold now');
if (otc.smartFold) {
ot.action.Fold();
}
}
}
}
});
return result;
}
})();