-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDataSet.ts
75 lines (63 loc) · 2.03 KB
/
createDataSet.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
import { EditAnimation, EditDataSet, EditProfile } from "./edit";
function addAnimations(
dataSet: EditDataSet,
animations: readonly Readonly<EditAnimation>[]
) {
const animStartIndex = dataSet.animations.length;
// Add animations and their child animations
for (const anim of animations) {
for (const a of anim.collectAnimations()) {
if (!dataSet.animations.includes(a)) {
dataSet.animations.push(a);
}
}
}
// Include all patterns used by the animations
const animEndIndex = dataSet.animations.length;
for (let i = animStartIndex; i < animEndIndex; ++i) {
const anim = dataSet.animations[i];
const { rgb, grayscale } = anim.collectPatterns();
if (grayscale) {
for (const p of grayscale) {
if (!dataSet.patterns.includes(p)) {
dataSet.patterns.push(p);
}
}
}
if (rgb) {
for (const p of rgb) {
if (!dataSet.rgbPatterns.includes(p)) {
dataSet.rgbPatterns.push(p);
}
}
}
}
}
export function createDataSetForAnimation(
animation: Readonly<EditAnimation>
): EditDataSet {
// The EditDataSet that will only contain the given animation and its patterns
const dataSet = new EditDataSet();
// Add the single animation we need
addAnimations(dataSet, [animation]);
return dataSet;
}
export function createDataSetForAnimations(
animations: readonly Readonly<EditAnimation>[]
): EditDataSet {
// The EditDataSet that will only contain the given animation and its patterns
const dataSet = new EditDataSet();
// Add animation list and their patterns to the data set
addAnimations(dataSet, animations);
return dataSet;
}
export function createDataSetForProfile(
profile: Readonly<EditProfile>,
brightnessFactor?: number
): EditDataSet {
const brightness = (brightnessFactor ?? 1) * profile.brightness;
const dataSet = new EditDataSet({ profile, brightness });
// Add the animations and patterns that the profile uses
addAnimations(dataSet, dataSet.profile.collectAnimations());
return dataSet;
}