-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
236 lines (214 loc) · 9.97 KB
/
mod.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// deno-lint-ignore-file prefer-const
import { Arc, Bomb, Chain, Difficulty,Note,RawKeyframesAny, Wall } from "https://deno.land/x/remapper@3.1.2/src/mod.ts"
type option_animations = {
customEvents?: boolean
notes?: boolean
walls?: boolean
bombs?: boolean
arcs?: boolean
chains?: boolean
fakeNotes?: boolean
fakeBombs?: boolean
fakeWalls?: boolean
fakeChains?: boolean
}
type target = "Note" | "Wall" | "Bomb" | "Arc" | "Chain" | "FakeNote" | "FakeWall" | "FakeBomb" | "FakeChain"
type variant = Note[] | Wall[] | Bomb[] | Arc[] | Chain[]
type keyframeDefinition = [string, RawKeyframesAny | string]
// Identifiers | Custom Event: E_ , Note: N_ , Bomb: B_ , Wall: W_ , Arc: A_ , Chain: C_.
// Fake Identifiers: Note: FN_ , Bomb: FB_ , Wall: FW_ , Chain: FC_ .
// CustomEvents, Vanilla Objects (Notes/Walls/Bombs/Arcs/Chains)
export class Optimize {
private difficulty?: Difficulty;
private animations?: option_animations = {customEvents: true, bombs: true, notes: true, walls: true, arcs: true, fakeNotes: true, fakeBombs: true, fakeChains: true, fakeWalls: true, chains: true}
constructor(diff: Difficulty, settings?: option_animations) {
if(settings) {
this.animations = settings;
}
this.difficulty = diff;
if(this.animations) {
if(this.animations.customEvents) {
const events = diff.customEvents;
let keyframeSetIndex = 0;
events.forEach(baseEvent => {
let existingPoints: keyframeDefinition[] = [];
let baseProperties: keyframeDefinition[] = [];
Object.entries(baseEvent.data).forEach(x => {
if(x[0] == "track" || x[0] == "duration") return;
baseProperties.push(x);
})
Object.entries(diff.pointDefinitions).forEach(x=> {existingPoints.push(x)});
events.forEach(pairEvent => {
if(baseEvent.data == pairEvent.data) return; // So pairEvent foreach doesnt process the baseEvent
let pairProperties: keyframeDefinition[] = [];
Object.entries(pairEvent.data).forEach(x => {
if(x[0] == "track" || x[0] == "duration") return;
pairProperties.push(x);
})
pairProperties.forEach(pair => {
baseProperties.forEach(base => {
if(checkEqual(pair[1],base[1]) && pair[0] === base[0]) { // If the arrays/props are the same
let pointExists = 0;
existingPoints.forEach(point => {
if(checkEqual(point[1],pair[1])) { // If the keyframes are same to the pointdef, set the events keyframes to the pointDef.
baseEvent.data[base[0]] = point[0];
pairEvent.data[pair[0]] = point[0];
pointExists++
}
})
if(pointExists > 0) return;
if(typeof base[1] != "string") { // If it wasnt assigned a pointDef, create one.
diff.pointDefinitions[`E_${base[0]}_${keyframeSetIndex}`] = base[1];
existingPoints.push([`E_${base[0]}_${keyframeSetIndex}`,base[1]]);
baseEvent.data[base[0]] = `E_${base[0]}_${keyframeSetIndex}`
pairEvent.data[pair[0]] = `E_${base[0]}_${keyframeSetIndex}`
keyframeSetIndex++
}
}
})
})
})
})
}
if(this.animations.notes) {
this.joeBiden("Note")
}
if(this.animations.fakeNotes) {
this.joeBiden("FakeNote")
}
if(this.animations.bombs) {
this.joeBiden("Bomb")
}
if(this.animations.fakeBombs) {
this.joeBiden("FakeBomb")
}
if(this.animations.walls) {
this.joeBiden("Wall")
}
if(this.animations.fakeWalls){
this.joeBiden('FakeWall')
}
if(this.animations.chains) {
this.joeBiden("Chain")
}
if(this.animations.fakeChains) {
this.joeBiden("FakeChain")
}
if(this.animations.arcs) {
this.joeBiden("Arc")
}
}
}
private joeBiden(target: target) {
const diff = this.difficulty;
if(diff) {
let prefix: string = "NA";
let gObject: variant;
switch(target) {
case "Note":
gObject = diff.notes;
prefix = "N";
break;
case "FakeNote":
gObject = diff.fakeNotes;
prefix = "FN";
break;
case "Bomb":
gObject = diff.bombs;
prefix = "B";
break;
case "FakeBomb":
gObject = diff.fakeBombs;
prefix = "FB";
break;
case "Wall":
gObject = diff.walls;
prefix = "W";
break;
case "FakeWall":
gObject = diff.fakeWalls;
prefix = "FW";
break;
case "Chain":
gObject = diff.chains;
prefix = "C";
break;
case "FakeChain":
gObject = diff.fakeChains;
prefix = "FC";
break;
case "Arc":
gObject = diff.arcs;
prefix = "A";
break;
}
let keyframeSetIndex = 0;
if(gObject) {
gObject.forEach(baseObject => {
if(!baseObject.animation) return; // Dont do shit if the note doesnt have animation(s).
let existingPoints: keyframeDefinition[] = [];
let baseAnim: keyframeDefinition[] = [];
Object.entries(diff.pointDefinitions).forEach(x=> {existingPoints.push(x)});
Object.entries(baseObject.animation).forEach(x=> {
if(Array.isArray(x)) {
baseAnim.push([x[0],x[1] as RawKeyframesAny]);
}
})
gObject.forEach(pairObject => {
if(baseObject == pairObject || !baseObject.animation) return;
let pairAnim: keyframeDefinition[] = [];
Object.entries(pairObject.animation).forEach(x=> {
if(Array.isArray(x)) {
pairAnim.push([x[0],x[1] as RawKeyframesAny]);
}
})
pairAnim.forEach(pair => {
baseAnim.forEach(base => {
if(checkEqual(pair[1],base[1]) && pair[0] == base[0]) {
let pointExists = 0;
existingPoints.forEach(point => {
if(checkEqual(point[1],pair[1])) {
baseObject.animation[base[0]] = point[0];
pairObject.animation[pair[0]] = point[0];
pointExists++
}
})
if(pointExists > 0) return;
if(typeof base[1] != "string") {
diff.pointDefinitions[`${prefix}_${base[0]}_${keyframeSetIndex}`] = base[1];
existingPoints.push([`${prefix}_${base[0]}_${keyframeSetIndex}`,base[1]]);
baseObject.animation[base[0]] = `${prefix}_${base[0]}_${keyframeSetIndex}`
pairObject.animation[pair[0]] = `${prefix}_${base[0]}_${keyframeSetIndex}`
keyframeSetIndex++
}
}
})
})
})
})
}
}
}
}
function checkEqual(obj1: unknown, obj2: unknown): boolean { // Thanks swiffer
if (obj1 === null || obj2 === null) return obj1 === obj2
if (typeof obj1 !== typeof obj2) return false
if (typeof obj1 === "object") {
if (Array.isArray(obj1)) {
// array
const arr2 = obj2 as unknown[]
if (obj1.length !== arr2.length) return false
return obj1.every((x, i) => checkEqual(x, arr2[i]))
} else {
// object
const rec1 = obj1 as Record<string | symbol | number, unknown>
const rec2 = obj2 as Record<string | symbol | number, unknown>
if (Object.values(rec1).length !== Object.values(rec2).length) return false
if (!checkEqual(Object.keys(rec1), Object.keys(rec2))) return false
return Object.entries(rec1).every(([key, value]) => checkEqual(value, rec2[key as keyof typeof rec2]))
}
} else {
// number, boolean, string, undefined
return obj1 === obj2
}
}