show remaining cards, not played ones

This commit is contained in:
Maximilian Keßler 2022-09-15 19:54:02 +02:00
parent 8ce9263b3d
commit 7b2022c0a3

View file

@ -94,10 +94,56 @@ for(let i = 8; i > 1; i--) {
// set up counting of played cards // set up counting of played cards
var OnlineTichuCounter = { var OnlineTichuCounter = {
$playedCards: {}, $playedCards: {},
played: {}, allCards: {},
total_played: [], playedCards: {},
exchanged_to: {}, totalPlayed: [],
exchanged_from: {}, exchangedTo: {},
exchangedFrom: {},
util: {
displayCardsHtmlString: function(cards) {
htmlString = "";
$(cards).each(function () {
var value = this.Value;
if (this.Shape == 7) {
value = 0;
}
htmlString += '<li id="c' + this.Shape + '-' + value
+ '" class="card c' + this.Shape + '-' + value
+ '" data-shape="' + this.Shape + '" data-value="'
+ value + '"></li>';
});
return htmlString;
},
populateAllCards: function() {
for(let val = 2; val < 15; val++) {
otc.allCards[val] = [];
for(let shape = 0; shape < 4; shape++) {
otc.allCards[val].push({
Shape: shape,
Value: val
});
}
}
otc.allCards[1] = [
{ Shape: 4, Value: 1 },
{ Shape: 5, Value: 0 },
{ Shape: 6, Value: 15},
{ Shape: 7, Value: 14 }
];
},
cardInArray: function(card, array) {
contained = false;
for(let i = 0; i < array.length; i++) {
if (array[i].Shape == card.Shape && array[i].Value == card.Value) {
contained = true;
}
return contained;
}
}
},
action: { action: {
@ -111,10 +157,10 @@ var OnlineTichuCounter = {
} else { } else {
index = card.Value; index = card.Value;
} }
otc.played[index].push(card); otc.playedCards[index].push(card);
otc.total_played.push(card); otc.totalPlayed.push(card);
otc.played[index].sort(function(c1, c2){ otc.playedCards[index].sort(function(c1, c2){
return c2.Shape - c1.Shape; return c2.Shape - c1.Shape;
}); });
}, },
@ -124,7 +170,7 @@ var OnlineTichuCounter = {
contained = false; contained = false;
// console.log(message.Table.TableCards[0].Shape); // console.log(message.Table.TableCards[0].Shape);
// console.log(message.Table.TableCards[0].Value); // console.log(message.Table.TableCards[0].Value);
$(otc.total_played).each(function (index, item) { $(otc.totalPlayed).each(function (index, item) {
if (item.Shape == cards[0].Shape) { if (item.Shape == cards[0].Shape) {
if (item.Value == cards[0].Value) { if (item.Value == cards[0].Value) {
contained = true; contained = true;
@ -142,24 +188,25 @@ var OnlineTichuCounter = {
resetPlayedCards: function() { resetPlayedCards: function() {
for(let i = 1; i < 15; i++) { for(let i = 1; i < 15; i++) {
otc.played[i] = []; otc.playedCards[i] = [];
} }
otc.total_played = []; otc.totalPlayed = [];
}, },
drawPlayedCards: function() { drawPlayedCards: function() {
// console.log('drawing played cards'); console.log('drawing played cards');
console.log(otc.played); console.log(otc.playedCards);
console.log(otc.allCards);
for(let i = 1; i < 15; i++) { for(let i = 1; i < 15; i++) {
displayCardsHtmlString = ""; cards = [];
$(otc.played[i]).each(function () { for(let j=0; j < otc.allCards[i].length; j ++) {
var value = this.Value; if(!otc.util.cardInArray(otc.allCards[i][j], otc.playedCards[i])) {
if (this.Shape == 7) { cards.push(otc.allCards[i][j]);
value = 0;
} }
displayCardsHtmlString += '<li id="c' + this.Shape + '-' + value + '" class="card c' + this.Shape + '-' + value + '" data-shape="' + this.Shape + '" data-value="' + value + '"></li>'; }
}); // cards = otc.allCards[i].filter(x => otc.util.cardInArray(x, otc.playedCards[i]));
otc.$playedCards[i].html(displayCardsHtmlString); console.log(cards);
otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards));
} }
} }
} }
@ -174,12 +221,13 @@ for(let i = 1; i < 15; i++) {
} }
otc.action.resetPlayedCards(); otc.action.resetPlayedCards();
otc.util.populateAllCards();
MyTableState = (function() { MyTableState = (function() {
var cached_function = ot.reaction.TableState; var cachedFunction = ot.reaction.TableState;
return function() { return function() {
var result = cached_function.apply(this, arguments); var result = cachedFunction.apply(this, arguments);
message = arguments[0]; message = arguments[0];
@ -208,10 +256,10 @@ MyTableState = (function() {
MyChat = (function() { MyChat = (function() {
var cached_function = ot.reaction.Chat; var cachedFunction = ot.reaction.Chat;
return function() { return function() {
var result = cached_function.apply(this, arguments); var result = cachedFunction.apply(this, arguments);
message = arguments[0]; message = arguments[0];
if (message.User.Username === "System") { if (message.User.Username === "System") {
@ -234,32 +282,32 @@ MyChat = (function() {
})(); })();
MyExchangeCards = (function() { MyExchangeCards = (function() {
var cached_function = ot.action.ExchangeCards; var cachedFunction = ot.action.ExchangeCards;
return function() { return function() {
otc.exchanged_to['west'] = { otc.exchangedTo['west'] = {
Shape: ot.$westExchange.children('li:nth-child(1)').data('shape'), Shape: ot.$westExchange.children('li:nth-child(1)').data('shape'),
Value: ot.$westExchange.children('li:nth-child(1)').data('value') }; Value: ot.$westExchange.children('li:nth-child(1)').data('value') };
otc.exchanged_to['north'] = { otc.exchangedTo['north'] = {
Shape: ot.$northExchange.children('li:nth-child(1)').data('shape'), Shape: ot.$northExchange.children('li:nth-child(1)').data('shape'),
Value: ot.$northExchange.children('li:nth-child(1)').data('value') }; Value: ot.$northExchange.children('li:nth-child(1)').data('value') };
otc.exchanged_to['east'] = { otc.exchangedTo['east'] = {
Shape: ot.$eastExchange.children('li:nth-child(1)').data('shape'), Shape: ot.$eastExchange.children('li:nth-child(1)').data('shape'),
Value: ot.$eastExchange.children('li:nth-child(1)').data('value') }; Value: ot.$eastExchange.children('li:nth-child(1)').data('value') };
console.log(otc.exchanged_to); console.log(otc.exchangedTo);
var result = cached_function.apply(this, arguments); var result = cachedFunction.apply(this, arguments);
return result; return result;
} }
})(); })();
MyReviewExchange = (function() { MyReviewExchange = (function() {
var cached_function = ot.reaction.ReviewExchange; var cachedFunction = ot.reaction.ReviewExchange;
return function() { return function() {
var result = cached_function.apply(this, arguments); var result = cachedFunction.apply(this, arguments);
return result; return result;
} }
})(); })();