-
Notifications
You must be signed in to change notification settings - Fork 1
/
CatchReplayFrame.ts
71 lines (59 loc) · 1.6 KB
/
CatchReplayFrame.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 {
IConvertibleReplayFrame,
LegacyReplayFrame,
ReplayButtonState,
ReplayFrame,
Vector2,
} from 'osu-classes';
import { CatchAction } from './Enums/CatchAction';
export class CatchReplayFrame extends ReplayFrame implements IConvertibleReplayFrame {
/**
* Player position of this replay frame.
*/
position = 0;
/**
* Whether the player is in dashing state or not.
*/
isDashing = false;
/**
* Button actions of this replay frame.
*/
actions: Set<CatchAction> = new Set();
fromLegacy(
currentFrame: LegacyReplayFrame,
lastFrame: CatchReplayFrame | null,
): this {
this.startTime = currentFrame.startTime;
this.interval = currentFrame.interval;
this.position = currentFrame.position.x;
this.isDashing = currentFrame.buttonState === ReplayButtonState.Left1;
if (this.isDashing) {
this.actions.add(CatchAction.Dash);
}
/**
* This probably needs some cross-checking with osu-stable
* to ensure it is actually correct.
*/
if (lastFrame instanceof CatchReplayFrame) {
if (this.position > lastFrame.position) {
lastFrame.actions.add(CatchAction.MoveRight);
}
if (this.position < lastFrame.position) {
lastFrame.actions.add(CatchAction.MoveLeft);
}
}
return this;
}
toLegacy(): LegacyReplayFrame {
let state = ReplayButtonState.None;
if (this.actions.has(CatchAction.Dash)) {
state |= ReplayButtonState.Left1;
}
return new LegacyReplayFrame(
this.startTime,
this.interval,
new Vector2(this.position, 0),
state,
);
}
}