-
Notifications
You must be signed in to change notification settings - Fork 1
/
Motions.ts
123 lines (112 loc) · 2.6 KB
/
Motions.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { EasingType } from './EasingType';
import { TilePosition } from './TilePosition';
// MOTION SETTINGS
/**
* Motion settings.
*
* @public
*/
export type MotionSettings = {
/**
* The speed of the motion in pixels per second.
*/
speed: number;
/**
* The easing function to use for the motion.
*
* Easing functions specify the rate of change of a parameter over time
*
* @default 'linear'
*
* @see https://easings.net/
*/
easing?: EasingType;
/**
* The maximum duration of the motion in seconds.
* If it is not provided, the motion will run until it reaches the target using the configured speed.
* If it is provided, the speed will be calculated to reach the target in the given max duration.
*/
maxDuration?: number;
/**
* The minimum duration of the motion in seconds.
*
* @default 0
*/
minDuration?: number;
};
// MOTION REQUESTS
export type MotionRequestTarget = TilePosition | 'center' | number;
/**
* A motion request.
*
* @public
*/
export type MotionRequest<T extends MotionRequestTarget> = {
/**
* Settings of the motion.
*
* @example { speed: 100, easing: 'linear' }
*/
settings: MotionSettings;
/**
* The target position after the motion.
*/
target: T;
};
// MOTION QUEUE
export type CurrentMotionPosition = number | TilePosition;
/**
* A motion that is being executed.
*
* @public
*/
export type CurrentMotion<T extends CurrentMotionPosition> = {
/**
* The time at which the motion started in long milliseconds.
*/
startAt: number;
/**
* The time at which the motion will end in long milliseconds.
*/
endAt: number;
/**
* The easing function to use for the motion.
*
* Easing functions specify the rate of change of a parameter over time
*
* @default 'linear'
*/
easing?: EasingType;
/**
* The initial position before the motion.
*/
initialPosition: T;
/**
* The target position after the motion.
*/
targetPosition: T;
};
// RECENTER MOTION
/**
* Types of recenter motion targets.
*
* @public
*/
export type RecenterCameraMotionTarget = 'center' | TilePosition;
/**
* Configuration for camera motions that are being executed after a canvas resize or zoom change.
*
* @public
*/
export type RecenterCameraMotion = {
/**
* Settings of the motion.
*/
settings: MotionSettings;
/**
* The target position of the camera after any canvas resize.
* If it is 'center', the camera will be centered on the tilemap.
* If it is a tile position, the camera will be centered on the given tile position.
*/
target: RecenterCameraMotionTarget;
};