-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathbsor.ts
More file actions
69 lines (63 loc) · 2.06 KB
/
Copy pathbsor.ts
File metadata and controls
69 lines (63 loc) · 2.06 KB
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
import type { FileData, FileFormat, FormatHandler } from "../FormatHandler.ts";
import { Replay } from "./bsor/replay.ts";
import { render } from "./bsor/renderer.ts";
import CommonFormats, { Category } from "src/CommonFormats.ts";
class bsorHandler implements FormatHandler {
public name: string = "bsor";
public supportedFormats: FileFormat[] = [
{
name: "Beat Saber Open Replay",
format: "bsor",
extension: "bsor",
mime: "application/x-bsor",
from: true,
to: false,
internal: "bsor",
category: Category.DATA,
lossless: false
},
CommonFormats.PNG.supported("png", false, true),
CommonFormats.JPEG.supported("jpeg", false, true),
CommonFormats.JSON.supported("json", false, true, true)
];
public ready: boolean = true;
async init() {
this.ready = true;
}
async doConvert (
inputFiles: FileData[],
inputFormat: FileFormat,
outputFormat: FileFormat
): Promise<FileData[]> {
let frameIndex = 0;
return (await Promise.all(inputFiles.map(async(file) => {
const replay = new Replay(file.bytes);
if(outputFormat.internal === "json") {
return [{
name: file.name.split(".").slice(0, -1).join(".") + ".json",
bytes: new TextEncoder().encode(JSON.stringify(replay))
}];
}
let outputs: FileData[] = [];
await new Promise<void>(resolve => {
render(replay, 640, 480,
async(renderer) => {
const bytes: Uint8Array = await new Promise((resolve, reject) => {
renderer.domElement.toBlob((blob) => {
if (!blob) return reject("Canvas output failed");
blob.arrayBuffer().then(buf => resolve(new Uint8Array(buf)));
}, outputFormat.mime);
});
outputs.push({
name: file.name.split(".")[0]+"_"+(frameIndex++)+"."+outputFormat.extension,
bytes: bytes
});
},
async() => resolve()
);
})
return outputs;
}))).flat();
}
}
export default bsorHandler;