-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.ts
39 lines (36 loc) · 1.2 KB
/
store.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
import ICrane from './interfaces/crane';
import { animate } from './helpers';
export default function createStore(crane: ICrane) {
return new Proxy(crane, {
set(target, key, value) {
switch (key) {
case 'lift_elevation_mm': {
// TODO: check for constraints here
const heightLimit = target.constraints.lift_height_mm
- target.constraints.gripper_height_mm;
animate(
target[key],
(value > heightLimit ? heightLimit : value),
3,
(currLerp) => { target[key] = currLerp; },
);
return true;
}
case 'rail_position_mm': {
// TODO: check for constraints here
if (value > target.constraints.rail_length_mm) return true;
animate(target[key], value, 3, (currLerp) => { target[key] = currLerp; });
return true;
}
case 'swing_rot_deg': {
// TODO: check for constraints here
// if(value > target.constraints.rail_length_mm) return true
animate(target[key], value, 0.5, (currLerp) => { target[key] = currLerp; });
return true;
}
default:
return true;
}
},
});
}