-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession-manager.mjs
79 lines (65 loc) · 1.61 KB
/
session-manager.mjs
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
// https://simon.html5.org/dump/html5-canvas-cheat-sheet.html
import { sumProp } from './utils.mjs';
import { rpms } from './constants/rpms.mjs';
let steps;
let sessionCurrentTime = 0;
let sessionDuration;
let sessionPercentage;
export function setSteps(steps_) {
sessionCurrentTime = 0;
sessionDuration = sumProp(steps_, 'seconds');
sessionPercentage = 0;
steps = steps_;
}
function _getCurrentStep() {
let s = 0;
for (let step of steps) {
if (sessionCurrentTime >= s && sessionCurrentTime <= s + step.seconds) {
return { step, stepTime: sessionCurrentTime - s };
}
s += step.seconds;
}
return {};
}
export function getCurrentStep() {
return _getCurrentStep().step;
}
export function getSessionCurrentTime() {
return sessionCurrentTime;
}
export function getCurrentStepCurrentTime() {
return _getCurrentStep().stepTime || 0;
}
export function getCurrentStepTimeLeft() {
return getCurrentStepDuration() - getCurrentStepCurrentTime();
}
export function setSessionCurrentTime(ct) {
sessionCurrentTime = ct;
sessionPercentage = Math.min(
sessionDuration,
Math.max(0, ct / sessionDuration)
);
}
export function getCurrentStepIntensity() {
const step = getCurrentStep();
if (!step) {
return;
}
return step.intensity;
}
export function getCurrentStepDuration() {
const step = getCurrentStep();
if (!step) {
return;
}
return step.seconds;
}
export function getCurrentRpm() {
return rpms[getCurrentStepIntensity()] || 0;
}
export function getSessionPercentage() {
return sessionPercentage;
}
export function getSessionDuration() {
return sessionDuration;
}