integrationFunctions.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // MOODLE MODIF.
  2. console.log("integrationFunctions.js: start.");
  3. const moodleVar = {
  4. hits: [0,0,0,0],
  5. errors: [0,0,0,0],
  6. time: [0,0,0,0]
  7. }
  8. let getParameterByName = function (name) {
  9. var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
  10. return match ? decodeURIComponent(match[1].replace(/\+/g, ' ')) : null;
  11. }
  12. const iLMparameters = {
  13. iLM_PARAM_ServerToGetAnswerURL: getParameterByName("iLM_PARAM_ServerToGetAnswerURL"),
  14. iLM_PARAM_SendAnswer: getParameterByName("iLM_PARAM_SendAnswer"),
  15. iLM_PARAM_AssignmentURL: getParameterByName("iLM_PARAM_AssignmentURL"),
  16. iLM_PARAM_Assignment: getParameterByName("iLM_PARAM_Assignment"),
  17. lang: getParameterByName("lang")
  18. };
  19. function getAnswer() {
  20. console.log("integrationFunctions.js: start getAnswer()");
  21. let str = '';
  22. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') { // professor
  23. str += 'gameTypeString:' + gameTypeString
  24. + '\ngameShape:' + gameShape
  25. + '\ngameModeType:' + gameModeType
  26. + '\ngameOperationType:' + gameOperationType
  27. + '\ngameDifficulty:' + gameDifficulty
  28. + '\nfractionLabel:' + fractionLabel
  29. + '\nresults:';
  30. for (let i = 0; i < moodleVar.hits.length; i++) {
  31. str += '{level:' + (i + 1)
  32. + ',hits:' + moodleVar.hits[i]
  33. + ',errors:' + moodleVar.errors[i]
  34. + ',timeElapsed:' + moodleVar.time[i]
  35. + '}';
  36. }
  37. } else { // professor
  38. if (!gameType) {
  39. alert("Erro: Você precisa escolher pelo menos um jogo");
  40. return x;
  41. }
  42. moodleVar.hits = [0, 0, 0, 0];
  43. moodleVar.errors = [0, 0, 0, 0];
  44. moodleVar.time = [0, 0, 0, 0];
  45. str += 'gameTypeString:' + gameTypeString
  46. + '\ngameShape:' + gameShape
  47. + '\ngameModeType:' + gameModeType
  48. + '\ngameOperationType:' + gameOperationType
  49. + '\ngameDifficulty:' + gameDifficulty
  50. + '\nfractionLabel:' + fractionLabel;
  51. }
  52. console.log("-----------------");
  53. console.log(str);
  54. console.log("-----------------");
  55. console.log("integrationFunctions.js: end getAnswer()");
  56. return str;
  57. }
  58. function getEvaluation() {
  59. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') { // aluno
  60. const nota = 1;
  61. parent.getEvaluationCallback(nota);
  62. return nota;
  63. }
  64. }
  65. function decodificaArquivo(text) {
  66. let gameInfo = {};
  67. let line = text.split('\n');
  68. line.forEach(cur => {
  69. try {
  70. let newline = cur.split(':');
  71. const chave = newline[0].replace(/^\s+|\s+$/g, '');
  72. const valor = newline[1].replace(/^\s+|\s+$/g, '');
  73. gameInfo[chave.trim()] = valor.trim();
  74. } catch (Error) { if (debugMode) console.log('Sintax error'); }
  75. });
  76. gameTypeString = gameInfo['gameTypeString'];
  77. gameShape = gameInfo['gameShape'];
  78. gameModeType = gameInfo['gameModeType'];
  79. gameOperationType = gameInfo['gameOperationType'];
  80. gameDifficulty = parseInt(gameInfo['gameDifficulty']);
  81. fractionLabel = gameInfo['fractionLabel'];
  82. console.log("decodificaArquivo:", gameTypeString, gameShape, gameModeType, gameOperationType, gameDifficulty, fractionLabel);
  83. mapPosition = 0; // Map position
  84. mapMove = true; // Move no next point
  85. completedLevels = 0; // Reset the game progress when entering a new level
  86. if (iLMparameters.iLM_PARAM_SendAnswer == 'false') { // aluno
  87. iLMparameters.return_get_answer = 1;
  88. iLMparameters.iLM_PARAM_ActivityEvaluation = ((mapPosition == 4) ? 1 : 0);
  89. iLMparameters.iLM_PARAM_ArchiveContent = text;
  90. } else { // professor
  91. iLMparameters.iLM_PARAM_ActivityEvaluation = 0;
  92. iLMparameters.iLM_PARAM_ArchiveContent = text;
  93. }
  94. game.state.start('customMenu');
  95. }
  96. function getiLMContent() {
  97. const url = iLMparameters.iLM_PARAM_Assignment;
  98. if (iLMparameters.iLM_PARAM_Assignment == null) {
  99. console.log("integrationFunctions.js: getiLMContent(): NAO existe arquivo FRC para ser carregado (iLMparameters.iLM_PARAM_Assignment vazio), finalize.");
  100. return;
  101. }
  102. console.log("integrationFunctions.js: getiLMContent(): tenta pegar arquivo de " + url);
  103. let gameFile = new XMLHttpRequest();
  104. gameFile.open("GET", url, true);
  105. gameFile.send();
  106. gameFile.responseType = "text";
  107. gameFile.onreadystatechange = function () {
  108. if (gameFile.readyState === 4 && gameFile.status === 200) {
  109. const text = gameFile.responseText;
  110. decodificaArquivo(text);
  111. }
  112. }
  113. console.log("integrationFunctions.js: getiLMContent(): final");
  114. }
  115. console.log("integrationFunctions.js: end.");