From 086c0b0d52ed24392d2dbba503b801dea698ff08 Mon Sep 17 00:00:00 2001 From: Peiyan Yang Date: Sat, 30 Apr 2022 15:16:53 -0700 Subject: [PATCH 01/25] Select username before first hand --- .../ui/record-game/RecordJapaneseGame.html | 138 +++++++++--------- imports/ui/record-game/RecordJapaneseGame.js | 16 ++ 2 files changed, 88 insertions(+), 66 deletions(-) diff --git a/imports/ui/record-game/RecordJapaneseGame.html b/imports/ui/record-game/RecordJapaneseGame.html index d6e55ea..d7594d6 100644 --- a/imports/ui/record-game/RecordJapaneseGame.html +++ b/imports/ui/record-game/RecordJapaneseGame.html @@ -2,7 +2,7 @@

Riichi Japanese Mahjong Game Sheet

-
+

East

-
diff --git a/imports/ui/record-game/RecordJapaneseGame.js b/imports/ui/record-game/RecordJapaneseGame.js index 953ea93..0d22617 100644 --- a/imports/ui/record-game/RecordJapaneseGame.js +++ b/imports/ui/record-game/RecordJapaneseGame.js @@ -352,6 +352,22 @@ Template.RecordJapaneseGame.events({ } } }, + + //Submission of names + 'click .submit_names_button'(event, template) { + if ( !$( event.target ).hasClass( "disabled")) { + if (GameRecordUtils.allPlayersSelected()) { + document.getElementById("jpn_buttons").style.display = "block"; + document.getElementById("jpn_rest").style.display = "block"; + document.getElementById("jpn_dynamic").style.display = "block"; + document.getElementById("jpn_players").style.display = "none"; + document.getElementById("submit_button").style.display = "none"; + } else { + window.alert("please enter all 4 player names!"); + } + } + }, + //Submission of a hand 'click .submit_hand_button'(event, template) { From c6e23aa3b73c1804a85028ec3e3e06cbe368b68c Mon Sep 17 00:00:00 2001 From: Peiyan Yang Date: Sun, 1 May 2022 01:15:51 -0700 Subject: [PATCH 02/25] Added game summaries on the home page --- client/stylesheets/Home.css | 50 +++++++++++++++++++++++++++++++ client/{ => stylesheets}/Main.css | 0 imports/ui/Index.js | 2 +- imports/ui/home/Home.html | 37 +++++++++++++++++++++++ imports/ui/home/Home.js | 35 ++++++++++++++++++++++ imports/ui/static/Home.html | 4 --- package.json | 2 +- 7 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 client/stylesheets/Home.css rename client/{ => stylesheets}/Main.css (100%) create mode 100644 imports/ui/home/Home.html create mode 100644 imports/ui/home/Home.js delete mode 100644 imports/ui/static/Home.html diff --git a/client/stylesheets/Home.css b/client/stylesheets/Home.css new file mode 100644 index 0000000..fc71132 --- /dev/null +++ b/client/stylesheets/Home.css @@ -0,0 +1,50 @@ +.game-list { + display: flex; + flex-wrap: wrap; + justify-content: center; +} + +.summary-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 8px; + margin: 8px; + border: 3px solid black; + border-radius: 8px; + font-family: "Helvetica Neue"; + font-size: 20px; + cursor: pointer; +} + +.summary-container:hover { + background-color: #eee; +} + +.summary-column-container { + display: flex; + margin: 12px 0; +} + +.summary-column-container > div { + margin: 0 8px; +} + +.winds { + text-align: left; +} + +.points { + text-align: right; +} + +.username { + width: 150px; +} + +.username > div { + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} diff --git a/client/Main.css b/client/stylesheets/Main.css similarity index 100% rename from client/Main.css rename to client/stylesheets/Main.css diff --git a/imports/ui/Index.js b/imports/ui/Index.js index 377a256..cd1471c 100644 --- a/imports/ui/Index.js +++ b/imports/ui/Index.js @@ -1,7 +1,7 @@ import './static/About.html'; -import './static/Home.html'; import './Index.html'; +import './home/Home'; import './record-game/RecordHongKongGame'; import './record-game/RecordJapaneseGame'; import './ranking/Ranking'; diff --git a/imports/ui/home/Home.html b/imports/ui/home/Home.html new file mode 100644 index 0000000..b969b0b --- /dev/null +++ b/imports/ui/home/Home.html @@ -0,0 +1,37 @@ + + + \ No newline at end of file diff --git a/imports/ui/home/Home.js b/imports/ui/home/Home.js new file mode 100644 index 0000000..2342ecd --- /dev/null +++ b/imports/ui/home/Home.js @@ -0,0 +1,35 @@ +import { Template } from 'meteor/templating'; +import Constants from '../../api/Constants'; +import GameRecordUtils from '../../api/utils/GameRecordUtils'; + +import { JapaneseHands, HongKongHands } from '../../api/GameDatabases'; + +import './Home.html'; + +Template.Home.onCreated( function() { + console.log("created"); +}); + +Template.Home.helpers({ + current_games() { + return JapaneseHands.find().fetch(); + } +}); + +Template.game_summary.helpers({ + displayScore(score) { + return (score / 1000).toFixed(1); + }, + displayRoundWind(rounds) { + let lastRound = rounds[rounds.length - 1]; + return GameRecordUtils.displayRoundWind(lastRound.round, Constants.GAME_TYPE.JAPANESE); + }, + displayRoundNumber(rounds) { + let lastRound = rounds[rounds.length - 1]; + return GameRecordUtils.handNumberToRoundNumber(lastRound.round, Constants.GAME_TYPE.JAPANESE); + }, + getBonus(rounds) { + let lastRound = rounds[rounds.length - 1]; + return lastRound.bonus; + } +}); diff --git a/imports/ui/static/Home.html b/imports/ui/static/Home.html deleted file mode 100644 index 56446ff..0000000 --- a/imports/ui/static/Home.html +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/package.json b/package.json index edea6dd..1307eed 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "start": "meteor run" }, "dependencies": { - "@babel/runtime": "^7.14.8", + "@babel/runtime": "^7.17.9", "babel-runtime": "^6.26.0", "body-parser": "^1.15.2", "meteor-node-stubs": "~0.2.0" From 246419d400e02407a446de3234e62e3e76670073 Mon Sep 17 00:00:00 2001 From: Peiyan Yang Date: Mon, 2 May 2022 23:51:20 -0700 Subject: [PATCH 03/25] extend summary --- client/stylesheets/Home.css | 2 +- imports/ui/home/Home.js | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/client/stylesheets/Home.css b/client/stylesheets/Home.css index fc71132..53ed896 100644 --- a/client/stylesheets/Home.css +++ b/client/stylesheets/Home.css @@ -40,7 +40,7 @@ } .username { - width: 150px; + width: 160px; } .username > div { diff --git a/imports/ui/home/Home.js b/imports/ui/home/Home.js index 2342ecd..e5f205e 100644 --- a/imports/ui/home/Home.js +++ b/imports/ui/home/Home.js @@ -6,10 +6,6 @@ import { JapaneseHands, HongKongHands } from '../../api/GameDatabases'; import './Home.html'; -Template.Home.onCreated( function() { - console.log("created"); -}); - Template.Home.helpers({ current_games() { return JapaneseHands.find().fetch(); @@ -22,14 +18,14 @@ Template.game_summary.helpers({ }, displayRoundWind(rounds) { let lastRound = rounds[rounds.length - 1]; - return GameRecordUtils.displayRoundWind(lastRound.round, Constants.GAME_TYPE.JAPANESE); + return GameRecordUtils.displayRoundWind(lastRound.round + 1, Constants.GAME_TYPE.JAPANESE); }, displayRoundNumber(rounds) { let lastRound = rounds[rounds.length - 1]; - return GameRecordUtils.handNumberToRoundNumber(lastRound.round, Constants.GAME_TYPE.JAPANESE); + return GameRecordUtils.handNumberToRoundNumber(lastRound.round + 1, Constants.GAME_TYPE.JAPANESE); }, getBonus(rounds) { let lastRound = rounds[rounds.length - 1]; return lastRound.bonus; } -}); +}); // TODO: custom popups, localStorage stuff From 551c5418654d199a5df10efc08409dcb53ccc365 Mon Sep 17 00:00:00 2001 From: Redorangegamez Date: Tue, 3 May 2022 14:01:18 -0700 Subject: [PATCH 04/25] Changed game type to include "complete" and "current round", "current bonus". Home page now displays games that are not "complete". Changed RecordJapaneseGame so that you must submit names first. Added Delete Game button. --- .meteor/packages | 14 +- .meteor/release | 2 +- .meteor/versions | 98 +++++++------- imports/ui/home/Home.html | 2 +- imports/ui/home/Home.js | 21 +-- .../ui/record-game/RecordJapaneseGame.html | 2 + imports/ui/record-game/RecordJapaneseGame.js | 128 +++++++++++++++++- 7 files changed, 188 insertions(+), 79 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index 6c2c582..5e22ab7 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -4,18 +4,18 @@ # 'meteor add' and 'meteor remove' will edit this file for you, # but you can also edit it by hand. -meteor-base@1.4.0 # Packages every Meteor app needs to have +meteor-base@1.5.1 # Packages every Meteor app needs to have mobile-experience@1.1.0 # Packages for a great mobile UX -mongo@1.10.1 # The database Meteor supports right now +mongo@1.14.6 # The database Meteor supports right now blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views reactive-var@1.0.11 # Reactive variable for tracker jquery@1.11.10 # Helpful client-side library tracker@1.2.0 # Meteor's client-side reactive programming library -standard-minifier-css@1.7.2 # CSS minifier run for production mode -standard-minifier-js@2.6.0 # JS minifier run for production mode +standard-minifier-css@1.8.1 # CSS minifier run for production mode +standard-minifier-js@2.8.0 # JS minifier run for production mode es5-shim@4.8.0 # ECMAScript 5 compatibility for older browsers. -ecmascript@0.15.0 # Enable ECMAScript2015+ syntax in app code +ecmascript@0.16.2 # Enable ECMAScript2015+ syntax in app code shell-server@0.5.0 # Server-side component of the `meteor shell` command autopublish@1.0.7 # Publish all data to the clients (for prototyping) @@ -25,5 +25,5 @@ session@1.2.0 twbs:bootstrap kadira:flow-router kadira:blaze-layout -dynamic-import@0.6.0 -underscore +dynamic-import@0.7.2 +underscore@1.0.10 diff --git a/.meteor/release b/.meteor/release index bc0e717..8e3f170 100644 --- a/.meteor/release +++ b/.meteor/release @@ -1 +1 @@ -METEOR@2.0 +METEOR@2.7.1 diff --git a/.meteor/versions b/.meteor/versions index 93e73af..d351840 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -1,85 +1,83 @@ -allow-deny@1.1.0 +allow-deny@1.1.1 autopublish@1.0.7 -autoupdate@1.7.0 -babel-compiler@7.6.2 +autoupdate@1.8.0 +babel-compiler@7.9.0 babel-runtime@1.5.0 base64@1.0.12 binary-heap@1.0.11 -blaze@2.3.4 -blaze-html-templates@1.1.2 -blaze-tools@1.0.10 +blaze@2.5.0 +blaze-html-templates@1.2.1 +blaze-tools@1.1.3 boilerplate-generator@1.7.1 caching-compiler@1.2.2 -caching-html-compiler@1.1.2 -callback-hook@1.3.0 +caching-html-compiler@1.2.0 +callback-hook@1.4.0 check@1.3.1 ddp@1.4.0 -ddp-client@2.4.0 +ddp-client@2.5.0 ddp-common@1.4.0 -ddp-server@2.3.2 -deps@1.0.12 +ddp-server@2.5.0 diff-sequence@1.1.1 -dynamic-import@0.6.0 -ecmascript@0.15.0 -ecmascript-runtime@0.7.0 -ecmascript-runtime-client@0.11.0 -ecmascript-runtime-server@0.10.0 -ejson@1.1.1 +dynamic-import@0.7.2 +ecmascript@0.16.2 +ecmascript-runtime@0.8.0 +ecmascript-runtime-client@0.12.1 +ecmascript-runtime-server@0.11.0 +ejson@1.1.2 es5-shim@4.8.0 fetch@0.1.1 geojson-utils@1.0.10 hot-code-push@1.0.4 -html-tools@1.0.11 -htmljs@1.0.11 -id-map@1.1.0 +html-tools@1.1.3 +htmljs@1.1.1 +id-map@1.1.1 insecure@1.0.7 inter-process-messaging@0.1.1 -jquery@1.11.10 +jquery@1.11.11 kadira:blaze-layout@2.3.0 kadira:flow-router@2.12.1 -launch-screen@1.2.0 -livedata@1.0.18 -logging@1.2.0 -meteor@1.9.3 -meteor-base@1.4.0 -minifier-css@1.5.3 -minifier-js@2.6.0 -minimongo@1.6.1 +launch-screen@1.3.0 +logging@1.3.1 +meteor@1.10.0 +meteor-base@1.5.1 +minifier-css@1.6.0 +minifier-js@2.7.4 +minimongo@1.8.0 mobile-experience@1.1.0 mobile-status-bar@1.1.0 -modern-browsers@0.1.5 -modules@0.16.0 -modules-runtime@0.12.0 -mongo@1.10.1 -mongo-decimal@0.1.2 +modern-browsers@0.1.7 +modules@0.18.0 +modules-runtime@0.13.0 +mongo@1.14.6 +mongo-decimal@0.1.3 mongo-dev-server@1.1.0 -mongo-id@1.0.7 -npm-mongo@3.8.1 -observe-sequence@1.0.16 +mongo-id@1.0.8 +npm-mongo@4.3.1 +observe-sequence@1.0.20 ordered-dict@1.1.0 -promise@0.11.2 +promise@0.12.0 random@1.2.0 -react-fast-refresh@0.1.1 +react-fast-refresh@0.2.3 reactive-dict@1.3.0 reactive-var@1.0.11 reload@1.3.1 retry@1.1.0 -routepolicy@1.1.0 +routepolicy@1.1.1 session@1.2.0 shell-server@0.5.0 -socket-stream-client@0.3.1 -spacebars@1.0.15 -spacebars-compiler@1.1.3 -standard-minifier-css@1.7.2 -standard-minifier-js@2.6.0 +socket-stream-client@0.4.0 +spacebars@1.2.0 +spacebars-compiler@1.2.1 +standard-minifier-css@1.8.1 +standard-minifier-js@2.8.0 templates:array@1.0.3 -templating@1.3.2 -templating-compiler@1.3.3 -templating-runtime@1.3.2 -templating-tools@1.1.2 +templating@1.4.1 +templating-compiler@1.4.1 +templating-runtime@1.5.0 +templating-tools@1.2.0 tracker@1.2.0 twbs:bootstrap@3.3.6 ui@1.0.13 underscore@1.0.10 -webapp@1.10.0 +webapp@1.13.1 webapp-hashing@1.1.0 diff --git a/imports/ui/home/Home.html b/imports/ui/home/Home.html index b969b0b..2b03da8 100644 --- a/imports/ui/home/Home.html +++ b/imports/ui/home/Home.html @@ -31,7 +31,7 @@

Home

- {{displayRoundWind all_hands}} {{displayRoundNumber all_hands}} Bonus {{getBonus all_hands}} + {{displayRoundWind current_round}} {{displayRoundNumber current_round}} Bonus {{current_bonus}}
\ No newline at end of file diff --git a/imports/ui/home/Home.js b/imports/ui/home/Home.js index 2342ecd..3b64346 100644 --- a/imports/ui/home/Home.js +++ b/imports/ui/home/Home.js @@ -6,13 +6,9 @@ import { JapaneseHands, HongKongHands } from '../../api/GameDatabases'; import './Home.html'; -Template.Home.onCreated( function() { - console.log("created"); -}); - Template.Home.helpers({ current_games() { - return JapaneseHands.find().fetch(); + return JapaneseHands.find({complete: 0}).fetch(); } }); @@ -20,16 +16,11 @@ Template.game_summary.helpers({ displayScore(score) { return (score / 1000).toFixed(1); }, - displayRoundWind(rounds) { - let lastRound = rounds[rounds.length - 1]; - return GameRecordUtils.displayRoundWind(lastRound.round, Constants.GAME_TYPE.JAPANESE); + displayRoundWind(round) { + return GameRecordUtils.displayRoundWind(round, Constants.GAME_TYPE.JAPANESE); }, - displayRoundNumber(rounds) { - let lastRound = rounds[rounds.length - 1]; - return GameRecordUtils.handNumberToRoundNumber(lastRound.round, Constants.GAME_TYPE.JAPANESE); + displayRoundNumber(round) { + return GameRecordUtils.handNumberToRoundNumber(round, Constants.GAME_TYPE.JAPANESE); }, - getBonus(rounds) { - let lastRound = rounds[rounds.length - 1]; - return lastRound.bonus; - } + }); diff --git a/imports/ui/record-game/RecordJapaneseGame.html b/imports/ui/record-game/RecordJapaneseGame.html index d7594d6..bcfb973 100644 --- a/imports/ui/record-game/RecordJapaneseGame.html +++ b/imports/ui/record-game/RecordJapaneseGame.html @@ -133,6 +133,8 @@

Riichi Japanese Mahjong Game Sheet

+ + diff --git a/imports/ui/record-game/RecordJapaneseGame.js b/imports/ui/record-game/RecordJapaneseGame.js index 0d22617..5b6e756 100644 --- a/imports/ui/record-game/RecordJapaneseGame.js +++ b/imports/ui/record-game/RecordJapaneseGame.js @@ -366,6 +366,29 @@ Template.RecordJapaneseGame.events({ window.alert("please enter all 4 player names!"); } } + + var position; + var east_player = Session.get("current_east"); + var south_player= Session.get("current_south"); + var west_player = Session.get("current_west"); + var north_player= Session.get("current_north"); + + var game = { + timestamp: Date.now(), + east_player: east_player, + south_player: south_player, + west_player: west_player, + north_player: north_player, + east_score: Constants.JPN_START_POINTS, + south_score: Constants.JPN_START_POINTS, + west_score: Constants.JPN_START_POINTS, + north_score: Constants.JPN_START_POINTS, + current_round: 1, + current_bonus: 0, + all_hands: [], + complete: 0, + }; + Session.set("game_id", JapaneseHands.insert(game)); }, //Submission of a hand @@ -394,9 +417,11 @@ Template.RecordJapaneseGame.events({ } else { window.alert("Invalid points/fu entry!"); + return; } } else { window.alert("You need to fill out who won and who dealt in!"); + return; } break; // Push a self draw hand and ensure proper information @@ -411,9 +436,11 @@ Template.RecordJapaneseGame.events({ } else { window.alert("Invalid points/fu entry!"); + return; } } else { window.alert("You need to fill out who self drew!"); + return; } break; // Push a tenpai hand -> cannot input invalid information @@ -437,6 +464,7 @@ Template.RecordJapaneseGame.events({ resetRoundStats(); } else { window.alert("You need to fill out who chomboed!"); + return; } break; @@ -457,9 +485,11 @@ Template.RecordJapaneseGame.events({ } else { window.alert("Invalid points/fu entry!"); + return; } } else { window.alert("You need to fill out who won, who dealt in, and who has pao penalty!"); + return; } break; // No other hands should be possible! @@ -470,8 +500,17 @@ Template.RecordJapaneseGame.events({ } else { window.alert("You need to fill out the player information!"); + return; } + let current_hand = template.hands.get()[template.hands.get().length - 1]; + JapaneseHands.update({_id: Session.get("game_id")}, + {$set:{all_hands: template.hands.get(), + current_round: Session.get("current_round"), + current_bonus: Session.get("current_bonus")}, + $inc: {east_score: current_hand.eastDelta, south_score: current_hand.southDelta, + west_score: current_hand.westDelta, north_score: current_hand.northDelta}}); + // If game ending conditions are met, do not allow more hand submissions and allow game submission if (GameRecordUtils.japaneseGameOver(handType)) { $( event.target ).addClass( "disabled"); @@ -533,9 +572,91 @@ Template.RecordJapaneseGame.events({ if (Template.instance().hands.get().length === 0) { $( ".delete_hand_button" ).addClass( "disabled" ); } + + JapaneseHands.update({_id: Session.get("game_id")}, + {$set:{all_hands: template.hands.get(), + current_round: Session.get("current_round"), + current_bonus: Session.get("current_bonus"), + east_score: Session.get("east_score"), + south_score: Session.get("south_score"), + west_score: Session.get("west_score"), + north_score: Session.get("north_score")}}); + + } + } + }, + //Delete a game from the database + + 'click .delete_game_button'(event, template) { + if ( !$(event.target ).hasClass( "disabled" )) { + var r = confirm("Are you sure you want to delete this game?"); + if (r == true) { + //deletes game from database + JapaneseHands.remove({_id: Session.get("game_id")}); + + //resets page UI + document.getElementById("jpn_buttons").style.display = "none"; + document.getElementById("jpn_rest").style.display = "none"; + document.getElementById("jpn_dynamic").style.display = "none"; + document.getElementById("jpn_players").style.display = "block"; + document.getElementById("submit_button").style.display = "block"; + + + //Deletes all hands to reset to empty game + while (template.hands.pop()) {} + + Session.set("east_score", Constants.JPN_START_POINTS); + Session.set("south_score", Constants.JPN_START_POINTS); + Session.set("west_score", Constants.JPN_START_POINTS); + Session.set("north_score", Constants.JPN_START_POINTS); + + Session.set("current_round", 1); + Session.set("current_bonus", 0); + + Session.set("free_riichi_sticks", 0); + + Session.set("eastPlayerRiichisWon", 0); + Session.set("southPlayerRiichisWon", 0); + Session.set("westPlayerRiichisWon", 0); + Session.set("northPlayerRiichisWon", 0); + + Session.set("eastMistakeTotal", 0); + Session.set("southMistakeTotal", 0); + Session.set("westMistakeTotal", 0); + Session.set("northMistakeTotal", 0); + + Session.set("eastPlayerWins", 0); + Session.set("southPlayerWins", 0); + Session.set("westPlayerWins", 0); + Session.set("northPlayerWins", 0); + + Session.set("eastPlayerPointsWon", 0); + Session.set("southPlayerPointsWon", 0); + Session.set("westPlayerPointsWon", 0); + Session.set("northPlayerPointsWon", 0); + + Session.set("eastPlayerDoraSum", 0); + Session.set("southPlayerDoraSum", 0); + Session.set("westPlayerDoraSum", 0); + Session.set("northPlayerDoraSum", 0); + + Session.set("eastPlayerLosses", 0); + Session.set("southPlayerLosses", 0); + Session.set("westPlayerLosses", 0); + Session.set("northPlayerLosses", 0); + + resetRoundStats(); + + $( ".submit_hand_button" ).removeClass( "disabled" ); + $( ".submit_game_button" ).addClass( "disabled" ); + $( ".delete_hand_button" ).addClass( "disabled" ); } + } }, + + + //Submit a game to the database 'click .submit_game_button'(event, template) { if ( !$(event.target ).hasClass( "disabled" )) { @@ -630,7 +751,6 @@ function save_game_to_database(hands_array) { // Initialise game to be saved var game = { - timestamp: Date.now(), east_player: east_player, south_player: south_player, west_player: west_player, @@ -639,9 +759,10 @@ function save_game_to_database(hands_array) { south_score: (Number(Session.get("south_score"))), west_score: (Number(Session.get("west_score"))), north_score: (Number(Session.get("north_score"))), - all_hands: hands_array, }; + JapaneseHands.update({_id: Session.get("game_id")}, {$set:{complete: 1}}); + // Initialise ELO calculator to update player ELO var jpn_elo_calculator = new EloCalculator(Constants.ELO_CALCULATOR_N, Constants.ELO_CALCULATOR_EXP, @@ -737,9 +858,6 @@ function save_game_to_database(hands_array) { Players.update({ _id: idMappings[positions[1].wind] }, { $inc: { japaneseSecondPlaceSum: 1 }}); Players.update({ _id: idMappings[positions[2].wind] }, { $inc: { japaneseThirdPlaceSum: 1 }}); Players.update({ _id: idMappings[positions[3].wind] }, { $inc: { japaneseFourthPlaceSum: 1 }}); - - //Save game to database - JapaneseHands.insert(game); } }; From df962b99ac7f3278bc691c76bf460aad85add9a5 Mon Sep 17 00:00:00 2001 From: Peiyan Yang Date: Fri, 6 May 2022 13:32:28 -0700 Subject: [PATCH 05/25] store game in database everytime a new hand is submitted --- imports/api/GameDatabases.js | 13 ++++- imports/ui/Index.html | 4 +- imports/ui/Index.js | 10 +++- imports/ui/record-game/RecordJapaneseGame.js | 50 ++++++++++++++++++++ 4 files changed, 73 insertions(+), 4 deletions(-) diff --git a/imports/api/GameDatabases.js b/imports/api/GameDatabases.js index 43799af..6c542f7 100644 --- a/imports/api/GameDatabases.js +++ b/imports/api/GameDatabases.js @@ -1,4 +1,15 @@ import { Mongo } from 'meteor/mongo'; +import Players from './Players'; + export const HongKongHands = new Mongo.Collection('hongKongHands'); -export const JapaneseHands = new Mongo.Collection('japaneseHands'); \ No newline at end of file +export const JapaneseHands = new Mongo.Collection('japaneseHands'); + +Meteor.methods({ + getJapaneseGame: function (gameId) { + return JapaneseHands.findOne({_id: gameId}); + }, + canRetrievePlayer: function (param) { + return Players.find().fetch(); + } +}); \ No newline at end of file diff --git a/imports/ui/Index.html b/imports/ui/Index.html index e22c57d..e28dca6 100644 --- a/imports/ui/Index.html +++ b/imports/ui/Index.html @@ -1,7 +1,7 @@ @@ -218,15 +220,7 @@

Hong Kong Mahjong Game Sheet

{{> loser_s east=get_east south=get_south west=get_west north=get_north}} - - - diff --git a/imports/ui/record-game/RecordJapaneseGame.js b/imports/ui/record-game/RecordJapaneseGame.js index f454a2d..33306d4 100644 --- a/imports/ui/record-game/RecordJapaneseGame.js +++ b/imports/ui/record-game/RecordJapaneseGame.js @@ -1,6 +1,6 @@ //Databases import Players from '../../api/Players'; -import { JapaneseHands } from '../../api/GameDatabases'; +import { JapaneseHands, InProgressJapaneseHands } from '../../api/GameDatabases'; import Constants from '../../api/Constants'; import EloCalculator from '../../api/EloCalculator'; @@ -52,7 +52,10 @@ Template.RecordJapaneseGame.onCreated( function() { let self = this; if (localStorage.getItem("game_id") !== null) { Session.set("game_id", localStorage.getItem("game_id")); - Meteor.call('getJapaneseGame', Session.get("game_id"), function (error, game) { + if (localStorage.getItem("game_type") !== "jp") { + return; + } + Meteor.call('getInProgressJapaneseGame', Session.get("game_id"), function (error, game) { for (let i = 0; i < game.all_hands.length; i++) { let hand = game.all_hands[i]; self.hands.push({ @@ -129,16 +132,13 @@ Template.RecordJapaneseGame.onCreated( function() { Template.RecordJapaneseGame.onRendered( function() { if (localStorage.getItem("game_id") !== null) { -// if (localStorage.getItem("game_type") !== "jp") { -// document.getElementsById("jpn_container").style.display = "none"; -// window.alert("Please submit games in progress before starting a new game!"); -// return; -// } - document.getElementById("jpn_buttons").style.display = "block"; - document.getElementById("jpn_rest").style.display = "block"; - document.getElementById("jpn_dynamic").style.display = "block"; - document.getElementById("jpn_players").style.display = "none"; - document.getElementById("jpn_submit_button").style.display = "none"; + if (localStorage.getItem("game_type") !== "jp") { + document.getElementsById("jpn_container").style.display = "none"; + window.alert("Please submit games in progress before starting a new game!"); + return; + } + document.getElementById("jpn_names").style.display = "block"; + document.getElementById("jpn_game_buttons").style.display = "none"; } }); @@ -203,7 +203,7 @@ Template.RecordJapaneseGame.helpers({ get_player_score_final(direction) { retval = GameRecordUtils.getDirectionScore(direction); - var winScore = Math.max(Number(Session.get("east_score")), + let winScore = Math.max(Number(Session.get("east_score")), Number(Session.get("south_score")), Number(Session.get("west_score")), Number(Session.get("north_score"))); @@ -448,23 +448,20 @@ Template.RecordJapaneseGame.events({ 'click .submit_names_button'(event, template) { if ( !$( event.target ).hasClass( "disabled")) { if (GameRecordUtils.allPlayersSelected()) { - document.getElementById("jpn_buttons").style.display = "block"; - document.getElementById("jpn_rest").style.display = "block"; - document.getElementById("jpn_dynamic").style.display = "block"; - document.getElementById("jpn_players").style.display = "none"; - document.getElementById("jpn_submit_button").style.display = "none"; + document.getElementById("jpn_names").style.display = "block"; + document.getElementById("jpn_game_buttons").style.display = "none"; } else { window.alert("please enter all 4 player names!"); } } - var position; - var east_player = Session.get("current_east"); - var south_player= Session.get("current_south"); - var west_player = Session.get("current_west"); - var north_player= Session.get("current_north"); + let position; + let east_player = Session.get("current_east"); + let south_player= Session.get("current_south"); + let west_player = Session.get("current_west"); + let north_player= Session.get("current_north"); - var game = { + let game = { timestamp: Date.now(), east_player: east_player, south_player: south_player, @@ -479,7 +476,6 @@ Template.RecordJapaneseGame.events({ free_riichi_sticks: 0, riichi_sum_history: [], all_hands: [], - complete: 0, eastPlayerWins: 0, southPlayerWins: 0, westPlayerWins: 0, @@ -509,7 +505,7 @@ Template.RecordJapaneseGame.events({ westPlayerDoraSum: 0, northPlayerDoraSum: 0, }; - Session.set("game_id", JapaneseHands.insert(game)); + Session.set("game_id", InProgressJapaneseHands.insert(game)); localStorage.setItem("game_id", Session.get("game_id")); localStorage.setItem("game_type", "jp"); }, @@ -524,7 +520,6 @@ Template.RecordJapaneseGame.events({ if (GameRecordUtils.allPlayersSelected()) { // Save what the free riichi stick number is in case we delete this hand template.riichi_sum_history.push(Session.get("free_riichi_sticks")); - console.log(Session.get("free_riichi_sticks")); switch(handType) { // Push a deal in hand and ensure proper information @@ -628,8 +623,7 @@ Template.RecordJapaneseGame.events({ } let current_hand = template.hands.get()[template.hands.get().length - 1]; - console.log(template.riichi_sum_history); - JapaneseHands.update({_id: Session.get("game_id")}, + InProgressJapaneseHands.update({_id: Session.get("game_id")}, {$set:{all_hands: template.hands.get(), current_round: Session.get("current_round"), current_bonus: Session.get("current_bonus"), @@ -677,11 +671,11 @@ Template.RecordJapaneseGame.events({ //Remove the last submitted hand 'click .delete_hand_button'(event, template) { if ( !$(event.target ).hasClass( "disabled" )) { - var r = confirm("Are you sure you want to delete the last hand?"); + let r = confirm("Are you sure you want to delete the last hand?"); // Reset game to last hand state if (r == true) { // Deletes last hand - var del_hand = Template.instance().hands.pop(); + let del_hand = Template.instance().hands.pop(); Session.set("east_score", Number(Session.get("east_score")) - Number(del_hand.eastDelta)); Session.set("south_score", Number(Session.get("south_score")) - Number(del_hand.southDelta)); @@ -693,7 +687,7 @@ Template.RecordJapaneseGame.events({ //Set free riichi sticks to last round's value Session.set("free_riichi_sticks", template.riichi_sum_history.pop()) - var riichiHistory = template.riichi_round_history.pop(); + let riichiHistory = template.riichi_round_history.pop(); if (riichiHistory.east == true) Session.set("east_riichi_sum", Number(Session.get("east_riichi_sum")) - 1); if (riichiHistory.south == true) @@ -728,7 +722,7 @@ Template.RecordJapaneseGame.events({ $( ".delete_hand_button" ).addClass( "disabled" ); } - JapaneseHands.update({_id: Session.get("game_id")}, + InProgressJapaneseHands.update({_id: Session.get("game_id")}, {$set:{all_hands: template.hands.get(), current_round: Session.get("current_round"), current_bonus: Session.get("current_bonus"), @@ -774,21 +768,18 @@ Template.RecordJapaneseGame.events({ 'click .delete_game_button'(event, template) { if ( !$(event.target ).hasClass( "disabled" )) { - var r = confirm("Are you sure you want to delete this game?"); + let r = confirm("Are you sure you want to delete this game?"); if (r == true) { let r2 = confirm("Are you sure sure you want to delete this game?"); if (r2 == true) { localStorage.clear(); - //deletes game from database - JapaneseHands.remove({_id: Session.get("game_id")}); + //deletes game from in progress database + InProgressJapaneseHands.remove({_id: Session.get("game_id")}); //resets page UI - document.getElementById("jpn_buttons").style.display = "none"; - document.getElementById("jpn_rest").style.display = "none"; - document.getElementById("jpn_dynamic").style.display = "none"; - document.getElementById("jpn_players").style.display = "block"; - document.getElementById("jpn_submit_button").style.display = "block"; + document.getElementById("jpn_names").style.display = "block"; + document.getElementById("jpn_game_buttons").style.display = "none"; document.querySelector('select[name="east_player"]').value=""; document.querySelector('select[name="south_player"]').value=""; @@ -858,7 +849,7 @@ Template.RecordJapaneseGame.events({ let r = confirm("Are you sure you want to submit this game?"); if (r == true) { localStorage.clear(); - var winScore = Math.max(Number(Session.get("east_score")), + let winScore = Math.max(Number(Session.get("east_score")), Number(Session.get("south_score")), Number(Session.get("west_score")), Number(Session.get("north_score"))); @@ -875,11 +866,8 @@ Template.RecordJapaneseGame.events({ save_game_to_database(template.hands.get()); //resets page UI - document.getElementById("jpn_buttons").style.display = "none"; - document.getElementById("jpn_rest").style.display = "none"; - document.getElementById("jpn_dynamic").style.display = "none"; - document.getElementById("jpn_players").style.display = "block"; - document.getElementById("jpn_submit_button").style.display = "block"; + document.getElementById("jpn_names").style.display = "block"; + document.getElementById("jpn_game_buttons").style.display = "none"; document.querySelector('select[name="east_player"]').value=""; document.querySelector('select[name="south_player"]').value=""; @@ -939,7 +927,7 @@ Template.RecordJapaneseGame.events({ }, //Toggle between different round types 'click .nav-pills li'( event, template ) { - var hand_type = $( event.target ).closest( "li" ); + let hand_type = $( event.target ).closest( "li" ); hand_type.addClass( "active" ); $( ".nav-pills li" ).not( hand_type ).removeClass( "active" ); @@ -950,15 +938,15 @@ Template.RecordJapaneseGame.events({ // Save the currently recorded game to database and update player statistics function save_game_to_database(hands_array) { - var position; + let position; - var east_player = Session.get("current_east"); - var south_player= Session.get("current_south"); - var west_player = Session.get("current_west"); - var north_player= Session.get("current_north"); + let east_player = Session.get("current_east"); + let south_player= Session.get("current_south"); + let west_player = Session.get("current_west"); + let north_player= Session.get("current_north"); // Initialise game to be saved - var game = { + let game = { east_player: east_player, south_player: south_player, west_player: west_player, @@ -967,25 +955,24 @@ function save_game_to_database(hands_array) { south_score: (Number(Session.get("south_score"))), west_score: (Number(Session.get("west_score"))), north_score: (Number(Session.get("north_score"))), + all_hands: hands_array, }; - JapaneseHands.update({_id: Session.get("game_id")}, {$set:{complete: 1}}); - // Initialise ELO calculator to update player ELO - var jpn_elo_calculator = new EloCalculator(Constants.ELO_CALCULATOR_N, + let jpn_elo_calculator = new EloCalculator(Constants.ELO_CALCULATOR_N, Constants.ELO_CALCULATOR_EXP, Constants.JPN_SCORE_ADJUSTMENT, game, Constants.GAME_TYPE.JAPANESE); - var east_elo_delta = jpn_elo_calculator.eloChange(east_player); - var south_elo_delta = jpn_elo_calculator.eloChange(south_player); - var west_elo_delta = jpn_elo_calculator.eloChange(west_player); - var north_elo_delta = jpn_elo_calculator.eloChange(north_player); + let east_elo_delta = jpn_elo_calculator.eloChange(east_player); + let south_elo_delta = jpn_elo_calculator.eloChange(south_player); + let west_elo_delta = jpn_elo_calculator.eloChange(west_player); + let north_elo_delta = jpn_elo_calculator.eloChange(north_player); - var east_id = Players.findOne({japaneseLeagueName: east_player}, {})._id; - var south_id = Players.findOne({japaneseLeagueName: south_player}, {})._id; - var west_id = Players.findOne({japaneseLeagueName: west_player}, {})._id; - var north_id = Players.findOne({japaneseLeagueName: north_player}, {})._id; + let east_id = Players.findOne({japaneseLeagueName: east_player}, {})._id; + let south_id = Players.findOne({japaneseLeagueName: south_player}, {})._id; + let west_id = Players.findOne({japaneseLeagueName: west_player}, {})._id; + let north_id = Players.findOne({japaneseLeagueName: north_player}, {})._id; if (east_elo_delta != NaN && south_elo_delta != NaN && west_elo_delta != NaN && north_elo_delta != NaN) { // Save ELO @@ -1067,16 +1054,22 @@ function save_game_to_database(hands_array) { Players.update({ _id: idMappings[positions[2].wind] }, { $inc: { japaneseThirdPlaceSum: 1 }}); Players.update({ _id: idMappings[positions[3].wind] }, { $inc: { japaneseFourthPlaceSum: 1 }}); } + + //Save game to database + JapaneseHands.insert(game); + + //deletes game from in progress database + InProgressJapaneseHands.remove({_id: Session.get("game_id")}); }; function push_dealin_hand(template) { - var points = Number(Session.get("current_points")); - var fu = Number(Session.get("current_fu")); - var dora = Number(Session.get("current_dora")); + let points = Number(Session.get("current_points")); + let fu = Number(Session.get("current_fu")); + let dora = Number(Session.get("current_dora")); let dealerWind = GameRecordUtils.roundToDealerDirection(Number(Session.get("current_round"))); - var winnerWind = GameRecordUtils.playerToDirection(Session.get("round_winner")); - var loserWind = GameRecordUtils.playerToDirection(Session.get("round_loser")); - var riichiSum = Session.get("free_riichi_sticks"); + let winnerWind = GameRecordUtils.playerToDirection(Session.get("round_winner")); + let loserWind = GameRecordUtils.playerToDirection(Session.get("round_loser")); + let riichiSum = Session.get("free_riichi_sticks"); let seatDeltas = {}; Constants.WINDS.forEach(w => seatDeltas[w] = 0); @@ -1175,12 +1168,12 @@ function push_dealin_hand(template) { }; function push_selfdraw_hand(template) { - var points = Number(Session.get("current_points")); - var fu = Number(Session.get("current_fu")); - var dora = Number(Session.get("current_dora")); + let points = Number(Session.get("current_points")); + let fu = Number(Session.get("current_fu")); + let dora = Number(Session.get("current_dora")); let dealerWind = GameRecordUtils.roundToDealerDirection(Number(Session.get("current_round"))); - var winnerWind = GameRecordUtils.playerToDirection(Session.get("round_winner")); - var riichiSum = Session.get("free_riichi_sticks"); + let winnerWind = GameRecordUtils.playerToDirection(Session.get("round_winner")); + let riichiSum = Session.get("free_riichi_sticks"); let seatDeltas = {}; Constants.WINDS.forEach(w => seatDeltas[w] = 0); @@ -1269,8 +1262,8 @@ function push_selfdraw_hand(template) { }; function push_nowin_hand(template) { - var eastDelta = 0, southDelta = 0, westDelta = 0, northDelta = 0; - var tenpaiSum = 0, tenpaiWin, tenpaiLose, riichiSum = 0; + let eastDelta = 0, southDelta = 0, westDelta = 0, northDelta = 0; + let tenpaiSum = 0, tenpaiWin, tenpaiLose, riichiSum = 0; if (Session.get("east_tenpai") == true) tenpaiSum++; if (Session.get("south_tenpai") == true) tenpaiSum++; @@ -1308,7 +1301,6 @@ function push_nowin_hand(template) { } Session.set("free_riichi_sticks", Number(Session.get("free_riichi_sticks")) + riichiSum); - console.log(Session.get("free_riichi_sticks")); pushHand(template, Constants.NO_WIN, eastDelta, southDelta, westDelta, northDelta); @@ -1326,8 +1318,8 @@ function push_nowin_hand(template) { }; function push_restart_hand(template) { - var eastDelta = 0, southDelta = 0, westDelta = 0, northDelta = 0; - var riichiSum = 0; + let eastDelta = 0, southDelta = 0, westDelta = 0, northDelta = 0; + let riichiSum = 0; if (Session.get("east_riichi") == true) { eastDelta -= Constants.JPN_RIICHI_POINTS; @@ -1390,14 +1382,14 @@ function push_mistake_hand(template) { }; function push_split_pao_hand(template) { - var points = Number(Session.get("current_points")); - var fu = Number(Session.get("current_fu")); - var dora = Number(Session.get("current_dora")); + let points = Number(Session.get("current_points")); + let fu = Number(Session.get("current_fu")); + let dora = Number(Session.get("current_dora")); let dealerWind = GameRecordUtils.roundToDealerDirection(Number(Session.get("current_round"))); - var winnerWind = GameRecordUtils.playerToDirection(Session.get("round_winner")); - var loserWind = GameRecordUtils.playerToDirection(Session.get("round_loser")); - var paoWind = GameRecordUtils.playerToDirection(Session.get("round_pao_player")); - var riichiSum = Session.get("free_riichi_sticks"); + let winnerWind = GameRecordUtils.playerToDirection(Session.get("round_winner")); + let loserWind = GameRecordUtils.playerToDirection(Session.get("round_loser")); + let paoWind = GameRecordUtils.playerToDirection(Session.get("round_pao_player")); + let riichiSum = Session.get("free_riichi_sticks"); let seatDeltas = {}; Constants.WINDS.forEach(w => seatDeltas[w] = 0); @@ -1460,7 +1452,7 @@ function push_split_pao_hand(template) { Session.set("north_riichi_sum", Number(Session.get("north_riichi_sum")) + 1); } - var value = HandScoreCalculator.jpn.dealinDelta(points, + let value = HandScoreCalculator.jpn.dealinDelta(points, fu, Number(Session.get("current_bonus")), dealerWind, From d2018eb37dffcadbfda5c915f5cf888620612e17 Mon Sep 17 00:00:00 2001 From: Redorangegamez Date: Sun, 15 May 2022 02:51:10 -0700 Subject: [PATCH 15/25] record game ui bug fix --- .meteor/packages | 2 +- .meteor/release | 2 +- .meteor/versions | 6 ++--- imports/ui/Index.js | 6 ++++- .../ui/record-game/RecordHongKongGame.html | 8 +++--- imports/ui/record-game/RecordHongKongGame.js | 22 ++++++++++------ .../ui/record-game/RecordJapaneseGame.html | 8 +++--- imports/ui/record-game/RecordJapaneseGame.js | 25 +++++++++++++------ 8 files changed, 50 insertions(+), 29 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index 5e22ab7..838d664 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -6,7 +6,7 @@ meteor-base@1.5.1 # Packages every Meteor app needs to have mobile-experience@1.1.0 # Packages for a great mobile UX -mongo@1.14.6 # The database Meteor supports right now +mongo@1.15.0 # The database Meteor supports right now blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views reactive-var@1.0.11 # Reactive variable for tracker jquery@1.11.10 # Helpful client-side library diff --git a/.meteor/release b/.meteor/release index 8e3f170..2246232 100644 --- a/.meteor/release +++ b/.meteor/release @@ -1 +1 @@ -METEOR@2.7.1 +METEOR@2.7.2 diff --git a/.meteor/versions b/.meteor/versions index d351840..8bd2764 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -45,10 +45,10 @@ minifier-js@2.7.4 minimongo@1.8.0 mobile-experience@1.1.0 mobile-status-bar@1.1.0 -modern-browsers@0.1.7 +modern-browsers@0.1.8 modules@0.18.0 modules-runtime@0.13.0 -mongo@1.14.6 +mongo@1.15.0 mongo-decimal@0.1.3 mongo-dev-server@1.1.0 mongo-id@1.0.8 @@ -65,7 +65,7 @@ retry@1.1.0 routepolicy@1.1.1 session@1.2.0 shell-server@0.5.0 -socket-stream-client@0.4.0 +socket-stream-client@0.5.0 spacebars@1.2.0 spacebars-compiler@1.2.1 standard-minifier-css@1.8.1 diff --git a/imports/ui/Index.js b/imports/ui/Index.js index d2483b0..ad84c18 100644 --- a/imports/ui/Index.js +++ b/imports/ui/Index.js @@ -8,7 +8,11 @@ import './ranking/Ranking'; Template.Index.onCreated( function() { if (localStorage.getItem("game_id") !== null) { - this.currentTab = new ReactiveVar( "RecordJapaneseGame" ); + if (localStorage.getItem("game_type") === "jp") { + this.currentTab = new ReactiveVar( "RecordJapaneseGame" ); + } else if (localStorage.getItem("game_type") === "hk") { + this.currentTab = new ReactiveVar( "RecordHongKongGame" ); + } } else { this.currentTab = new ReactiveVar( "Home" ); } diff --git a/imports/ui/record-game/RecordHongKongGame.html b/imports/ui/record-game/RecordHongKongGame.html index e5291fd..29592f6 100644 --- a/imports/ui/record-game/RecordHongKongGame.html +++ b/imports/ui/record-game/RecordHongKongGame.html @@ -45,8 +45,8 @@

Hong Kong Mahjong Game Sheet

-
-