Skip to content

Commit fd7f7ce

Browse files
authored
Merge pull request #41 from KotRikD/fix-graph-background
Graph fixes and various adjustments
2 parents 57664c7 + 5a571cf commit fd7f7ce

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

packages/tosu/src/entities/BeatmapPpData/index.ts

+35-18
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ export class BeatmapPPData extends AbstractEntity {
122122
wLogger.debug(
123123
`maxPP -> ${this.currAttributes.maxThisPlayPP} pp -> ${pp} stars -> ${stars}`
124124
);
125-
const maxThisPlayPP =
126-
pp > this.currAttributes.maxThisPlayPP
127-
? pp
128-
: this.currAttributes.maxThisPlayPP;
125+
const maxThisPlayPP = Math.max(pp, this.currAttributes.maxThisPlayPP);
129126

130127
this.currAttributes = {
131128
...this.currAttributes,
@@ -143,9 +140,9 @@ export class BeatmapPPData extends AbstractEntity {
143140
}
144141

145142
updateBPM(commonBPM: number, minBPM: number, maxBPM: number) {
146-
this.commonBPM = commonBPM;
147-
this.minBPM = minBPM;
148-
this.maxBPM = maxBPM;
143+
this.commonBPM = Math.round(commonBPM);
144+
this.minBPM = Math.round(minBPM);
145+
this.maxBPM = Math.round(maxBPM);
149146
}
150147

151148
updateTimings(firstObj: number, full: number) {
@@ -227,25 +224,28 @@ export class BeatmapPPData extends AbstractEntity {
227224

228225
let oldStrains: number[] = [];
229226

230-
const offset: number = strains.sectionLength;
231-
232227
let lazerBeatmap: ParsedBeatmap;
233-
234228
try {
235229
const decoder = new BeatmapDecoder();
236230

237231
lazerBeatmap = await decoder.decodeFromPath(mapPath, {
238232
parseColours: false,
239233
parseDifficulty: false,
240234
parseEditor: false,
241-
parseEvents: false,
235+
parseEvents: true,
242236
parseGeneral: false,
243237
parseMetadata: false
244238
});
245239

246240
const { bpm, bpmMin, bpmMax } = lazerBeatmap;
247241

248-
this.updateBPM(bpm, bpmMin, bpmMax);
242+
menuData.BackgroundFilename =
243+
lazerBeatmap.events.backgroundPath || '';
244+
this.updateBPM(
245+
bpm * mapAttributes.clockRate,
246+
bpmMin * mapAttributes.clockRate,
247+
bpmMax * mapAttributes.clockRate
248+
);
249249

250250
const firstObj = Math.round(
251251
lazerBeatmap.hitObjects.at(0)?.startTime ?? 0
@@ -261,28 +261,45 @@ export class BeatmapPPData extends AbstractEntity {
261261
return;
262262
}
263263

264+
const offset = strains.sectionLength;
265+
const firstObj = this.timings.firstObj / mapAttributes.clockRate;
266+
const lastObj = this.timings.full / mapAttributes.clockRate;
267+
const graphLength = lastObj - firstObj;
268+
const mp3Length = menuData.MP3Length / mapAttributes.clockRate;
269+
264270
const beatmap_parse_time = performance.now();
265271
wLogger.debug(
266272
`(updateMapMetadata) Spend:${(
267273
beatmap_parse_time - calculation_time
268274
).toFixed(2)}ms on parsing beatmap`
269275
);
270276

271-
const LEFT_OFFSET = Math.floor(this.timings.firstObj / offset);
277+
const LEFT_OFFSET = Math.floor(firstObj / offset);
272278
const RIGHT_OFFSET =
273-
menuData.MP3Length > this.timings.full
274-
? Math.ceil((menuData.MP3Length - this.timings.full) / offset)
279+
mp3Length >= lastObj
280+
? Math.ceil((mp3Length - lastObj) / offset)
275281
: 0;
276282

277283
const updateWithOffset = (name: string, values: number[]) => {
278284
let data: number[] = [];
285+
let approximateTime =
286+
LEFT_OFFSET * offset +
287+
values.length * offset +
288+
RIGHT_OFFSET * offset;
279289

280290
if (Number.isFinite(LEFT_OFFSET) && LEFT_OFFSET > 0)
281291
data = Array(LEFT_OFFSET).fill(-100);
282292
data = data.concat(values);
283293
if (Number.isFinite(RIGHT_OFFSET) && RIGHT_OFFSET > 0)
284294
data = data.concat(Array(RIGHT_OFFSET).fill(-100));
285295

296+
const missingPoints =
297+
mp3Length >= approximateTime
298+
? Math.ceil((mp3Length - approximateTime) / offset)
299+
: 0;
300+
if (missingPoints > 0)
301+
data = data.concat(Array(missingPoints).fill(-100));
302+
286303
resultStrains.series.push({ name, data });
287304
};
288305

@@ -335,13 +352,13 @@ export class BeatmapPPData extends AbstractEntity {
335352
resultStrains.xaxis.push(i * offset);
336353
}
337354

338-
const amount = Math.ceil(this.timings.full / offset);
355+
const amount = Math.ceil(graphLength / offset);
339356
for (let i = 0; i < amount; i++) {
340-
resultStrains.xaxis.push(this.timings.firstObj + i * offset);
357+
resultStrains.xaxis.push(firstObj + i * offset);
341358
}
342359

343360
for (let i = 0; i < RIGHT_OFFSET; i++) {
344-
resultStrains.xaxis.push(this.timings.full + i * offset);
361+
resultStrains.xaxis.push(lastObj + i * offset);
345362
}
346363

347364
const end_time = performance.now();

packages/tosu/src/entities/MenuData/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ export class MenuData extends AbstractEntity {
9494
process.readInt(beatmapAddr + 0x64)
9595
);
9696
// // [[Beatmap] + 0x68]
97-
this.BackgroundFilename = process.readSharpString(
98-
process.readInt(beatmapAddr + 0x68)
99-
);
97+
// this.BackgroundFilename = process.readSharpString(
98+
// process.readInt(beatmapAddr + 0x68)
99+
// );
100100
// [[Beatmap] + 0x78]
101101
this.Folder = process.readSharpString(
102102
process.readInt(beatmapAddr + 0x78)

packages/tosu/src/objects/instanceManager/instanceManager.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { sleep } from '@tosu/common';
1+
import { sleep, wLogger } from '@tosu/common';
22
import { process_by_name } from '@tosu/find-process';
33

44
import { OsuInstance } from './osuInstance';
@@ -21,10 +21,9 @@ export class InstanceManager {
2121
delete this.osuInstances[pid];
2222
}
2323

24-
async runWatcher() {
25-
while (true) {
24+
private handleProcesses() {
25+
try {
2626
const osuProcesses = process_by_name('osu!.exe');
27-
2827
for (const process of osuProcesses || []) {
2928
if (process.pid in this.osuInstances) {
3029
// dont deploy not needed instances
@@ -48,6 +47,14 @@ export class InstanceManager {
4847
this.osuInstances[process.pid] = osuInstance;
4948
osuInstance.start();
5049
}
50+
} catch (error) {
51+
wLogger.error(error);
52+
}
53+
}
54+
55+
async runWatcher() {
56+
while (true) {
57+
this.handleProcesses();
5158

5259
await sleep(5000);
5360
}

packages/tosu/src/objects/instanceManager/osuInstance.ts

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export class OsuInstance {
264264
// Reset gameplay data on retry
265265
if (prevTime > allTimesData.PlayTime) {
266266
gamePlayData.init(true);
267+
beatmapPpData.resetCurrentAttributes();
267268
}
268269

269270
prevTime = allTimesData.PlayTime;

0 commit comments

Comments
 (0)