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.
- package/README.md +5 -7
- package/dist-node/jclic-node.js +14157 -0
- package/dist-node/jclic-node.umd.cjs +530 -0
- package/package.json +38 -26
- package/.vscode/launch.json +0 -33
- package/.vscode/settings.json +0 -13
- package/CHANGELOG.md +0 -672
- package/TRANSLATIONS.md +0 -11
- package/build-locales.mjs +0 -82
- package/dist/jclic-node.js +0 -31680
- package/dist/jclic-node.js.map +0 -1
- package/dist/jclic.components.LICENSE +0 -2254
- package/dist/jclic.min.js +0 -27
- package/dist/jclic.min.js.map +0 -1
- package/eslint.config.mjs +0 -31
- package/jsdoc.config.js +0 -71
- package/locales/ar.po +0 -244
- package/locales/ast.po +0 -246
- package/locales/bs.po +0 -247
- package/locales/ca.po +0 -248
- package/locales/ca_ES@valencia.po +0 -248
- package/locales/cs.po +0 -244
- package/locales/da.po +0 -244
- package/locales/de.po +0 -246
- package/locales/el.po +0 -244
- package/locales/es.po +0 -248
- package/locales/eu.po +0 -244
- package/locales/fr.po +0 -244
- package/locales/gl.po +0 -244
- package/locales/he.po +0 -244
- package/locales/hr.po +0 -245
- package/locales/it.po +0 -246
- package/locales/ja.po +0 -242
- package/locales/jclic.js.pot +0 -241
- package/locales/nb_NO.po +0 -244
- package/locales/nl.po +0 -244
- package/locales/pl.po +0 -244
- package/locales/pt.po +0 -244
- package/locales/pt_BR.po +0 -248
- package/locales/ro.po +0 -248
- package/locales/ru.po +0 -245
- package/locales/ta.po +0 -244
- package/locales/tr.po +0 -246
- package/locales/uk.po +0 -247
- package/locales/vec.po +0 -244
- package/locales/zh_TW.po +0 -246
- package/patches/po2json+1.0.0-beta-3.patch +0 -12
- package/src/AWT.js +0 -2067
- package/src/Activity.js +0 -1311
- package/src/Deps.js +0 -232
- package/src/GlobalData.js +0 -5
- package/src/JClic.js +0 -196
- package/src/JClicPlayer.js +0 -1308
- package/src/PlayerHistory.js +0 -305
- package/src/Utils.js +0 -1355
- package/src/activities/associations/ComplexAssociation.js +0 -321
- package/src/activities/associations/SimpleAssociation.js +0 -519
- package/src/activities/memory/MemoryGame.js +0 -423
- package/src/activities/panels/Explore.js +0 -349
- package/src/activities/panels/Identify.js +0 -356
- package/src/activities/panels/InformationScreen.js +0 -262
- package/src/activities/panels/Menu.js +0 -209
- package/src/activities/panels/icons/ico00.png +0 -0
- package/src/activities/panels/icons/ico01.png +0 -0
- package/src/activities/panels/icons/ico02.png +0 -0
- package/src/activities/panels/icons/ico03.png +0 -0
- package/src/activities/panels/icons/icofolder.png +0 -0
- package/src/activities/puzzles/DoublePuzzle.js +0 -424
- package/src/activities/puzzles/ExchangePuzzle.js +0 -374
- package/src/activities/puzzles/HolePuzzle.js +0 -360
- package/src/activities/text/Complete.js +0 -127
- package/src/activities/text/Evaluator.js +0 -534
- package/src/activities/text/FillInBlanks.js +0 -426
- package/src/activities/text/IdentifyText.js +0 -253
- package/src/activities/text/OrderText.js +0 -421
- package/src/activities/text/TextActivityBase.js +0 -557
- package/src/activities/text/TextActivityDocument.js +0 -660
- package/src/activities/text/WrittenAnswer.js +0 -557
- package/src/activities/textGrid/CrossWord.js +0 -565
- package/src/activities/textGrid/WordSearch.js +0 -458
- package/src/activities/textGrid/icons/hIcon.svg +0 -3
- package/src/activities/textGrid/icons/vIcon.svg +0 -3
- package/src/automation/AutoContentProvider.js +0 -182
- package/src/automation/arith/Arith.js +0 -864
- package/src/bags/ActivitySequence.js +0 -318
- package/src/bags/ActivitySequenceElement.js +0 -161
- package/src/bags/ActivitySequenceJump.js +0 -140
- package/src/bags/ConditionalJumpInfo.js +0 -113
- package/src/bags/JumpInfo.js +0 -136
- package/src/bags/MediaBag.js +0 -215
- package/src/bags/MediaBagElement.js +0 -516
- package/src/boxes/AbstractBox.js +0 -699
- package/src/boxes/ActiveBagContent.js +0 -494
- package/src/boxes/ActiveBox.js +0 -810
- package/src/boxes/ActiveBoxBag.js +0 -357
- package/src/boxes/ActiveBoxContent.js +0 -484
- package/src/boxes/ActiveBoxGrid.js +0 -179
- package/src/boxes/BoxBag.js +0 -500
- package/src/boxes/BoxBase.js +0 -398
- package/src/boxes/BoxConnector.js +0 -325
- package/src/boxes/TextGrid.js +0 -887
- package/src/boxes/TextGridContent.js +0 -215
- package/src/init-jsdom.js +0 -65
- package/src/jclic-node.js +0 -219
- package/src/media/ActiveMediaBag.js +0 -145
- package/src/media/ActiveMediaPlayer.js +0 -297
- package/src/media/AudioBuffer.js +0 -219
- package/src/media/EventSounds.js +0 -169
- package/src/media/EventSoundsElement.js +0 -155
- package/src/media/MediaContent.js +0 -328
- package/src/media/MidiAudioPlayer.js +0 -254
- package/src/media/icons/audio.svg +0 -3
- package/src/media/icons/generic.svg +0 -3
- package/src/media/icons/mic.svg +0 -3
- package/src/media/icons/movie.svg +0 -3
- package/src/media/icons/music.svg +0 -3
- package/src/media/icons/url.svg +0 -3
- package/src/media/sounds/actionError.mp3 +0 -0
- package/src/media/sounds/actionOk.mp3 +0 -0
- package/src/media/sounds/click.mp3 +0 -0
- package/src/media/sounds/finishedError.mp3 +0 -0
- package/src/media/sounds/finishedOk.mp3 +0 -0
- package/src/media/sounds/start.mp3 +0 -0
- package/src/project/JClicProject.js +0 -282
- package/src/project/ProjectSettings.js +0 -273
- package/src/report/ActionReg.js +0 -123
- package/src/report/ActivityReg.js +0 -271
- package/src/report/EncryptMin.js +0 -210
- package/src/report/Reporter.js +0 -727
- package/src/report/SCORM.js +0 -272
- package/src/report/SequenceReg.js +0 -275
- package/src/report/SessionReg.js +0 -340
- package/src/report/SessionStorageReporter.js +0 -131
- package/src/report/TCPReporter.js +0 -628
- package/src/shapers/ClassicJigSaw.js +0 -138
- package/src/shapers/Holes.js +0 -77
- package/src/shapers/JigSaw.js +0 -161
- package/src/shapers/Rectangular.js +0 -78
- package/src/shapers/Shaper.js +0 -386
- package/src/shapers/TriangularJigSaw.js +0 -121
- package/src/skins/BlueSkin.js +0 -80
- package/src/skins/Counter.js +0 -152
- package/src/skins/CustomSkin.js +0 -412
- package/src/skins/DefaultSkin.js +0 -376
- package/src/skins/EmptySkin.js +0 -82
- package/src/skins/GreenSkin.js +0 -94
- package/src/skins/MiniSkin.js +0 -130
- package/src/skins/OrangeSkin.js +0 -78
- package/src/skins/SimpleSkin.js +0 -92
- package/src/skins/Skin.js +0 -1021
- package/src/skins/assets/actionsIcon.svg +0 -3
- package/src/skins/assets/appLogo.svg +0 -8
- package/src/skins/assets/basic.css +0 -41
- package/src/skins/assets/closeDialogIcon.svg +0 -3
- package/src/skins/assets/closeIcon.svg +0 -3
- package/src/skins/assets/copyIcon.svg +0 -3
- package/src/skins/assets/fullScreenExitIcon.svg +0 -3
- package/src/skins/assets/fullScreenIcon.svg +0 -3
- package/src/skins/assets/infoIcon.svg +0 -3
- package/src/skins/assets/main.css +0 -43
- package/src/skins/assets/mainHalf.css +0 -23
- package/src/skins/assets/mainTwoThirds.css +0 -23
- package/src/skins/assets/mini.css +0 -15
- package/src/skins/assets/nextIcon.svg +0 -3
- package/src/skins/assets/okDialogIcon.svg +0 -3
- package/src/skins/assets/prevIcon.svg +0 -3
- package/src/skins/assets/reports.css +0 -156
- package/src/skins/assets/reportsIcon.svg +0 -3
- package/src/skins/assets/scoreIcon.svg +0 -3
- package/src/skins/assets/simple.css +0 -16
- package/src/skins/assets/simpleHalf.css +0 -11
- package/src/skins/assets/simpleTwoThirds.css +0 -11
- package/src/skins/assets/timeIcon.svg +0 -4
- package/src/skins/assets/waitAnim.css +0 -54
- package/src/skins/assets/waitImgBig.svg +0 -3
- package/src/skins/assets/waitImgSmall.svg +0 -3
- package/webpack.config.mjs +0 -169
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File : activities/memory/MemoryGame.js
|
|
3
|
-
* Created : 04/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
|
-
import $ from 'jquery';
|
|
33
|
-
import { Activity, ActivityPanel } from '../../Activity.js';
|
|
34
|
-
import ActiveBoxGrid from '../../boxes/ActiveBoxGrid.js';
|
|
35
|
-
import BoxBag from '../../boxes/BoxBag.js';
|
|
36
|
-
import BoxConnector from '../../boxes/BoxConnector.js';
|
|
37
|
-
import { Rectangle, Point } from '../../AWT.js';
|
|
38
|
-
import Rectangular from '../../shapers/Rectangular.js';
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* This class of {@link module:Activity.Activity Activity} shows a panel with duplicate {@link module:boxes/ActiveBox.ActiveBox ActiveBox} objects initially
|
|
42
|
-
* hidden and shuffled. To complete the activity, all object pairs must be found. Only two objects
|
|
43
|
-
* are revealed in every move, so the user must remember the content of each cell.
|
|
44
|
-
*
|
|
45
|
-
* The cell pairs can have identical content, defined in the `primary` {@link module:boxes/ActiveBagContent.ActiveBagContent ActiveBagContent} of
|
|
46
|
-
* the activity, or two different contents. In this case, the `secondary` bag elements will have
|
|
47
|
-
* content related to each `primary` element.
|
|
48
|
-
* @extends module:Activity.Activity
|
|
49
|
-
*/
|
|
50
|
-
export class MemoryGame extends Activity {
|
|
51
|
-
/**
|
|
52
|
-
* MemoryGame constructor
|
|
53
|
-
* @param {module:project/JClicProject.JClicProject} project - The {@link module:project/JClicProject.JClicProject JClicProject} to which this activity belongs
|
|
54
|
-
*/
|
|
55
|
-
constructor(project) {
|
|
56
|
-
super(project);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Retrieves the minimum number of actions needed to solve this activity.
|
|
61
|
-
* @override
|
|
62
|
-
* @returns {number}
|
|
63
|
-
*/
|
|
64
|
-
getMinNumActions() {
|
|
65
|
-
return this.abc.primary.getNumCells();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Whether or not the activity uses random to shuffle internal components
|
|
70
|
-
* @override
|
|
71
|
-
* @returns {boolean}
|
|
72
|
-
*/
|
|
73
|
-
hasRandom() {
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* When `true`, the activity must always be shuffled
|
|
79
|
-
* @override
|
|
80
|
-
* @returns {boolean}
|
|
81
|
-
*/
|
|
82
|
-
shuffleAlways() {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The {@link module:Activity.ActivityPanel ActivityPanel} where {@link module:activities/memory/MemoryGame.MemoryGame MemoryGame} activities are played.
|
|
89
|
-
* @extends module:Activity.ActivityPanel
|
|
90
|
-
*/
|
|
91
|
-
export class MemoryGamePanel extends ActivityPanel {
|
|
92
|
-
/**
|
|
93
|
-
* MemoryGamePanel constructor
|
|
94
|
-
* @param {module:Activity.Activity} act - The {@link module:Activity.Activity Activity} to which this Panel belongs
|
|
95
|
-
* @param {module:JClicPlayer.JClicPlayer} ps - Any object implementing the methods defined in the
|
|
96
|
-
* [PlayStation](http://projectestac.github.io/jclic/apidoc/edu/xtec/jclic/PlayStation.html) Java interface.
|
|
97
|
-
* @param {external:jQuery} [$div] - The jQuery DOM element where this Panel will deploy
|
|
98
|
-
*/
|
|
99
|
-
constructor(act, ps, $div) {
|
|
100
|
-
super(act, ps, $div);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Miscellaneous cleaning operations
|
|
105
|
-
* @override
|
|
106
|
-
*/
|
|
107
|
-
clear() {
|
|
108
|
-
if (this.bg) {
|
|
109
|
-
this.bg.end();
|
|
110
|
-
this.bg = null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Prepares the visual components of the activity
|
|
116
|
-
* @override
|
|
117
|
-
*/
|
|
118
|
-
buildVisualComponents() {
|
|
119
|
-
if (this.firstRun)
|
|
120
|
-
super.buildVisualComponents();
|
|
121
|
-
this.clear();
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
abcA = this.act.abc['primary'],
|
|
125
|
-
abcB = this.act.abc['secondary'];
|
|
126
|
-
|
|
127
|
-
if (abcA) {
|
|
128
|
-
if (abcA.image)
|
|
129
|
-
abcA.setImgContent(this.act.project.mediaBag, null, false);
|
|
130
|
-
if (abcB && abcB.image)
|
|
131
|
-
abcB.setImgContent(this.act.project.mediaBag, null, false);
|
|
132
|
-
if (this.act.acp !== null) {
|
|
133
|
-
const contentKit = [abcA];
|
|
134
|
-
if (abcB)
|
|
135
|
-
contentKit.push(abcB);
|
|
136
|
-
this.act.acp.generateContent(abcA.nch, abcA.ncw, contentKit, false);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
let ncw = abcA.ncw, nch = abcA.nch;
|
|
140
|
-
if (this.act.boxGridPos === 'AB' || this.act.boxGridPos === 'BA')
|
|
141
|
-
ncw *= 2;
|
|
142
|
-
else
|
|
143
|
-
nch *= 2;
|
|
144
|
-
|
|
145
|
-
this.bg = new ActiveBoxGrid(null, this, abcA.style,
|
|
146
|
-
this.act.margin, this.act.margin,
|
|
147
|
-
abcA.w * ncw, abcA.h * nch, new Rectangular(ncw, nch));
|
|
148
|
-
|
|
149
|
-
const nc = abcA.getNumCells();
|
|
150
|
-
this.bg.setBorder(abcA.border);
|
|
151
|
-
this.bg.setContent(abcA, null, 0, 0, nc);
|
|
152
|
-
this.bg.setContent(abcB ? abcB : abcA, null, 0, nc, nc);
|
|
153
|
-
for (let i = 0; i < 2; i++) {
|
|
154
|
-
for (let j = 0; j < nc; j++) {
|
|
155
|
-
const bx = this.bg.getActiveBox(i * nc + j);
|
|
156
|
-
bx.idAss = j;
|
|
157
|
-
bx.setInactive(true);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
this.bg.setVisible(true);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Basic initialization procedure
|
|
166
|
-
* @override
|
|
167
|
-
*/
|
|
168
|
-
initActivity() {
|
|
169
|
-
super.initActivity();
|
|
170
|
-
|
|
171
|
-
if (!this.firstRun)
|
|
172
|
-
this.buildVisualComponents();
|
|
173
|
-
else
|
|
174
|
-
this.firstRun = false;
|
|
175
|
-
|
|
176
|
-
if (this.bg) {
|
|
177
|
-
this.shuffle([this.bg], true, true);
|
|
178
|
-
this.invalidate().update();
|
|
179
|
-
this.setAndPlayMsg('initial', 'start');
|
|
180
|
-
this.playing = true;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Updates the graphic content of this panel.
|
|
186
|
-
* This method will be called from {@link module:AWT.Container#update} when needed.
|
|
187
|
-
* @override
|
|
188
|
-
* @param {module:AWT.Rectangle} dirtyRegion - Specifies the area to be updated. When `null`,
|
|
189
|
-
* it's the whole panel.
|
|
190
|
-
*/
|
|
191
|
-
updateContent(dirtyRegion) {
|
|
192
|
-
super.updateContent(dirtyRegion);
|
|
193
|
-
if (this.bg && this.$canvas) {
|
|
194
|
-
const
|
|
195
|
-
canvas = this.$canvas.get(-1),
|
|
196
|
-
ctx = canvas.getContext('2d');
|
|
197
|
-
if (!dirtyRegion)
|
|
198
|
-
dirtyRegion = new Rectangle(0, 0, canvas.width, canvas.height);
|
|
199
|
-
ctx.clearRect(dirtyRegion.pos.x, dirtyRegion.pos.y, dirtyRegion.dim.width, dirtyRegion.dim.height);
|
|
200
|
-
this.bg.update(ctx, dirtyRegion);
|
|
201
|
-
}
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Sets the real dimension of this panel.
|
|
207
|
-
* @override
|
|
208
|
-
* @param {module:AWT.Dimension} preferredMaxSize - The maximum surface available for the activity panel
|
|
209
|
-
* @returns {module:AWT.Dimension}
|
|
210
|
-
*/
|
|
211
|
-
setDimension(preferredMaxSize) {
|
|
212
|
-
if (!this.bg || this.getBounds().equals(preferredMaxSize))
|
|
213
|
-
return preferredMaxSize;
|
|
214
|
-
return BoxBag.layoutSingle(preferredMaxSize, this.bg, this.act.margin);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Sets the size and position of this activity panel
|
|
219
|
-
* @override
|
|
220
|
-
* @param {module:AWT.Rectangle} rect
|
|
221
|
-
*/
|
|
222
|
-
setBounds(rect) {
|
|
223
|
-
if (this.$canvas)
|
|
224
|
-
this.$canvas.remove();
|
|
225
|
-
|
|
226
|
-
super.setBounds(rect);
|
|
227
|
-
if (this.bg) {
|
|
228
|
-
// Create the main canvas
|
|
229
|
-
this.$canvas = $(`<canvas width="${rect.dim.width}" height="${rect.dim.height}"/>`).css({
|
|
230
|
-
position: 'absolute',
|
|
231
|
-
top: 0,
|
|
232
|
-
left: 0
|
|
233
|
-
});
|
|
234
|
-
this.$div.append(this.$canvas);
|
|
235
|
-
|
|
236
|
-
// Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
|
|
237
|
-
this.bc = new BoxConnector(this, this.$canvas);
|
|
238
|
-
|
|
239
|
-
// Repaint all
|
|
240
|
-
this.invalidate().update();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Builds the accessible components needed for this ActivityPanel
|
|
246
|
-
* This method is called when all main elements are placed and visible, when the activity is ready
|
|
247
|
-
* to start or when resized.
|
|
248
|
-
* @override
|
|
249
|
-
*/
|
|
250
|
-
buildAccessibleComponents() {
|
|
251
|
-
if (this.$canvas && this.accessibleCanvas && this.bg) {
|
|
252
|
-
super.buildAccessibleComponents();
|
|
253
|
-
this.bg.setCellAttr('accessibleAlwaysActive', true);
|
|
254
|
-
this.bg.buildAccessibleElements(this.$canvas, this.$div, 'mousedown');
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Main handler used to process mouse, touch, keyboard and edit events
|
|
260
|
-
* @override
|
|
261
|
-
* @param {external:Event} event - The HTML event to be processed
|
|
262
|
-
* @returns {boolean} - When this event handler returns `false`, jQuery will stop its
|
|
263
|
-
* propagation through the DOM tree. See: {@link http://api.jquery.com/on}
|
|
264
|
-
*/
|
|
265
|
-
processEvent(event) {
|
|
266
|
-
if (this.bc && this.playing) {
|
|
267
|
-
//
|
|
268
|
-
// The [AWT.Point](AWT.html#Point) where the mouse or touch event has been originated
|
|
269
|
-
let p = null;
|
|
270
|
-
//
|
|
271
|
-
// Two [ActiveBox](ActiveBox.html) pointers used for the [BoxConnector](BoxConnector.html)
|
|
272
|
-
// `origin` and `dest` points.
|
|
273
|
-
let bx1, bx2,
|
|
274
|
-
// Array to be filled with actions to be executed at the end of event processing
|
|
275
|
-
delayedActions = [];
|
|
276
|
-
//
|
|
277
|
-
// _touchend_ event don't provide pageX nor pageY information
|
|
278
|
-
if (event.type === 'touchend')
|
|
279
|
-
p = this.bc.active ? this.bc.dest.clone() : new Point();
|
|
280
|
-
else {
|
|
281
|
-
// Touch events can have more than one touch, so `pageX` must be obtained from `touches[0]`
|
|
282
|
-
const
|
|
283
|
-
x = event.originalEvent && event.originalEvent.touches ? event.originalEvent.touches[0].pageX : event.pageX,
|
|
284
|
-
y = event.originalEvent && event.originalEvent.touches ? event.originalEvent.touches[0].pageY : event.pageY;
|
|
285
|
-
p = new Point(x - this.$div.offset().left, y - this.$div.offset().top);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Flag for tracking `mouseup` events
|
|
289
|
-
let up = false;
|
|
290
|
-
switch (event.type) {
|
|
291
|
-
case 'touchcancel':
|
|
292
|
-
// Canvel movement
|
|
293
|
-
if (this.bc.active)
|
|
294
|
-
this.bc.end();
|
|
295
|
-
break;
|
|
296
|
-
|
|
297
|
-
case 'mouseup':
|
|
298
|
-
case 'touchend':
|
|
299
|
-
// Don't consider drag moves below 3 pixels. Can be a "trembling click"
|
|
300
|
-
if (this.bc.active && p.distanceTo(this.bc.origin) <= 3)
|
|
301
|
-
break;
|
|
302
|
-
|
|
303
|
-
up = true;
|
|
304
|
-
/* falls through */
|
|
305
|
-
case 'touchstart':
|
|
306
|
-
case 'mousedown':
|
|
307
|
-
if (!this.bc.active) {
|
|
308
|
-
// New pairing starts
|
|
309
|
-
//
|
|
310
|
-
// Pairings can never start with a `mouseup` event
|
|
311
|
-
if (up)
|
|
312
|
-
break;
|
|
313
|
-
|
|
314
|
-
this.ps.stopMedia(1);
|
|
315
|
-
//
|
|
316
|
-
// Find the ActiveBox behind the clicked point
|
|
317
|
-
bx1 = this.bg ? this.bg.findActiveBox(p) : null;
|
|
318
|
-
if (bx1 && bx1.idAss !== -1) {
|
|
319
|
-
// Play cell media or event sound
|
|
320
|
-
if (!bx1.playMedia(this.ps, delayedActions))
|
|
321
|
-
this.playEvent('click');
|
|
322
|
-
bx1.setInactive(false);
|
|
323
|
-
// Start the [BoxConnector](BoxConnector.html)
|
|
324
|
-
this.update();
|
|
325
|
-
if (this.act.dragCells)
|
|
326
|
-
this.bc.begin(p, bx1);
|
|
327
|
-
else
|
|
328
|
-
this.bc.begin(p);
|
|
329
|
-
}
|
|
330
|
-
} else {
|
|
331
|
-
this.ps.stopMedia(1);
|
|
332
|
-
// Pairing completed
|
|
333
|
-
//
|
|
334
|
-
// Find the active boxes behind `bc.origin` and `p`
|
|
335
|
-
if (this.act.dragCells)
|
|
336
|
-
bx1 = this.bc.bx;
|
|
337
|
-
else
|
|
338
|
-
bx1 = this.bg ? this.bg.findActiveBox(this.bc.origin) : null;
|
|
339
|
-
this.bc.end();
|
|
340
|
-
bx2 = this.bg ? this.bg.findActiveBox(p) : null;
|
|
341
|
-
//
|
|
342
|
-
// Check if the pairing was OK
|
|
343
|
-
if (bx1 && bx1.idAss !== -1 && bx2 && bx2.idAss !== -1) {
|
|
344
|
-
if (bx1 !== bx2) {
|
|
345
|
-
let ok = false;
|
|
346
|
-
if (bx1.idAss === bx2.idAss ||
|
|
347
|
-
bx1.getContent().isEquivalent(bx2.getContent(), true)) {
|
|
348
|
-
ok = true;
|
|
349
|
-
bx1.idAss = -1;
|
|
350
|
-
bx1.setInactive(false);
|
|
351
|
-
bx2.idAss = -1;
|
|
352
|
-
bx2.setInactive(false);
|
|
353
|
-
} else {
|
|
354
|
-
bx1.setInactive(true);
|
|
355
|
-
if (this.act.dragCells)
|
|
356
|
-
bx2.setInactive(true);
|
|
357
|
-
else {
|
|
358
|
-
bx2.setInactive(false);
|
|
359
|
-
// Start the [BoxConnector](BoxConnector.html)
|
|
360
|
-
this.update();
|
|
361
|
-
if (this.act.dragCells)
|
|
362
|
-
this.bc.begin(p, bx1);
|
|
363
|
-
else
|
|
364
|
-
this.bc.begin(p);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
let m = bx2.playMedia(this.ps, delayedActions);
|
|
368
|
-
if (this.bg) {
|
|
369
|
-
const cellsAtPlace = this.bg.countCellsWithIdAss(-1);
|
|
370
|
-
this.ps.reportNewAction(this.act, 'MATCH', bx1.getDescription(), bx2.getDescription(), ok, cellsAtPlace / 2);
|
|
371
|
-
if (ok && cellsAtPlace === this.bg.getNumCells())
|
|
372
|
-
this.finishActivity(true);
|
|
373
|
-
else if (!m)
|
|
374
|
-
this.playEvent(ok ? 'actionOk' : 'actionError');
|
|
375
|
-
}
|
|
376
|
-
} else {
|
|
377
|
-
this.playEvent('CLICK');
|
|
378
|
-
bx1.setInactive(true);
|
|
379
|
-
}
|
|
380
|
-
} else if (bx1 !== null)
|
|
381
|
-
bx1.setInactive(true);
|
|
382
|
-
|
|
383
|
-
this.invalidate().update();
|
|
384
|
-
}
|
|
385
|
-
break;
|
|
386
|
-
|
|
387
|
-
case 'mousemove':
|
|
388
|
-
case 'touchmove':
|
|
389
|
-
this.bc.moveTo(p);
|
|
390
|
-
break;
|
|
391
|
-
}
|
|
392
|
-
delayedActions.forEach(action => action());
|
|
393
|
-
event.preventDefault();
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
Object.assign(MemoryGamePanel.prototype, {
|
|
399
|
-
/**
|
|
400
|
-
* The {@link module:boxes/ActiveBoxbag.ActiveBoxBag ActiveBoxBag} containing the information to be displayed.
|
|
401
|
-
* @name module:activities/memory/MemoryGame.MemoryGamePanel#bg
|
|
402
|
-
* @type {module:boxes/ActiveBoxBag.ActiveBoxBag} */
|
|
403
|
-
bg: null,
|
|
404
|
-
/**
|
|
405
|
-
* The {@link module:boxes/BoxConnector.BoxConnector BoxConnector} used to reveal pairs of cells
|
|
406
|
-
* @name module:activities/memory/MemoryGame.MemoryGamePanel#bc
|
|
407
|
-
* @type {module:boxes/BoxConnector.BoxConnector} */
|
|
408
|
-
bc: null,
|
|
409
|
-
/**
|
|
410
|
-
* List of mouse, touch and keyboard events intercepted by this panel
|
|
411
|
-
* @override
|
|
412
|
-
* @name module:activities/memory/MemoryGame.MemoryGamePanel#events
|
|
413
|
-
* @type {string[]} */
|
|
414
|
-
events: ['mousedown', 'mouseup', 'mousemove', 'touchstart', 'touchend', 'touchmove', 'touchcancel'],
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Panel class associated to this type of activity: {@link module:activities/memory/MemoryGame.MemoryGamePanel MemoryGamePanel}
|
|
419
|
-
* @type {class} */
|
|
420
|
-
MemoryGame.Panel = MemoryGamePanel;
|
|
421
|
-
|
|
422
|
-
// Register activity class
|
|
423
|
-
export default Activity.registerClass('@memory.MemoryGame', MemoryGame);
|