From b7ac1ddaaaf15d8d16fe1ee460223f7d81fca68b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 16 Sep 2022 10:21:32 +0200 Subject: [PATCH] some bugfixes. reverse counting now fully working --- .../qutebrowser/greasemonkey/onlinetichu.js | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/.config/qutebrowser/greasemonkey/onlinetichu.js b/.config/qutebrowser/greasemonkey/onlinetichu.js index caeb46a..98eaf8f 100644 --- a/.config/qutebrowser/greasemonkey/onlinetichu.js +++ b/.config/qutebrowser/greasemonkey/onlinetichu.js @@ -99,6 +99,7 @@ var OnlineTichuCounter = { totalPlayed: [], exchangedTo: {}, exchangedFrom: {}, + smartFold: false, util: { displayCardsHtmlString: function(cards) { @@ -127,10 +128,10 @@ var OnlineTichuCounter = { } } otc.allCards[1] = [ - { Shape: 4, Value: 1 }, - { Shape: 5, Value: 0 }, - { Shape: 6, Value: 15}, - { Shape: 7, Value: 14 } + { Shape: 4, Value: 1 }, // mahjong + { Shape: 5, Value: 0 }, // dog + { Shape: 6, Value: 15}, // dragon + { Shape: 7, Value: 14 } // phoenix ]; }, @@ -140,20 +141,23 @@ var OnlineTichuCounter = { if (array[i].Shape == card.Shape && array[i].Value == card.Value) { contained = true; } - return contained; } + return contained; } }, action: { handlePlayedCard: function(card) { -// console.log('Handling a card:'); -// console.log(card); -// console.log(otc.played); index = 0; + // special cards have Shapes 4,5,6,7. We group them at value 1 if(card.Shape >= 4) { index = 1; + if (card.Shape == 7) { + // Treat phoenix as if it had value 14 + // This is important for comparisons later + card.Value = 14; + } } else { index = card.Value; } @@ -166,23 +170,13 @@ var OnlineTichuCounter = { }, handlePlayedCards: function(cards) { - if (cards.length > 0) { - contained = false; - // console.log(message.Table.TableCards[0].Shape); - // console.log(message.Table.TableCards[0].Value); - $(otc.totalPlayed).each(function (index, item) { - if (item.Shape == cards[0].Shape) { - if (item.Value == cards[0].Value) { - contained = true; - } - } - }); - - if(!contained) { - $(message.Table.TableCards).each( - (index, card) => otc.action.handlePlayedCard(card) - ); - } + if (cards.length === 0) { + return; + } + if (!otc.util.cardInArray(cards[0], otc.totalPlayed)) { + $(message.Table.TableCards).each( + (index, card) => otc.action.handlePlayedCard(card) + ); } }, @@ -194,19 +188,14 @@ var OnlineTichuCounter = { }, drawPlayedCards: function() { - console.log('drawing played cards'); - console.log(otc.playedCards); - console.log(otc.allCards); for(let i = 1; i < 15; i++) { cards = []; for(let j=0; j < otc.allCards[i].length; j ++) { if(!otc.util.cardInArray(otc.allCards[i][j], otc.playedCards[i])) { cards.push(otc.allCards[i][j]); } - } -// cards = otc.allCards[i].filter(x => otc.util.cardInArray(x, otc.playedCards[i])); - console.log(cards); otc.$playedCards[i].html(otc.util.displayCardsHtmlString(cards)); + } } } }