Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
fix: some sliders have a normal sampleset when the origin is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
maotovisk committed Jun 26, 2023
1 parent d9233d9 commit 49d408d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 37 deletions.
65 changes: 34 additions & 31 deletions src/copier/hitsounds/service/copy-circle-hitsounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,38 @@ import { HitSample, HitSound } from "osu-classes";
import { findNearestHitObject } from "../../utils";

export type CopyCircleHitsoundsParams = {
hitObject: StandardHitObject;
key: number;
hitsoundedBeatmap: StandardBeatmap;
clickableHitsoundObjects: HitsoundableTimeLineObject[];
options: Options;
};
hitObject: StandardHitObject;
key: number;
hitsoundedBeatmap: StandardBeatmap;
clickableHitsoundObjects: HitsoundableTimeLineObject[];
options: Options;
};

export const copyCircleHitsounds = ({
hitObject,
hitsoundedBeatmap,
clickableHitsoundObjects,
key,
options,
}: CopyCircleHitsoundsParams) => {
const clickableSound = findNearestHitObject({
hitsoundableTimeLineObject: clickableHitsoundObjects,
startTime: hitObject.startTime,
threshold: options.timingThreshold,
});

if (!clickableSound && options.overwriteNotDefined) {
hitsoundedBeatmap.hitObjects[key].samples = [new HitSample()];
hitsoundedBeatmap.hitObjects[key].hitSound = HitSound.None;
}

if (clickableSound) {
hitsoundedBeatmap.hitObjects[key].samples = clickableSound.HitSample;
hitsoundedBeatmap.hitObjects[key].hitSound = clickableSound.HitSound;
}

return;
};
hitObject,
hitsoundedBeatmap,
clickableHitsoundObjects,
key,
options,
}: CopyCircleHitsoundsParams) => {
const clickableSound = findNearestHitObject({
hitsoundableTimeLineObject: clickableHitsoundObjects,
startTime: hitObject.startTime,
threshold: options.timingThreshold,
});

if (!clickableSound && options.overwriteNotDefined) {
const newSample = new HitSample();
newSample.hitSound = HitSound[HitSound.None];

hitsoundedBeatmap.hitObjects[key].samples = [newSample];
hitsoundedBeatmap.hitObjects[key].hitSound = HitSound.None;
}

if (clickableSound) {
hitsoundedBeatmap.hitObjects[key].samples = clickableSound.HitSample;
hitsoundedBeatmap.hitObjects[key].hitSound = clickableSound.HitSound;
}

return;
};
17 changes: 14 additions & 3 deletions src/copier/hitsounds/service/copy-slider-hitsounds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { HitSample, HitSound } from "osu-classes";
import { SliderTail, type Slider, StandardBeatmap, SliderTick } from "osu-standard-stable";
import {
SliderTail,
type Slider,
StandardBeatmap,
SliderTick,
} from "osu-standard-stable";
import type { HitsoundableTimeLineObject, Options } from "src/copier/types";
import { findNearestHitObject } from "../../utils";

Expand Down Expand Up @@ -36,8 +41,11 @@ export const copySliderHitsounds = ({
});

if (!clickableSound && options.overwriteNotDefined) {
const newSample = new HitSample();
newSample.hitSound = HitSound[HitSound.None];

(hitsoundedBeatmap.hitObjects[key] as Slider).nodeSamples[key_ns] = [
new HitSample(),
newSample,
];
}
if (clickableSound) {
Expand All @@ -54,7 +62,10 @@ export const copySliderHitsounds = ({
});

if (!dragableSound && options.overwriteNotDefined) {
hitsoundedBeatmap.hitObjects[key].samples = [new HitSample()];
const newSample = new HitSample();
newSample.hitSound = HitSound[HitSound.None];

hitsoundedBeatmap.hitObjects[key].samples = [newSample];
hitsoundedBeatmap.hitObjects[key].hitSound = HitSound.None;
}

Expand Down
5 changes: 4 additions & 1 deletion src/copier/hitsounds/service/copy-spinner-hitsounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export const copySpinnerHitsounds = ({
});

if (!clickableSpinnerSound && options.overwriteNotDefined) {
hitsoundedBeatmap.hitObjects[key].samples = [new HitSample()];
const newSample = new HitSample();
newSample.hitSound = HitSound[HitSound.None];

hitsoundedBeatmap.hitObjects[key].samples = [newSample];
hitsoundedBeatmap.hitObjects[key].hitSound = HitSound.None;
}

Expand Down
30 changes: 28 additions & 2 deletions src/copier/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HitSound, type HitSample } from "osu-classes";
import { HitSound, HitSample, SampleSet } from "osu-classes";
import {
Circle,
Slider,
Expand All @@ -25,6 +25,7 @@ export const convertBeatmapToHitsoundableTimeLine = (
beatmap: StandardBeatmap
): HitsoundableTimeLineObject[] => {
let hitsoundableTimeLineObject = [];
console.log(beatmap.hitObjects);

beatmap.hitObjects.forEach((hitObject) => {
if (hitObject instanceof Circle) {
Expand All @@ -35,6 +36,20 @@ export const convertBeatmapToHitsoundableTimeLine = (
clickable: true,
});
} else if (hitObject instanceof Slider) {
// This is a temporary workaround for a bug with the parser library that we are using,
// which causes undefined hitsounds to be considered Normal hitsounds
// when the hit object is a slider.
if (
hitObject.samples.length == 1 &&
hitObject.samples[0].volume === 100 &&
hitObject.samples[0].sampleSet === SampleSet[SampleSet.Normal]
) {
const newSample = new HitSample();
newSample.sampleSet = SampleSet[SampleSet.None];

hitObject.samples = [newSample];
}

hitsoundableTimeLineObject.push({
startTime: hitObject.startTime,
HitSample: hitObject.samples,
Expand All @@ -46,7 +61,18 @@ export const convertBeatmapToHitsoundableTimeLine = (
(nestedHitObject) => !(nestedHitObject instanceof SliderTick)
);

(hitObject as Slider).nodeSamples.forEach((samples, key) => {
hitObject.nodeSamples.forEach((samples, key) => {
if (
samples.length == 1 &&
samples[0].volume === 100 &&
samples[0].sampleSet === SampleSet[SampleSet.Normal]
) {
const newSample = new HitSample();
newSample.sampleSet = SampleSet[SampleSet.None];

samples = [newSample];
}

hitsoundableTimeLineObject.push({
startTime:
nestedHitObjects[key] instanceof SliderTail
Expand Down

0 comments on commit 49d408d

Please sign in to comment.