jclic 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +5 -7
  2. package/dist-node/jclic-node.js +14157 -0
  3. package/dist-node/jclic-node.umd.cjs +530 -0
  4. package/package.json +38 -26
  5. package/.vscode/launch.json +0 -33
  6. package/.vscode/settings.json +0 -13
  7. package/CHANGELOG.md +0 -672
  8. package/TRANSLATIONS.md +0 -11
  9. package/build-locales.mjs +0 -82
  10. package/dist/jclic-node.js +0 -31680
  11. package/dist/jclic-node.js.map +0 -1
  12. package/dist/jclic.components.LICENSE +0 -2254
  13. package/dist/jclic.min.js +0 -27
  14. package/dist/jclic.min.js.map +0 -1
  15. package/eslint.config.mjs +0 -31
  16. package/jsdoc.config.js +0 -71
  17. package/locales/ar.po +0 -244
  18. package/locales/ast.po +0 -246
  19. package/locales/bs.po +0 -247
  20. package/locales/ca.po +0 -248
  21. package/locales/ca_ES@valencia.po +0 -248
  22. package/locales/cs.po +0 -244
  23. package/locales/da.po +0 -244
  24. package/locales/de.po +0 -246
  25. package/locales/el.po +0 -244
  26. package/locales/es.po +0 -248
  27. package/locales/eu.po +0 -244
  28. package/locales/fr.po +0 -244
  29. package/locales/gl.po +0 -244
  30. package/locales/he.po +0 -244
  31. package/locales/hr.po +0 -245
  32. package/locales/it.po +0 -246
  33. package/locales/ja.po +0 -242
  34. package/locales/jclic.js.pot +0 -241
  35. package/locales/nb_NO.po +0 -244
  36. package/locales/nl.po +0 -244
  37. package/locales/pl.po +0 -244
  38. package/locales/pt.po +0 -244
  39. package/locales/pt_BR.po +0 -248
  40. package/locales/ro.po +0 -248
  41. package/locales/ru.po +0 -245
  42. package/locales/ta.po +0 -244
  43. package/locales/tr.po +0 -246
  44. package/locales/uk.po +0 -247
  45. package/locales/vec.po +0 -244
  46. package/locales/zh_TW.po +0 -246
  47. package/patches/po2json+1.0.0-beta-3.patch +0 -12
  48. package/src/AWT.js +0 -2067
  49. package/src/Activity.js +0 -1311
  50. package/src/Deps.js +0 -232
  51. package/src/GlobalData.js +0 -5
  52. package/src/JClic.js +0 -196
  53. package/src/JClicPlayer.js +0 -1308
  54. package/src/PlayerHistory.js +0 -305
  55. package/src/Utils.js +0 -1355
  56. package/src/activities/associations/ComplexAssociation.js +0 -321
  57. package/src/activities/associations/SimpleAssociation.js +0 -519
  58. package/src/activities/memory/MemoryGame.js +0 -423
  59. package/src/activities/panels/Explore.js +0 -349
  60. package/src/activities/panels/Identify.js +0 -356
  61. package/src/activities/panels/InformationScreen.js +0 -262
  62. package/src/activities/panels/Menu.js +0 -209
  63. package/src/activities/panels/icons/ico00.png +0 -0
  64. package/src/activities/panels/icons/ico01.png +0 -0
  65. package/src/activities/panels/icons/ico02.png +0 -0
  66. package/src/activities/panels/icons/ico03.png +0 -0
  67. package/src/activities/panels/icons/icofolder.png +0 -0
  68. package/src/activities/puzzles/DoublePuzzle.js +0 -424
  69. package/src/activities/puzzles/ExchangePuzzle.js +0 -374
  70. package/src/activities/puzzles/HolePuzzle.js +0 -360
  71. package/src/activities/text/Complete.js +0 -127
  72. package/src/activities/text/Evaluator.js +0 -534
  73. package/src/activities/text/FillInBlanks.js +0 -426
  74. package/src/activities/text/IdentifyText.js +0 -253
  75. package/src/activities/text/OrderText.js +0 -421
  76. package/src/activities/text/TextActivityBase.js +0 -557
  77. package/src/activities/text/TextActivityDocument.js +0 -660
  78. package/src/activities/text/WrittenAnswer.js +0 -557
  79. package/src/activities/textGrid/CrossWord.js +0 -565
  80. package/src/activities/textGrid/WordSearch.js +0 -458
  81. package/src/activities/textGrid/icons/hIcon.svg +0 -3
  82. package/src/activities/textGrid/icons/vIcon.svg +0 -3
  83. package/src/automation/AutoContentProvider.js +0 -182
  84. package/src/automation/arith/Arith.js +0 -864
  85. package/src/bags/ActivitySequence.js +0 -318
  86. package/src/bags/ActivitySequenceElement.js +0 -161
  87. package/src/bags/ActivitySequenceJump.js +0 -140
  88. package/src/bags/ConditionalJumpInfo.js +0 -113
  89. package/src/bags/JumpInfo.js +0 -136
  90. package/src/bags/MediaBag.js +0 -215
  91. package/src/bags/MediaBagElement.js +0 -516
  92. package/src/boxes/AbstractBox.js +0 -699
  93. package/src/boxes/ActiveBagContent.js +0 -494
  94. package/src/boxes/ActiveBox.js +0 -810
  95. package/src/boxes/ActiveBoxBag.js +0 -357
  96. package/src/boxes/ActiveBoxContent.js +0 -484
  97. package/src/boxes/ActiveBoxGrid.js +0 -179
  98. package/src/boxes/BoxBag.js +0 -500
  99. package/src/boxes/BoxBase.js +0 -398
  100. package/src/boxes/BoxConnector.js +0 -325
  101. package/src/boxes/TextGrid.js +0 -887
  102. package/src/boxes/TextGridContent.js +0 -215
  103. package/src/init-jsdom.js +0 -65
  104. package/src/jclic-node.js +0 -219
  105. package/src/media/ActiveMediaBag.js +0 -145
  106. package/src/media/ActiveMediaPlayer.js +0 -297
  107. package/src/media/AudioBuffer.js +0 -219
  108. package/src/media/EventSounds.js +0 -169
  109. package/src/media/EventSoundsElement.js +0 -155
  110. package/src/media/MediaContent.js +0 -328
  111. package/src/media/MidiAudioPlayer.js +0 -254
  112. package/src/media/icons/audio.svg +0 -3
  113. package/src/media/icons/generic.svg +0 -3
  114. package/src/media/icons/mic.svg +0 -3
  115. package/src/media/icons/movie.svg +0 -3
  116. package/src/media/icons/music.svg +0 -3
  117. package/src/media/icons/url.svg +0 -3
  118. package/src/media/sounds/actionError.mp3 +0 -0
  119. package/src/media/sounds/actionOk.mp3 +0 -0
  120. package/src/media/sounds/click.mp3 +0 -0
  121. package/src/media/sounds/finishedError.mp3 +0 -0
  122. package/src/media/sounds/finishedOk.mp3 +0 -0
  123. package/src/media/sounds/start.mp3 +0 -0
  124. package/src/project/JClicProject.js +0 -282
  125. package/src/project/ProjectSettings.js +0 -273
  126. package/src/report/ActionReg.js +0 -123
  127. package/src/report/ActivityReg.js +0 -271
  128. package/src/report/EncryptMin.js +0 -210
  129. package/src/report/Reporter.js +0 -727
  130. package/src/report/SCORM.js +0 -272
  131. package/src/report/SequenceReg.js +0 -275
  132. package/src/report/SessionReg.js +0 -340
  133. package/src/report/SessionStorageReporter.js +0 -131
  134. package/src/report/TCPReporter.js +0 -628
  135. package/src/shapers/ClassicJigSaw.js +0 -138
  136. package/src/shapers/Holes.js +0 -77
  137. package/src/shapers/JigSaw.js +0 -161
  138. package/src/shapers/Rectangular.js +0 -78
  139. package/src/shapers/Shaper.js +0 -386
  140. package/src/shapers/TriangularJigSaw.js +0 -121
  141. package/src/skins/BlueSkin.js +0 -80
  142. package/src/skins/Counter.js +0 -152
  143. package/src/skins/CustomSkin.js +0 -412
  144. package/src/skins/DefaultSkin.js +0 -376
  145. package/src/skins/EmptySkin.js +0 -82
  146. package/src/skins/GreenSkin.js +0 -94
  147. package/src/skins/MiniSkin.js +0 -130
  148. package/src/skins/OrangeSkin.js +0 -78
  149. package/src/skins/SimpleSkin.js +0 -92
  150. package/src/skins/Skin.js +0 -1021
  151. package/src/skins/assets/actionsIcon.svg +0 -3
  152. package/src/skins/assets/appLogo.svg +0 -8
  153. package/src/skins/assets/basic.css +0 -41
  154. package/src/skins/assets/closeDialogIcon.svg +0 -3
  155. package/src/skins/assets/closeIcon.svg +0 -3
  156. package/src/skins/assets/copyIcon.svg +0 -3
  157. package/src/skins/assets/fullScreenExitIcon.svg +0 -3
  158. package/src/skins/assets/fullScreenIcon.svg +0 -3
  159. package/src/skins/assets/infoIcon.svg +0 -3
  160. package/src/skins/assets/main.css +0 -43
  161. package/src/skins/assets/mainHalf.css +0 -23
  162. package/src/skins/assets/mainTwoThirds.css +0 -23
  163. package/src/skins/assets/mini.css +0 -15
  164. package/src/skins/assets/nextIcon.svg +0 -3
  165. package/src/skins/assets/okDialogIcon.svg +0 -3
  166. package/src/skins/assets/prevIcon.svg +0 -3
  167. package/src/skins/assets/reports.css +0 -156
  168. package/src/skins/assets/reportsIcon.svg +0 -3
  169. package/src/skins/assets/scoreIcon.svg +0 -3
  170. package/src/skins/assets/simple.css +0 -16
  171. package/src/skins/assets/simpleHalf.css +0 -11
  172. package/src/skins/assets/simpleTwoThirds.css +0 -11
  173. package/src/skins/assets/timeIcon.svg +0 -4
  174. package/src/skins/assets/waitAnim.css +0 -54
  175. package/src/skins/assets/waitImgBig.svg +0 -3
  176. package/src/skins/assets/waitImgSmall.svg +0 -3
  177. package/webpack.config.mjs +0 -169
@@ -1,565 +0,0 @@
1
- /**
2
- * File : activities/textGrid/CrossWord.js
3
- * Created : 17/06/2015
4
- * By : Francesc Busquets <francesc@gmail.com>
5
- *
6
- * JClic.js
7
- * An HTML5 player of JClic activities
8
- * https://projectestac.github.io/jclic.js
9
- *
10
- * @source https://github.com/projectestac/jclic.js
11
- *
12
- * @license EUPL-1.2
13
- * @licstart
14
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
15
- *
16
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
17
- * the European Commission- subsequent versions of the EUPL (the "Licence");
18
- * You may not use this work except in compliance with the Licence.
19
- *
20
- * You may obtain a copy of the Licence at:
21
- * https://joinup.ec.europa.eu/software/page/eupl
22
- *
23
- * Unless required by applicable law or agreed to in writing, software
24
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
25
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26
- * Licence for the specific language governing permissions and limitations
27
- * under the Licence.
28
- * @licend
29
- * @module
30
- */
31
-
32
- /* global window */
33
-
34
- import $ from 'jquery';
35
- import { Activity, ActivityPanel } from '../../Activity.js';
36
- import BoxBase from '../../boxes/BoxBase.js';
37
- import BoxBag from '../../boxes/BoxBag.js';
38
- import TextGrid from '../../boxes/TextGrid.js';
39
- import AbstractBox from '../../boxes/AbstractBox.js';
40
- import ActiveBox from '../../boxes/ActiveBox.js';
41
- import { Rectangle, Point } from '../../AWT.js';
42
- import { settings, svgToURI } from '../../Utils.js';
43
-
44
- // Use Webpack to import SVG files
45
- import hIcon from './icons/hIcon.svg';
46
- import vIcon from './icons/vIcon.svg';
47
-
48
- /**
49
- * This class of {@link module:Activity.Activity Activity} shows a {@link module:boxes/TextGrid.TextGrid TextGrid} initially empty, with some cells
50
- * marked in negative color that act as word stoppers. A blinking "cursor" indicates the cell that
51
- * will receive the next character entered by the user on the keyboard.
52
- *
53
- * The letter in each cell of the grid is always shared by two words: one in horizontal direction
54
- * and the other one in vertical direction. Two {@link module:boxes/ActiveBox.ActiveBox ActiveBox} objects are placed next to the
55
- * {@link module:boxes/TextGrid.TextGrid TextGrid}, hosting the definitions of the horizontal and vertical words crossing at the
56
- * cell currently marked by the cursor.
57
- *
58
- * Two special buttons placed near this boxes allow to write on the grid horizontally or vertically.
59
- * The aim of the activity is to fill all the text grid with the correct words.
60
- * @extends module:Activity.Activity
61
- */
62
- export class CrossWord extends Activity {
63
- /**
64
- * CrossWord constructor
65
- * @param {module:project/JClicProject.JClicProject} project - The JClic project to which this activity belongs
66
- */
67
- constructor(project) {
68
- super(project);
69
- }
70
-
71
- /**
72
- * Retrieves the minimum number of actions needed to solve this activity
73
- * @override
74
- * @returns {number}
75
- */
76
- getMinNumActions() {
77
- return this.tgc.getNumChars() - this.tgc.countWildChars();
78
- }
79
-
80
- /**
81
- * Crossword activities always make use of the keyboard
82
- * @override
83
- * @returns {boolean}
84
- */
85
- needsKeyboard() {
86
- return true;
87
- }
88
- }
89
-
90
- Object.assign(CrossWord.prototype, {
91
- /**
92
- * Whether all letters of the {@link module:boxes/TextGrid.TextGrid TextGrid} should be displayed in upper case
93
- * @name module:activities/textGrid/CrossWord.CrossWord#upperCase
94
- * @type {boolean} */
95
- upperCase: true,
96
- /**
97
- * Whether the case is significant to evaluate answers
98
- * @name module:activities/textGrid/CrossWord.CrossWord#checkCase
99
- * @type {boolean} */
100
- checkCase: true,
101
- /**
102
- * When `true`, the wildcard character of the {@link module:boxes/TextGrid.TextGrid TextGrid} will be transparent.
103
- * @name module:activities/textGrid/CrossWord.CrossWord#wildTransparent
104
- * @type {boolean} */
105
- wildTransparent: false,
106
- });
107
-
108
- /**
109
- * The {@link module:Activity.ActivityPanel ActivityPanel} where {@link module:activities/textGrid/CrossWord.CrossWord CrossWord} activities are played.
110
- * @extends module:Activity.ActivityPanel
111
- */
112
- export class CrossWordPanel extends ActivityPanel {
113
- /**
114
- * CrossWordPanel constructor
115
- * @param {module:Activity.Activity} act - The {@link module:Activity.Activity Activity} to which this Panel belongs
116
- * @param {module:JClicPlayer.JClicPlayer} ps - Any object implementing the methods defined in the
117
- * [PlayStation](http://projectestac.github.io/jclic/apidoc/edu/xtec/jclic/PlayStation.html) Java interface.
118
- * @param {external:jQuery} [$div] - The jQuery DOM element where this Panel will deploy
119
- */
120
- constructor(act, ps, $div) {
121
- super(act, ps, $div);
122
- }
123
-
124
- /**
125
- * Performs miscellaneous cleaning operations
126
- * @override
127
- */
128
- clear() {
129
- if (this.grid) {
130
- this.grid.end();
131
- this.grid = null;
132
- }
133
- if (this.style) {
134
- this.style.end();
135
- this.style = null;
136
- }
137
- }
138
-
139
- /**
140
- * Creates a {@link module:boxes/BoxBag.BoxBag BoxBag} with a label ("Horizontal" or "Vertical") and an {@link module:boxes/ActiveBox.ActiveBox ActiveBox}
141
- * that will be used to display clues.
142
- * @param {string} type - `acrossClues` for horizontal clues, 'downClues' for vertical.
143
- * @returns {module:boxes/BoxBag.BoxBag}
144
- */
145
- createBoxBag(type) {
146
- const
147
- bxb = new BoxBag(null, this, null),
148
- sb = new AbstractBox(bxb, this, this.icoBB);
149
-
150
- sb.setBounds(0, 0, this.LABEL_WIDTH, this.act.abc[type].h);
151
- const $btn = $('<button/>', { class: 'StockBtn' }).css({
152
- 'width': this.LABEL_WIDTH,
153
- 'height': this.act.abc[type].h,
154
- 'background-image': `url(${type === 'acrossClues' ? this.hIcon : this.vIcon})`,
155
- 'background-repeat': 'no-repeat',
156
- 'background-position': 'center',
157
- 'border-radius': '6px',
158
- 'z-index': 10
159
- }).on('click', () => {
160
- this.advance = type === 'acrossClues' ?
161
- this.advance === 'ADVANCE_RIGHT' ?
162
- 'NO_ADVANCE' : 'ADVANCE_RIGHT' :
163
- this.advance === 'ADVANCE_DOWN' ?
164
- 'NO_ADVANCE' : 'ADVANCE_DOWN';
165
- this.setBtnStatus();
166
- }).on('keypress', event => {
167
- if (String.fromCharCode(event.charCode || event.keyCode) === ' ')
168
- event.stopPropagation();
169
- }).appendTo(this.$div);
170
-
171
- sb.setHostedComponent($btn);
172
- bxb.addBox(sb);
173
-
174
- const ab = new ActiveBox(bxb, null, null, type, new Rectangle(this.LABEL_WIDTH + this.act.margin, 0, this.act.abc[type].w, this.act.abc[type].h));
175
- bxb.addBox(ab);
176
- bxb.setBoxBase(this.act.abc[type].style);
177
-
178
- if (type === 'acrossClues') { // Horizontal
179
- this.hClue = ab;
180
- this.hClueBtn = sb;
181
- } else {
182
- this.vClue = ab;
183
- this.vClueBtn = sb;
184
- }
185
- return bxb;
186
- }
187
-
188
- /**
189
- * Prepares the visual components of the activity
190
- * @override
191
- */
192
- buildVisualComponents() {
193
- if (this.firstRun)
194
- super.buildVisualComponents();
195
- this.clear();
196
-
197
- const
198
- tgc = this.act.tgc,
199
- abcH = this.act.abc['acrossClues'],
200
- abcV = this.act.abc['downClues'];
201
-
202
- if (abcH.image)
203
- abcH.setImgContent(this.act.project.mediaBag, null, false);
204
- if (abcV.image)
205
- abcV.setImgContent(this.act.project.mediaBag, null, false);
206
-
207
- if (this.act.acp !== null) {
208
- this.act.acp.generateContent(0, 0, this.act.abc, false);
209
- }
210
-
211
- if (tgc) {
212
- this.grid = TextGrid.createEmptyGrid(null, this, this.act.margin, this.act.margin, tgc, this.act.wildTransparent);
213
- this.style = new BoxBag(null, this, null);
214
- const
215
- bxbh = this.createBoxBag('acrossClues'),
216
- bxbv = this.createBoxBag('downClues');
217
- if (this.act.boxGridPos === 'AUB' || this.act.boxGridPos === 'BUA')
218
- bxbv.moveTo(new Point(bxbh.dim.width + this.act.margin, 0));
219
- else
220
- bxbv.moveTo(new Point(0, bxbh.dim.height + this.act.margin));
221
- this.style.addBox(bxbh);
222
- this.style.addBox(bxbv);
223
- this.grid.setVisible(true);
224
- this.style.setVisible(true);
225
- }
226
- }
227
-
228
- /**
229
- * Basic initialization procedure
230
- * @override
231
- */
232
- initActivity() {
233
- super.initActivity();
234
- if (!this.firstRun)
235
- this.buildVisualComponents();
236
- else
237
- this.firstRun = false;
238
-
239
- if (this.grid) {
240
- this.grid.setChars(this.act.tgc.text);
241
- this.numLetters = this.act.getMinNumActions();
242
- this.grid.setCellAttributes(true, true);
243
- this.grid.setCursorEnabled(true);
244
- this.setCursorAt(0, 0);
245
- this.advance = 'ADVANCE_RIGHT';
246
- this.setBtnStatus();
247
- this.setAndPlayMsg('initial', 'start');
248
- this.invalidate().update();
249
- this.$div.attr("tabindex", 0);
250
- this.$div.trigger('focus');
251
- this.playing = true;
252
- }
253
- }
254
-
255
- /**
256
- * Calculates the current score
257
- * @returns {number}
258
- */
259
- getCurrentScore() {
260
- return this.grid ? this.grid.countCoincidences(this.act.checkCase) : 0;
261
- }
262
-
263
- /**
264
- * Updates the graphic content of this panel.
265
- * This method will be called from {@link module:AWT.Container#update} when needed.
266
- * @override
267
- * @param {module:AWT.Rectangle} dirtyRegion - Specifies the area to be updated. When `null`,
268
- * it's the whole panel.
269
- */
270
- updateContent(dirtyRegion) {
271
- super.updateContent(dirtyRegion);
272
- if (this.grid && this.$canvas) {
273
- const
274
- canvas = this.$canvas.get(-1),
275
- ctx = canvas.getContext('2d');
276
- if (!dirtyRegion)
277
- dirtyRegion = new Rectangle(0, 0, canvas.width, canvas.height);
278
- ctx.clearRect(dirtyRegion.pos.x, dirtyRegion.pos.y, dirtyRegion.dim.width, dirtyRegion.dim.height);
279
- this.grid.update(ctx, dirtyRegion);
280
- this.style.update(ctx, dirtyRegion);
281
- }
282
- return this;
283
- }
284
-
285
- /**
286
- * Sets the real dimension of this panel.
287
- * @override
288
- * @param {module:AWT.Dimension} preferredMaxSize - The maximum surface available for the activity panel
289
- * @returns {module:AWT.Dimension}
290
- */
291
- setDimension(preferredMaxSize) {
292
- return !this.grid || !this.style || this.getBounds().equals(preferredMaxSize) ?
293
- preferredMaxSize :
294
- BoxBag.layoutDouble(preferredMaxSize, this.grid, this.style, this.act.boxGridPos, this.act.margin);
295
- }
296
-
297
- /**
298
- * Sets the size and position of this activity panel
299
- * @override
300
- * @param {module:AWT.Rectangle} rect
301
- */
302
- setBounds(rect) {
303
- if (this.$canvas) {
304
- this.$canvas.remove();
305
- this.$canvas = null;
306
- }
307
- super.setBounds(rect);
308
-
309
- if (this.grid) {
310
- // Create the main canvas
311
- this.$canvas = $(`<canvas width="${rect.dim.width}" height="${rect.dim.height}"/>`).css({
312
- position: 'absolute',
313
- top: 0,
314
- left: 0
315
- });
316
- this.$div.append(this.$canvas);
317
- // Repaint all
318
- this.invalidate().update();
319
- }
320
- }
321
-
322
- /**
323
- * Main handler used to process mouse, touch, keyboard and edit events
324
- * @override
325
- * @param {external:Event} event - The HTML event to be processed
326
- * @returns {boolean} - When this event handler returns `false`, jQuery will stop its
327
- * propagation through the DOM tree. See: {@link http://api.jquery.com/on}
328
- */
329
- processEvent(event) {
330
- if (this.playing) {
331
- switch (event.type) {
332
- case 'click':
333
- //
334
- // The [AWT.Point](AWT.html#Point) where the mouse or touch event has been originated
335
- // Touch events can have more than one touch, so `pageX` must be obtained from `touches[0]`
336
- const
337
- x = event.originalEvent && event.originalEvent.touches ? event.originalEvent.touches[0].pageX : event.pageX,
338
- y = event.originalEvent && event.originalEvent.touches ? event.originalEvent.touches[0].pageY : event.pageY,
339
- p = new Point(x - this.$div.offset().left, y - this.$div.offset().top),
340
- // Array to be filled with actions to be executed at the end of event processing
341
- delayedActions = [];
342
-
343
- this.ps.stopMedia(1);
344
- if (this.grid.contains(p)) {
345
- const pt = this.grid.getLogicalCoords(p);
346
- if (pt !== null) {
347
- this.setCursorAt(pt.x, pt.y);
348
- if (settings.TOUCH_DEVICE) {
349
- // We are in a touch device, so prompt user to write text:
350
- const d = this.advance === 'ADVANCE_DOWN';
351
- const txt = window.prompt(`${d ? 'Vertical' : 'Horizontal'} word:`, '');
352
- this.writeChars(txt);
353
- }
354
- }
355
- } else if (this.hClue.contains(p))
356
- this.hClue.playMedia(this.ps, delayedActions);
357
- else if (this.vClue.contains(p))
358
- this.vClue.playMedia(this.ps, delayedActions);
359
- else
360
- break;
361
-
362
- this.update();
363
- delayedActions.forEach(action => action());
364
- break;
365
-
366
- case 'keypress':
367
- const code = event.charCode || event.keyCode;
368
- if (code && this.grid.getCursor()) {
369
- event.preventDefault();
370
- this.writeChars(String.fromCharCode(code));
371
- }
372
- break;
373
-
374
- case 'keydown':
375
- let dx = 0, dy = 0;
376
- switch (event.keyCode) {
377
- case settings.VK.RIGHT:
378
- dx = 1;
379
- break;
380
- case settings.VK.LEFT:
381
- dx = -1;
382
- break;
383
- case settings.VK.DOWN:
384
- dy = 1;
385
- break;
386
- case settings.VK.UP:
387
- dy = -1;
388
- break;
389
- }
390
- if (dx || dy) {
391
- event.preventDefault();
392
- this.moveCursor(dx, dy);
393
- this.update();
394
- }
395
- break;
396
- }
397
- }
398
- }
399
-
400
- /**
401
- * Moves the cursor the specified `dx` and `dy` amount (in logical coordinates)
402
- * @param {number} dx - Amount of cells to horizontally move on
403
- * @param {number} dy - Amount of cells to vertically move on
404
- */
405
- moveCursor(dx, dy) {
406
- if (this.grid) {
407
- this.grid.moveCursor(dx, dy, true);
408
- this.cursorPosChanged();
409
- }
410
- }
411
-
412
- /**
413
- * Places the cursor at the specified location (in logical coordinates)
414
- * @param {number} x
415
- * @param {number} y
416
- */
417
- setCursorAt(x, y) {
418
- this.grid.setCursorAt(x, y, true);
419
- this.cursorPosChanged();
420
- }
421
-
422
- /**
423
- * Method called when the cursor moves to a different location
424
- */
425
- cursorPosChanged() {
426
- const pt = this.grid.getCursor();
427
- if (pt !== null && this.style !== null) {
428
- const items = this.grid.getItemFor(pt.x, pt.y);
429
- if (items !== null) {
430
- this.hClue.setContent(this.act.abc['acrossClues'].getActiveBoxContentWith(pt.y, items.x));
431
- this.vClue.setContent(this.act.abc['downClues'].getActiveBoxContentWith(pt.x, items.y));
432
- }
433
- }
434
- }
435
-
436
- /**
437
- * Writes a string on the grid starting at the current cursor position and
438
- * following the direction marked by the `advance` field
439
- * @param {string} txt - Text to write
440
- */
441
- writeChars(txt) {
442
- if (txt && txt.length > 0) {
443
- for (let i = 0; i < txt.length; i++) {
444
- const cur = this.grid.getCursor();
445
- let ch = txt.charAt(i);
446
- if (this.act.upperCase)
447
- ch = ch.toLocaleUpperCase();
448
- this.grid.setCharAt(cur.x, cur.y, ch);
449
- const
450
- ok = this.grid.isCellOk(cur.x, cur.y, this.act.checkCase),
451
- r = this.getCurrentScore();
452
- this.ps.reportNewAction(this.act, 'WRITE', ch, `X:${cur.x} Y:${cur.y}`, ok, r);
453
- // End activity or play event sound
454
- if (r === this.numLetters) {
455
- this.grid.setCursorEnabled(false);
456
- this.grid.stopCursorBlink();
457
- this.finishActivity(true);
458
- } else {
459
- this.playEvent('click');
460
- if (this.advance === 'ADVANCE_DOWN')
461
- this.moveCursor(0, 1);
462
- else if (this.advance === 'ADVANCE_RIGHT')
463
- this.moveCursor(1, 0);
464
- }
465
- }
466
- }
467
- this.update();
468
- }
469
-
470
- /**
471
- * Sets the status of horizontal and vertical buttons based on the value of `advance`
472
- */
473
- setBtnStatus() {
474
- if (this.hClueBtn)
475
- this.hClueBtn.setInactive(this.advance !== 'ADVANCE_RIGHT');
476
- if (this.vClueBtn)
477
- this.vClueBtn.setInactive(this.advance !== 'ADVANCE_DOWN');
478
- }
479
- }
480
-
481
- Object.assign(CrossWordPanel.prototype, {
482
- /**
483
- * The default width of the 'Horizontal' and 'Vertical' buttons (currently 40 pixels)
484
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#LABEL_WIDTH
485
- * @type {number} */
486
- LABEL_WIDTH: 40,
487
- /**
488
- * The text grid of this ActivityPanel
489
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#grid
490
- * @type {module:boxes/TextGrid.TextGrid} */
491
- grid: null,
492
- /**
493
- * A BoxBag used to place the across and down clues, and the `toggle direction` button.
494
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#style
495
- * @type {module:boxes/BoxBag.BoxBag} */
496
- style: null,
497
- /**
498
- * The total number of letters of this cross word
499
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#numLetters
500
- * @type {number} */
501
- numLetters: 0,
502
- /**
503
- * Flag indicating the type of automatic advance of the cursor.
504
- * Possible values are: `NO_ADVANCE` (default), 'ADVANCE_RIGHT' and 'ADVANCE_DOWN'.
505
- * TODO: Implement 'ADVANCE_LEFT' for LTR languages
506
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#advance
507
- * @type {string} */
508
- advance: 'NO_ADVANCE',
509
- /**
510
- * The ActiveBox object used to display the 'across' clues
511
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#hClue
512
- * @type {module:boxes/ActiveBox.ActiveBox} */
513
- hClue: null,
514
- /**
515
- * The ActiveBox object used to display the 'down' clues
516
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#vClue
517
- * @type {module:boxes/ActiveBox.ActiveBox} */
518
- vClue: null,
519
- /**
520
- * Button used to set the advance mode to 'ADVANCE_RIGHT'
521
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#hClueBtn
522
- * @type {module:boxes/ActiveBox.ActiveBox} */
523
- hClueBtn: null,
524
- /**
525
- * Button used to set the advance mode to 'ADVANCE_BOTTOM'
526
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#vClueBtn
527
- * @type {module:boxes/ActiveBox.ActiveBox} */
528
- vClueBtn: null,
529
- /**
530
- * Mouse and touch events intercepted by this panel
531
- * @override
532
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#events
533
- * @type {string[]} */
534
- events: ['click', 'keydown', 'keypress'],
535
- /**
536
- * Graphic icon for the horizontal direction button, represented as a string containing
537
- * an SVG file codified in base64.
538
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#hIcon
539
- * @type {string} */
540
- hIcon: svgToURI(hIcon),
541
- /**
542
- * Graphic icon for the vertical direction button, represented as a string containing
543
- * an SVG file codified in base64.
544
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#vIcon
545
- * @type {string} */
546
- vIcon: svgToURI(vIcon),
547
- /**
548
- * Sizes of the icons (currently 36 x 36 pixel)
549
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#icoSize
550
- * @type {object} */
551
- icoSize: { w: 36, h: 36 },
552
- /**
553
- * BoxBase with the style to be used by the direction buttons.
554
- * @name module:activities/textGrid/CrossWord.CrossWordPanel#icoBB
555
- * @type {module:boxes/BoxBase.BoxBase} */
556
- icoBB: new BoxBase().set('backColor', '#4285F4').set('inactiveColor', '#70A2F6').set('dontFill', true)
557
- });
558
-
559
- /**
560
- * Panel class associated to this type of activity: {@link module:activities/textGrid/CrossWord.CrossWordPanel CrossWordPanel}
561
- * @type {class} */
562
- CrossWord.Panel = CrossWordPanel;
563
-
564
- // Register activity class
565
- export default Activity.registerClass('@textGrid.CrossWord', CrossWord);