forked from chanind/hanzi-writer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quizActions.ts
71 lines (65 loc) · 1.92 KB
/
quizActions.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
import Mutation, { MutationChain } from './Mutation';
import * as characterActions from './characterActions';
import { objRepeat } from './utils';
import Character from './models/Character';
import { Point } from './typings/types';
export const startQuiz = (character: Character, fadeDuration: number): MutationChain => {
return [
...characterActions.hideCharacter('main', character, fadeDuration),
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 },
),
];
};
export const startUserStroke = (id: string | number, point: Point): MutationChain => {
return [
new Mutation('quiz.activeUserStrokeId', id, { force: true }),
new Mutation(
`userStrokes.${id}`,
{
points: [point],
opacity: 1,
},
{ force: true },
),
];
};
export const updateUserStroke = (
userStrokeId: string | number,
points: Point[],
): MutationChain => {
return [new Mutation(`userStrokes.${userStrokeId}.points`, points, { force: true })];
};
export const removeUserStroke = (
userStrokeId: string | number,
duration: number,
): MutationChain => {
return [
new Mutation(`userStrokes.${userStrokeId}.opacity`, 0, { duration }),
new Mutation(`userStrokes.${userStrokeId}`, null, { force: true }),
];
};
export const highlightCompleteChar = (
character: Character,
duration: number,
): MutationChain => {
return [
...characterActions.hideCharacter('highlight', character),
...characterActions.showCharacter('highlight', character, duration / 2),
...characterActions.hideCharacter('highlight', character, duration / 2),
];
};
export const highlightStroke = characterActions.highlightStroke;