Skip to content

Commit

Permalink
Merge pull request #5 from kionell/patch-1
Browse files Browse the repository at this point in the history
Some fixes
  • Loading branch information
Itsyuka authored Oct 1, 2020
2 parents b5992cf + 5e36fa8 commit 207f38b
Show file tree
Hide file tree
Showing 10 changed files with 808 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osu-bpdpc",
"version": "0.1.1",
"version": "0.2.2",
"description": "Osu beatmap parser, difficulty and performance calculator",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/Beatmap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default class Beatmap {
SampleSet: string;
StackLeniency: number;
Mode: number;
MinBPM: number;
MaxBPM: number;
LetterboxInBreaks: boolean;
WidescreenStoryboard: boolean;
};
Expand Down
42 changes: 38 additions & 4 deletions src/Beatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Colour = require("./Colour");
const Crunch = require("./Utils/OsuCruncher");
const HitType = require("./Enum/HitType");
const OsuHitObjectFactory = require("./Rulesets/Osu/HitObjectFactory");
const {SliderPath, PathControlPoint} = require("./Utils/SliderPath");

class Beatmap {
constructor() {
Expand Down Expand Up @@ -182,7 +183,8 @@ class Beatmap {
break;
case "OverallDifficulty":
beatmap[section][key] = parseFloat(value);
break;
key = "ApproachRate";
if (beatmap[section][key]) break;
case "ApproachRate":
beatmap[section][key] = parseFloat(value);
break;
Expand All @@ -204,7 +206,7 @@ class Beatmap {
hitType: parseInt(hitType, 10),
hitSound: parseInt(hitSound)
};
if (args[args.length - 1].includes(":")) {
if (args.length && args[args.length - 1].includes(":")) {
// some sliders don't use the extras
if (hitType & HitType.Hold) {
let [
Expand Down Expand Up @@ -252,7 +254,7 @@ class Beatmap {
repeat,
pixelLength,
edgeHitSounds,
edgeAdditions
edgeAdditions,
] = args;
let [type, ...curves] = curvyBits.split("|");
let curvePoints = curves
Expand All @@ -263,8 +265,32 @@ class Beatmap {
curveType: type,
curvePoints,
repeat: parseInt(repeat, 10),
pixelLength: parseInt(pixelLength, 10)
pixelLength: parseInt(pixelLength, 10),
};

hitObject.pathPoints = [new PathControlPoint(
new Vector2(0, 0), hitObject.curveType
)];

hitObject.curvePoints.forEach(x => {
let point = new PathControlPoint(x.subtract(hitObject.pos));

hitObject.pathPoints.push(point);
});

let sliderPath = new SliderPath(
hitObject.pathPoints, hitObject.pixelLength
);

let endPoint = sliderPath.positionAt(1);

if (endPoint && endPoint.x && endPoint.y) {
hitObject.endPos = hitObject.pos.add(endPoint);
} else {
// If endPosition could not be calculated, approximate it by setting it to the last point
hitObject.endPos = hitObject.curvePoints[hitObject.curvePoints.length - 1];
}

if (edgeHitSounds) {
hitObject.edgeHitSounds = edgeHitSounds
.split("|")
Expand All @@ -283,6 +309,7 @@ class Beatmap {
if (hitType & HitType.Spinner) {
hitObject = {
...hitObject,
endPos: hitObject.pos,
endTime: parseInt(args[0], 10)
};
}
Expand Down Expand Up @@ -337,6 +364,13 @@ class Beatmap {
for (const tp of beatmap.TimingPoints) {
if (!tp.inherited) parentPoint = tp;

let bpm = Math.round(60000 / tp.beatLength);

if (bpm > 0) {
beatmap.General.MinBPM = Math.min(beatmap.General.MinBPM, bpm) || bpm;
beatmap.General.MaxBPM = Math.max(beatmap.General.MaxBPM, bpm) || bpm;
}

for (let hitObject of beatmap.HitObjects.filter(
ho => ho.startTime >= tp.time
)) {
Expand Down
6 changes: 5 additions & 1 deletion src/Rulesets/Osu/Objects/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ const HitObject = require("./HitObject");

class Circle extends HitObject {
constructor(hitObject) {
super({ ...hitObject, endTime: hitObject.startTime });
super({
...hitObject,
endPos: hitObject.pos,
endTime: hitObject.startTime
});
}

toOsu() {
Expand Down
2 changes: 2 additions & 0 deletions src/Rulesets/Osu/Objects/HitObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const HitType = require("../../../Enum/HitType");
class HitObject {
constructor({
pos,
endPos,
startTime,
endTime,
hitType,
Expand All @@ -11,6 +12,7 @@ class HitObject {
combo = 1
}) {
this.pos = pos;
this.endPos = endPos;
this.startTime = startTime;
this.endTime = endTime;
this.hitType = hitType;
Expand Down
25 changes: 16 additions & 9 deletions src/Rulesets/Osu/Objects/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,26 @@ class Slider extends HitObject {

finalize(timingPoint, parentTimingPoint, beatmap) {
let velocityMultiplier = 1;
if (timingPoint.inherited && timingPoint.beatLength < 0)
let difficulty = beatmap.Difficulty;

if (!timingPoint.inherited && timingPoint.beatLength < 0) {
velocityMultiplier = -100 / timingPoint.beatLength;
let pixelsPerBeat =
beatmap.Difficulty.SliderMultiplier * 100 * velocityMultiplier;
}

let pixelsPerBeat = difficulty.SliderMultiplier * 100;

if (beatmap.Version >= 8) {
pixelsPerBeat *= velocityMultiplier;
}

let beats = (this.pixelLength * this.repeat) / pixelsPerBeat;
let duration = Math.ceil(
beats * parentTimingPoint ? parentTimingPoint.beatLength : 1
);
let parentBeatLength = parentTimingPoint ? parentTimingPoint.beatLength : 1;
let duration = Math.ceil(beats * parentBeatLength);

this.endTime = this.startTime + duration;
this.combo =
Math.ceil(
((beats - 0.01) / this.repeat) * beatmap.Difficulty.SliderTickRate
) - 1;
Math.ceil((beats - 0.1) / this.repeat * difficulty.SliderTickRate) - 1;

this.combo *= this.repeat;
this.combo += this.repeat + 1;
}
Expand Down
Loading

0 comments on commit 207f38b

Please sign in to comment.