forked from chanind/hanzi-writer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quizActions.js
58 lines (52 loc) · 1.72 KB
/
quizActions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const Mutation = require('./Mutation');
const characterActions = require('./characterActions');
const { objRepeat } = require('./utils');
const startQuiz = (character, fadeDuration) => {
return characterActions.hideCharacter('main', character, fadeDuration)
.concat([
new Mutation('character.highlight', {
opacity: 1,
strokes: objRepeat({ opacity: 0 }, character.strokes.length),
}, { force: true }),
new Mutation('character.main', {
opacity: 1,
strokes: objRepeat({ opacity: 0 }, character.strokes.length),
}, { force: true }),
]);
};
const startUserStroke = (id, point) => {
return [
new Mutation('quiz.activeUserStrokeId', id, { force: true }),
new Mutation(`userStrokes.${id}`, {
points: [point],
opacity: 1,
}, { force: true }),
];
};
const updateUserStroke = (userStrokeId, points) => {
return [
new Mutation(`userStrokes.${userStrokeId}.points`, points, { force: true }),
];
};
const removeUserStroke = (userStrokeId, duration) => {
return [
new Mutation(`userStrokes.${userStrokeId}.opacity`, 0, { duration }),
new Mutation(`userStrokes.${userStrokeId}`, null, { force: true }),
];
};
const highlightCompleteChar = (character, color, duration) => {
return [
new Mutation('character.highlight.strokeColor', color),
]
.concat(characterActions.hideCharacter('highlight', character))
.concat(characterActions.showCharacter('highlight', character, duration / 2))
.concat(characterActions.hideCharacter('highlight', character, duration / 2));
};
module.exports = {
highlightCompleteChar,
highlightStroke: characterActions.highlightStroke,
startQuiz,
startUserStroke,
updateUserStroke,
removeUserStroke,
};