diff --git a/.config/qutebrowser/greasemonkey/onlinetichu.js b/.config/qutebrowser/greasemonkey/onlinetichu.js index 504f6bc..caeb46a 100644 --- a/.config/qutebrowser/greasemonkey/onlinetichu.js +++ b/.config/qutebrowser/greasemonkey/onlinetichu.js @@ -94,10 +94,56 @@ for(let i = 8; i > 1; i--) { // set up counting of played cards var OnlineTichuCounter = { $playedCards: {}, - played: {}, - total_played: [], - exchanged_to: {}, - exchanged_from: {}, + allCards: {}, + playedCards: {}, + totalPlayed: [], + exchangedTo: {}, + exchangedFrom: {}, + + util: { + displayCardsHtmlString: function(cards) { + htmlString = ""; + $(cards).each(function () { + var value = this.Value; + if (this.Shape == 7) { + value = 0; + } + htmlString += '
  • '; + }); + 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: { @@ -111,10 +157,10 @@ var OnlineTichuCounter = { } else { index = card.Value; } - otc.played[index].push(card); - otc.total_played.push(card); + otc.playedCards[index].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; }); }, @@ -124,7 +170,7 @@ var OnlineTichuCounter = { contained = false; // console.log(message.Table.TableCards[0].Shape); // 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.Value == cards[0].Value) { contained = true; @@ -142,24 +188,25 @@ var OnlineTichuCounter = { resetPlayedCards: function() { for(let i = 1; i < 15; i++) { - otc.played[i] = []; + otc.playedCards[i] = []; } - otc.total_played = []; + otc.totalPlayed = []; }, drawPlayedCards: function() { -// console.log('drawing played cards'); - console.log(otc.played); + console.log('drawing played cards'); + console.log(otc.playedCards); + console.log(otc.allCards); for(let i = 1; i < 15; i++) { - displayCardsHtmlString = ""; - $(otc.played[i]).each(function () { - var value = this.Value; - if (this.Shape == 7) { - value = 0; + 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]); } - displayCardsHtmlString += '
  • '; - }); - otc.$playedCards[i].html(displayCardsHtmlString); + } +// cards = otc.allCards[i].filter(x => otc.util.cardInArray(x, otc.playedCards[i])); + 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.util.populateAllCards(); MyTableState = (function() { - var cached_function = ot.reaction.TableState; + var cachedFunction = ot.reaction.TableState; return function() { - var result = cached_function.apply(this, arguments); + var result = cachedFunction.apply(this, arguments); message = arguments[0]; @@ -208,10 +256,10 @@ MyTableState = (function() { MyChat = (function() { - var cached_function = ot.reaction.Chat; + var cachedFunction = ot.reaction.Chat; return function() { - var result = cached_function.apply(this, arguments); + var result = cachedFunction.apply(this, arguments); message = arguments[0]; if (message.User.Username === "System") { @@ -234,32 +282,32 @@ MyChat = (function() { })(); MyExchangeCards = (function() { - var cached_function = ot.action.ExchangeCards; + var cachedFunction = ot.action.ExchangeCards; return function() { - otc.exchanged_to['west'] = { + otc.exchangedTo['west'] = { Shape: ot.$westExchange.children('li:nth-child(1)').data('shape'), 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'), 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'), 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; } })(); MyReviewExchange = (function() { - var cached_function = ot.reaction.ReviewExchange; + var cachedFunction = ot.reaction.ReviewExchange; return function() { - var result = cached_function.apply(this, arguments); + var result = cachedFunction.apply(this, arguments); return result; } })();