Browse Source

Merge branch 'fix/moodle-bugs' of LInE/Ifractions-web into master

laira 6 months ago
parent
commit
2db4cde70e

+ 2 - 1
assets/lang/en_US

@@ -7,7 +7,7 @@ circleOne_intro_b=How many arcs must we select so that\nthe boy can reach the ba
 squareOne_intro_a=What size hole must be opened in the ground so that\nall the blocks that the tractor will take can fit?
 squareOne_intro_b=How many blocks must the tractor push to\nfill the hole in the ground?
 squareTwo_intro=Select portions in the two figures so that\none is equivalent to the other
-congratulations=congratulations!
+congratulations=Congratulations!
 continue=Continue
 custom_game=CUSTOMIZE THE CURRENT GAME
 difficulties=Difficulties
@@ -61,5 +61,6 @@ errors=Errors
 time=Time
 results=RESULTS
 student=Student
+submit=Submit your assignment below
 professor=Professor
 scale=Scale

+ 1 - 0
assets/lang/es_ES

@@ -61,5 +61,6 @@ errors=Errores
 time=Tiempo
 results=RESULTADOS
 student=Estudiante
+submit=Envía tu tarea a continuación
 professor=Professor
 scale=Escala

+ 3 - 2
assets/lang/fr_FR

@@ -7,14 +7,14 @@ circleOne_intro_b=Combien de cerceaux devons-nous choisir pour que\nle garçon p
 squareOne_intro_a=Quelle taille de trou faut-il ouvrir dans le sol pour que tous les blocs\nque prendra le tracteur puissent y rentrer ?
 squareOne_intro_b=Combien de blocs le bulldozer doit-il pousser\npour combler le trou dans le sol ?
 squareTwo_intro=Sélectionnez des parties dans les deux figures afin\nque l'une soit équivalente à l'autre
-congratulations=Toutes nos félicitations!
+congratulations=Toutes nos félicitations !
 continue=Continuez
 custom_game=PERSONNALISER LE JEU ACTUEL
 difficulties=Difficultés
 difficulty=Difficulté
 empty_name=Vous avez oublié de taper votre nom
 equals=Égalité
-error_must_select_game=vous devez sélectionner au moins un jeu!
+error_must_select_game=vous devez sélectionner au moins un jeu !
 game=Jeu
 game_mode=Mode de Jeu
 game_modes=Modes de Jeu
@@ -61,5 +61,6 @@ errors=Erreurs
 time=Temps
 results=RÉSULTATS
 student=Étudiant
+submit=Soumettez votre mission ci-dessous
 professor=Professeur
 scale=Balance

+ 1 - 0
assets/lang/it_IT

@@ -61,5 +61,6 @@ errors=Errori
 time=Tempo
 results=RISULTATI
 student=Alunno
+submit=Invia il tuo compito qui sotto
 professor=Professore
 scale=Bilancia

+ 1 - 0
assets/lang/pt_BR

@@ -61,5 +61,6 @@ errors=Erros
 time=Tempo
 results=RESULTADOS
 student=Aluno
+submit=Envie sua tarefa abaixo
 professor=Professor
 scale=Balança

+ 3 - 1
js/games/squareTwo.js

@@ -447,6 +447,8 @@ const squareTwo = {
       );
     },
     startDelayHandler: () => {
+      game.timer.stop();
+
       self.control.animationDelay++;
 
       if (self.control.animationDelay === 50) {
@@ -736,7 +738,7 @@ const squareTwo = {
         gameShape +
         '&line_mode=' +
         gameMode +
-        '&line_oper=Equal' +
+        '&line_oper=equal' +
         '&line_leve=' +
         gameDifficulty +
         '&line_posi=' +

+ 5 - 1
js/globals/globals_control.js

@@ -39,7 +39,11 @@
  */
 const moodle = false;
 
-let moodleVar;
+let moodleVar = {
+  hits: [0, 0, 0, 0],
+  errors: [0, 0, 0, 0],
+  time: [0, 0, 0, 0],
+};
 
 /**
  * Index of the current game in gameList array

+ 5 - 3
js/globals/globals_functions.js

@@ -66,8 +66,10 @@ const navigation = {
   },
 
   disableIcon: (icon) => {
-    icon.alpha = 0;
-    icon.isDisabled = true;
+    if (icon) {
+      icon.alpha = 0;
+      icon.isDisabled = true;
+    }
   },
 
   onInputDown: (x, y) => {
@@ -152,7 +154,7 @@ const navigation = {
 const sendToDatabase = function (extraData) {
   // FOR MOODLE
   if (moodle) {
-    if (self.result) moodleVar.hits[curMapPosition - 1]++;
+    if (self.control.isCorrect) moodleVar.hits[curMapPosition - 1]++;
     else moodleVar.errors[curMapPosition - 1]++;
 
     moodleVar.time[curMapPosition - 1] += game.timer.elapsed;

+ 16 - 9
js/menus/menu_main.js

@@ -16,18 +16,25 @@ const menuState = {
       // Student role
 
       playerName = game.lang.student; // TODO pegar o nome do aluno no bd do moodle
-      getiLMContent();
+      try {
+        getiLMContent();
+      } catch (error) {
+        console.error(
+          'Game error: Could not load the iLM Content on Moodle. ' + error
+        );
+      }
     } else {
       // FOR MOODLE
-      if (moodle && iLMparameters.iLM_PARAM_SendAnswer == 'true')
+      if (moodle && iLMparameters.iLM_PARAM_SendAnswer == 'true') {
         playerName = game.lang.professor;
-
-      // reset game values
-      gameId = null;
-      gameMode = null;
-      gameOperation = null;
-      gameDifficulty = null;
-      showFractions = true;
+      } else {
+        // reset game values
+        gameId = null;
+        gameMode = null;
+        gameOperation = null;
+        gameDifficulty = null;
+        showFractions = true;
+      }
 
       renderBackground();
 

+ 46 - 26
js/moodle/integrationFunctions.js

@@ -37,8 +37,8 @@ function getParameterByName(name) {
  */
 function getAnswer() {
   let str = '';
+  // Student role: sending results
   if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
-    // Student - sending results
     str +=
       'gameName:' +
       gameName +
@@ -50,6 +50,8 @@ function getAnswer() {
       gameOperation +
       '\ngameDifficulty:' +
       gameDifficulty +
+      '\ngameId:' +
+      gameId +
       '\nshowFractions:' +
       showFractions +
       '\nresults:';
@@ -66,7 +68,7 @@ function getAnswer() {
         '}';
     }
   } else {
-    // Professor - creating new assignment
+    // Professor role: creating new assignment
     if (!gameName) {
       alert(game.lang.error_must_select_game);
       return x;
@@ -85,6 +87,8 @@ function getAnswer() {
       gameOperation +
       '\ngameDifficulty:' +
       gameDifficulty +
+      '\ngameId:' +
+      gameId +
       '\nshowFractions:' +
       showFractions;
   }
@@ -101,43 +105,48 @@ function getAnswer() {
  * @returns {number} student's grade for the current assignment : real number between 0.0 and 1.0
  */
 function getEvaluation() {
+  // Student role
   if (iLMparameters.iLM_PARAM_SendAnswer == 'false') {
-    // Student
     let i;
     for (i = 0; i < moodleVar.hits.length && moodleVar.hits[i] == 1; i++);
     const grade = i / 4;
-    parent.getEvaluationCallback(grade); // Sends grade to moodle db
     return grade;
   }
 }
 
+// function getEvaluationCallbackHandler() {
+//   const grade = getEvaluation();
+//   parent.getEvaluationCallback(grade); // Sends grade to moodle db
+// }
+
 /** [Functions used by iAssign]
  *
  * Holds the parameters passed by the iAssign to the iLM via URL.
  */
 const iLMparameters = {
   /**
-   * This parameter gets the role in which the iLM is being used: <br>
-   * - if true, the user is creating a new iLM (as professor) <br>
-   * - if false, the user is solving the iLM (as student), value=false
+   * This parameter must receive from iAssign the URL of the iLM content. <br>
+   * Example: http://myschool.edu/moodle/mod/iassign/ilm_security.php?id=3&token=b3660dd4de0b0e9bb01fea6cc8f02ccd&view=1<br>
+   * Obs.: the first url parameter, 'token', can be used only once, after sending its content to the iLM, iAssign will erase the file (avoiding "peeping")
    */
-  iLM_PARAM_SendAnswer: getParameterByName('iLM_PARAM_SendAnswer'), // Checks if you're student (false) or professor (true)
+  iLM_PARAM_Assignment: getParameterByName('iLM_PARAM_Assignment'),
+
   /**
-   * This parameter is used when the user is opening an iLM to solve it. <br>
-   * It holds a URL with the path to the game file (assignment/iLM) created by the professor. <br>
-   * Example: http://myschool.edu/moodle/mod/iassign/ilm_security.php?id=3&token=b3660dd4de0b0e9bb01fea6cc8f02ccd&view=1
-   *
-   * The first parameter, 'token', can be used only once.
-   * Once the iLM gets the game file, the token is destroied (for security).
+   * if true => iLM MUST NOT send any answer to the server
    */
-  iLM_PARAM_Assignment: getParameterByName('iLM_PARAM_Assignment'),
+  iLM_PARAM_SendAnswer: getParameterByName('iLM_PARAM_SendAnswer'), // Checks if you're student (false) or professor (true)
+
   /**
-   * Gets current moodle language.
+   * if true => iLM WILL be used by TEACHER to create a new exercise
    */
-  lang: getParameterByName('lang'),
+  iLM_PARAM_Authoring: getParameterByName('iLM_PARAM_Authoring'),
   iLM_PARAM_ServerToGetAnswerURL: getParameterByName(
     'iLM_PARAM_ServerToGetAnswerURL'
   ),
+  /**
+   * Gets current moodle language.
+   */
+  lang: getParameterByName('lang'),
 };
 
 /**
@@ -195,7 +204,7 @@ const breakString = function (text) {
         results = line[1].replace(/^\s+|\s+$/g, '');
       }
     } catch (Error) {
-      console.error('Game error: sintax error.');
+      console.error('Game error: sintax error. ' + Error);
     }
   });
 
@@ -216,7 +225,7 @@ const breakString = function (text) {
             results['l' + i][key] = parseInt(value);
           }
         } catch (Error) {
-          console.error('Game error: sintax error.');
+          console.error('Game error: sintax error. ' + Error);
         }
       });
       i++;
@@ -231,12 +240,29 @@ const breakString = function (text) {
  * - calls state 'customMenu' if the assignment WAS NOT previously completed. <br>
  * - calls state 'studentReport' otherwise.
  *
- * @param {object} info game information
+ * @param {object} infoGame game information
  * @param {undefined|object} infoResults student answer (if there is any)
  */
 const updateGlobalVariables = function (infoGame, infoResults) {
   // Update game variables to content received from game file
   gameName = infoGame['gameName'];
+  if (infoGame['gameId']) {
+    gameId = infoGame['gameId'];
+  } else {
+    switch (gameName) {
+      case 'squareOne':
+        gameId = 0;
+        break;
+      case 'circleOne':
+        gameId = 1;
+        break;
+      case 'squareTwo':
+        gameId = 2;
+        break;
+      default:
+        gameId = 0;
+    }
+  }
   gameShape = infoGame['gameShape'];
   gameMode = infoGame['gameMode'];
   gameOperation = infoGame['gameOperation'];
@@ -260,9 +286,3 @@ const updateGlobalVariables = function (infoGame, infoResults) {
     game.state.start('customMenu');
   }
 };
-
-moodleVar = {
-  hits: [0, 0, 0, 0],
-  errors: [0, 0, 0, 0],
-  time: [0, 0, 0, 0],
-};

+ 20 - 22
js/screens/end.js

@@ -115,15 +115,9 @@ const endState = {
       }
     }
 
-    if (self.control.endLevel) {
-      // FOR MOODLE
-      if (!moodle) {
-        completedLevels = 0;
-        game.state.start('menu');
-      } else {
-        // FOR MOODLE
-        parent.location.reload(true);
-      }
+    if (!moodle && self.control.endLevel) {
+      completedLevels = 0;
+      game.state.start('menu');
     }
 
     game.render.all();
@@ -194,23 +188,28 @@ const endState = {
     },
     renderEndUI: () => {
       const btnY = context.canvas.height / 2;
+      let btnTextFont = textStyles.btn;
 
       // Continue Button
-      self.ui.continue.button = game.add.geom.rect(
-        context.canvas.width / 2,
-        btnY,
-        600,
-        100,
-        colors.green
-      );
-      self.ui.continue.button.anchor(0.5, 0.5);
+      if (!moodle) {
+        self.ui.continue.button = game.add.geom.rect(
+          context.canvas.width / 2,
+          btnY,
+          600,
+          100,
+          colors.green
+        );
+        self.ui.continue.button.anchor(0.5, 0.5);
+      } else {
+        btnTextFont = { ...btnTextFont, fill: colors.blue };
+      }
 
       // Continue button text
       self.ui.continue.text = game.add.text(
         context.canvas.width / 2,
         btnY + 16,
-        game.lang.back_to_menu,
-        textStyles.btn
+        moodle ? game.lang.submit : game.lang.back_to_menu,
+        btnTextFont
       );
 
       // Title
@@ -235,7 +234,7 @@ const endState = {
       const x = game.math.getMouse(mouseEvent).x;
       const y = game.math.getMouse(mouseEvent).y;
 
-      if (self.control.waitUserAction) {
+      if (!moodle && self.control.waitUserAction) {
         if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
           if (audioStatus) game.audio.popSound.play();
           self.control.endLevel = true;
@@ -251,9 +250,8 @@ const endState = {
     onInputOver: function (mouseEvent) {
       const x = game.math.getMouse(mouseEvent).x;
       const y = game.math.getMouse(mouseEvent).y;
-      let overIcon;
 
-      if (self.control.waitUserAction) {
+      if (!moodle && self.control.waitUserAction) {
         if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
           // If pointer is over icon
           document.body.style.cursor = 'pointer';

+ 6 - 6
php/save.php

@@ -5,10 +5,10 @@
 // Adjust the names here and those in your MySQL server.
 //
 // The following files make reference to the table fields (must use the same names "line_id, line_name, ...")
-// @see js/globals.js
-// @see js/circleOne.js
-// @see js/squareOne.js
-// @see js/squareTwo.js
+// @see js/globals/globals_functions.js
+// @see js/games/circleOne.js
+// @see js/games/squareOne.js
+// @see js/games/squareTwo.js
 
 // Change these values according to your database settings
 $servername = "localhost";  // INSERT MySQL server (e.g "line.ime.usp.br")
@@ -49,8 +49,8 @@ if ($conn->connect_error) {
 
 $ip = clientIP();
 
-// /js/globals.js: data = line_ip=120.0.0.1&line_name=name&line_lang=pt_BR
-// /js/squareOne.js: data += &line_game=Square&line_mode=a&line_oper=Plus&line_leve=1&line_posi=1&line_resu=true&line_time=3&line_deta=numBlocks:3, valBlocks: 1,1,1, blockIndex: 2, floorIndex: 2;url=php/save.php
+// /js/globals/globals_functions.js: data = line_ip=120.0.0.1&line_name=name&line_lang=pt_BR
+// /js/games/squareOne.js: data += &line_game=square&line_mode=a&line_oper=plus&line_leve=1&line_posi=1&line_resu=true&line_time=3&line_deta=numBlocks:3, valBlocks: 1,1,1, blockIndex: 2, floorIndex: 2;url=php/save.php
 $name = $_REQUEST["line_name"];
 $date = date("Y-m-d H:i:s");
 $lang = $_REQUEST["line_lang"];