浏览代码

refactor: maintains game settings if user returns to custom menu (resets only after returning to main menu)

lairaalmas 1 年之前
父节点
当前提交
4e8d8187bb
共有 4 个文件被更改,包括 20 次插入9 次删除
  1. 1 1
      js/globals/globals_control.js
  2. 2 2
      js/globals/globals_debug.js
  3. 10 6
      js/menus/menu_custom.js
  4. 7 0
      js/menus/menu_main.js

+ 1 - 1
js/globals/globals_control.js

@@ -17,7 +17,7 @@
  * ...plus...minus.......minus........plus.minus.mixed. = gameOperation (game math operation)
  * .......\./..............|................\.|./.......
  * ........|...............|..................|.........
- * ......1,2,3.........1,2,3,4,5..........1,2,3,4,5..... = gameDifficulty (difficulty level)
+ * ......1,2,3.........1,2,3,4,5............1,2,3,...... = gameDifficulty (difficulty level)
  * .....................................................
  *
  * About levels in map:

+ 2 - 2
js/globals/globals_debug.js

@@ -1,9 +1,9 @@
-const isDebugMode = false;
+const isDebugMode = true;
 
 const debugState = {
   lang: { skip: true, lang: 'pt_BR' },
   name: { skip: true, name: 'Username' },
-  menu: { skip: true, id: 0, audioStatus: false },
+  menu: { skip: false, id: 1, audioStatus: false },
   customMenu: {
     skip: false,
     getData: () => {

+ 10 - 6
js/menus/menu_custom.js

@@ -294,6 +294,8 @@ const customMenuState = {
     x = getFrameInfo().x + offsetW;
     y = getFrameInfo().y + offsetH / 2;
 
+    if (!gameMode) gameMode = gameList[gameId].gameMode[0];
+
     for (
       let i = 0;
       i < curGame.assets.customMenu.gameModeBtn.length;
@@ -311,8 +313,8 @@ const customMenuState = {
 
       icon.gameMode = curGame.gameMode[i];
       icon.iconType = 'gameMode';
-      if (i == 0) {
-        gameMode = icon.gameMode;
+
+      if (gameList[gameId].gameMode[i] == gameMode) {
         icon.curFrame = 1;
       }
 
@@ -329,6 +331,8 @@ const customMenuState = {
       curGame.gameOperation.length - 1
     );
 
+    if (!gameOperation) gameOperation = gameList[gameId].gameOperation[0];
+
     let icon;
 
     // Placing math operation icons
@@ -346,8 +350,7 @@ const customMenuState = {
       icon.gameOperation = curGame.gameOperation[i];
       icon.iconType = 'gameOperation';
 
-      if (i == 0) {
-        gameOperation = icon.gameOperation;
+      if (gameList[gameId].gameOperation[i] == gameOperation) {
         icon.curFrame = 1;
       }
 
@@ -365,6 +368,8 @@ const customMenuState = {
 
     y = getFrameInfo().y + offsetH / 3;
 
+    if (!gameDifficulty) gameDifficulty = 1;
+
     if (gameName === 'squareTwo') x -= 70;
 
     for (let i = 0; i < curGame.gameDifficulty; i++) {
@@ -376,8 +381,7 @@ const customMenuState = {
       icon.difficulty = i + 1;
       icon.iconType = 'difficulty';
 
-      if (i == 0) {
-        gameDifficulty = icon.difficulty;
+      if (i == gameDifficulty - 1) {
         icon.curFrame = 0;
       }
       self.menuIcons.push(icon);

+ 7 - 0
js/menus/menu_main.js

@@ -22,6 +22,13 @@ const menuState = {
       if (moodle && iLMparameters.iLM_PARAM_SendAnswer == 'true')
         playerName = game.lang.professor;
 
+      // reset game values
+      gameId = null;
+      gameMode = null;
+      gameOperation = null;
+      gameDifficulty = null;
+      showFractions = true;
+
       renderBackground();
 
       // Overtitle: Welcome, <player name>!