Skip to content

Commit

Permalink
Update osu! dependencies and its usages
Browse files Browse the repository at this point in the history
  • Loading branch information
Rian8337 committed Oct 18, 2024
1 parent 3f26ed2 commit 6c2ad1a
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 328 deletions.
185 changes: 93 additions & 92 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions src/events/messageCreate/utils/userBeatmapCalculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import { MessageCreator } from "@alice-utils/creators/MessageCreator";
import { BeatmapDifficultyHelper } from "@alice-utils/helpers/BeatmapDifficultyHelper";
import { StringHelper } from "@alice-utils/helpers/StringHelper";
import { BeatmapManager } from "@alice-utils/managers/BeatmapManager";
import { Message, EmbedBuilder, bold, underscore } from "discord.js";
import {
MapInfo,
Modes,
calculateOsuDifficultyStatistics,
} from "@rian8337/osu-base";
import { Message, EmbedBuilder, bold, underline } from "discord.js";
import { MapInfo, Modes, ModUtil } from "@rian8337/osu-base";
import { UserBeatmapCalculationLocalization } from "@alice-localization/events/messageCreate/userBeatmapCalculation/UserBeatmapCalculationLocalization";
import { CommandHelper } from "@alice-utils/helpers/CommandHelper";
import { DPPProcessorRESTManager } from "@alice-utils/managers/DPPProcessorRESTManager";
Expand Down Expand Up @@ -175,13 +171,10 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
embedOptions.files = [];

const embed = EmbedBuilder.from(embedOptions.embeds![0]);
const { mods, customSpeedMultiplier } = calcParams;

const difficultyStatisticsCalculatorOptions =
calcParams.toDifficultyStatisticsCalculatorOptions();

const speedMultiplier = calculateOsuDifficultyStatistics(
difficultyStatisticsCalculatorOptions,
).overallSpeedMultiplier;
const speedMultiplier =
ModUtil.calculateRateWithMods(mods) * customSpeedMultiplier;

embed
.spliceFields(0, embed.data.fields!.length)
Expand All @@ -195,7 +188,8 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
`${BeatmapManager.showStatistics(
firstBeatmap,
1,
difficultyStatisticsCalculatorOptions,
mods,
customSpeedMultiplier,
)}\n` +
`${bold("BPM")}: ${BeatmapManager.convertBPM(
firstBeatmap.bpm,
Expand Down Expand Up @@ -233,7 +227,7 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
}

embed.addFields({
name: `${underscore(
name: `${underline(
beatmapInfo.version,
)} (${droidDiffAttribs.attributes.starRating.toFixed(2)} ${
Symbols.star
Expand All @@ -244,17 +238,20 @@ export const run: EventUtil["run"] = async (_, message: Message) => {
`${BeatmapManager.showStatistics(
beatmapInfo,
2,
difficultyStatisticsCalculatorOptions,
mods,
customSpeedMultiplier,
)}\n` +
`${BeatmapManager.showStatistics(
beatmapInfo,
3,
difficultyStatisticsCalculatorOptions,
mods,
customSpeedMultiplier,
)}\n` +
`${BeatmapManager.showStatistics(
beatmapInfo,
4,
difficultyStatisticsCalculatorOptions,
mods,
customSpeedMultiplier,
)}\n` +
`${bold(
droidDiffAttribs.attributes.starRating.toFixed(2),
Expand Down
4 changes: 4 additions & 0 deletions src/interactions/commands/Bot Creators/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const run: SlashCommand["run"] = async (client, interaction) => {
ApplicationCommandType.ChatInput)
);

if (type === ApplicationCommandType.PrimaryEntryPoint) {
return;
}

if (type === ApplicationCommandType.ChatInput) {
const command = client.interactions.chatInput.get(commandName);

Expand Down
44 changes: 27 additions & 17 deletions src/interactions/commands/osu! and osu!droid/simulate/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BeatmapManager } from "@alice-utils/managers/BeatmapManager";
import { DPPProcessorRESTManager } from "@alice-utils/managers/DPPProcessorRESTManager";
import {
Accuracy,
calculateDroidDifficultyStatistics,
BeatmapDifficulty,
Circle,
DroidHitWindow,
IModApplicableToDroid,
Expand Down Expand Up @@ -332,27 +332,37 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
// This will be used when comparing accuracy against hit result, as the result was rounded down
// to the nearest integer, making some hits look like they should receive a 300 but instead they
// receive a 100. The same can be applied for 100 and 50.
const realOD = calculateDroidDifficultyStatistics({
overallDifficulty: beatmap.od,
// Do not apply speed-changing mods as they will affect the hit window.
mods: ModUtil.removeSpeedChangingMods(realMods),
convertOverallDifficulty: false,
}).overallDifficulty;

const realHitWindow = new DroidHitWindow(realOD);
const realDifficulty = new BeatmapDifficulty();
realDifficulty.od = beatmap.od;

ModUtil.applyModsToBeatmapDifficulty(
realDifficulty,
Modes.droid,
realMods,
realSpeedMultiplier,
false,
realOldStatistics,
);

const realHitWindow = new DroidHitWindow(realDifficulty.od);
const realIsPrecise = realMods.some((m) => m instanceof ModPrecise);

const realHitWindow300 = realHitWindow.hitWindowFor300(realIsPrecise);
const realHitWindow100 = realHitWindow.hitWindowFor100(realIsPrecise);

const simulatedOD = calculateDroidDifficultyStatistics({
overallDifficulty: beatmap.od,
// Do not apply speed-changing mods as they will affect the hit window and required spinner rotations.
mods: ModUtil.removeSpeedChangingMods(simulatedMods),
convertOverallDifficulty: false,
}).overallDifficulty;
const simulatedDifficulty = new BeatmapDifficulty();
simulatedDifficulty.od = beatmap.od;

ModUtil.applyModsToBeatmapDifficulty(
simulatedDifficulty,
Modes.droid,
simulatedMods,
simulatedSpeedMultiplier,
false,
realOldStatistics,
);

const simulatedHitWindow = new DroidHitWindow(simulatedOD);
const simulatedHitWindow = new DroidHitWindow(simulatedDifficulty.od);
const simulatedIsPrecise = simulatedMods.some(
(m) => m instanceof ModPrecise,
);
Expand All @@ -364,7 +374,7 @@ export const run: SlashCommand["run"] = async (_, interaction) => {
const simulatedHitWindow50 =
simulatedHitWindow.hitWindowFor50(simulatedIsPrecise);

const spinnerRotationsNeeded = 2 + (2 * simulatedOD) / 10;
const spinnerRotationsNeeded = 2 + (2 * simulatedDifficulty.od) / 10;

const addSliderNestedResult = (
object: SliderNestedHitObject,
Expand Down
44 changes: 29 additions & 15 deletions src/utils/creators/EmbedCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,33 @@ export abstract class EmbedCreator {
});

const totalDifficulty = beatmapInfo.totalDifficulty ?? 0;
const diffStatOptions =
calculationParams?.toDifficultyStatisticsCalculatorOptions();

embed
.setAuthor({
name: localization.getTranslation("beatmapInfo"),
iconURL: `attachment://osu-${totalDifficulty.toFixed(2)}.png`,
})
.setTitle(
BeatmapManager.showStatistics(beatmapInfo, 0, diffStatOptions),
BeatmapManager.showStatistics(
beatmapInfo,
0,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
),
)
.setDescription(
BeatmapManager.showStatistics(beatmapInfo, 1, diffStatOptions) +
BeatmapManager.showStatistics(
beatmapInfo,
1,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
) +
"\n" +
BeatmapManager.showStatistics(
beatmapInfo,
2,
diffStatOptions,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
),
)
.setURL(beatmapInfo.beatmapLink)
Expand All @@ -172,7 +181,8 @@ export abstract class EmbedCreator {
value: BeatmapManager.showStatistics(
beatmapInfo,
3,
diffStatOptions,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
),
},
{
Expand All @@ -182,7 +192,8 @@ export abstract class EmbedCreator {
value: BeatmapManager.showStatistics(
beatmapInfo,
4,
diffStatOptions,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
),
},
{
Expand All @@ -192,19 +203,22 @@ export abstract class EmbedCreator {
value: BeatmapManager.showStatistics(
beatmapInfo,
5,
diffStatOptions,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
),
},
{
name: BeatmapManager.showStatistics(
beatmapInfo,
6,
diffStatOptions,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
),
value: BeatmapManager.showStatistics(
beatmapInfo,
7,
diffStatOptions,
calculationParams?.mods,
calculationParams?.customSpeedMultiplier,
),
},
{
Expand Down Expand Up @@ -370,9 +384,7 @@ export abstract class EmbedCreator {
...calculationParams.accuracy,
nobjects: beatmap.objects,
});
const { accuracy } = calculationParams;
const diffStatOptions =
calculationParams.toDifficultyStatisticsCalculatorOptions();
const { accuracy, mods, customSpeedMultiplier } = calculationParams;

embed
.setColor(
Expand All @@ -388,12 +400,14 @@ export abstract class EmbedCreator {
name: BeatmapManager.showStatistics(
beatmap,
6,
diffStatOptions,
mods,
customSpeedMultiplier,
),
value: `${BeatmapManager.showStatistics(
beatmap,
7,
diffStatOptions,
mods,
customSpeedMultiplier,
)}\n${bold(
`${localization.getTranslation("result")}`,
)}: ${combo}/${droidDiffAttribs.maxCombo}x | ${(
Expand Down
21 changes: 1 addition & 20 deletions src/utils/dpp/DifficultyCalculationParameters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { CloneableDifficultyCalculationParameters } from "@alice-structures/dpp/CloneableDifficultyCalculationParameters";
import {
DifficultyStatisticsCalculatorOptions,
Mod,
ModDifficultyAdjust,
ModUtil,
} from "@rian8337/osu-base";
import { Mod, ModDifficultyAdjust, ModUtil } from "@rian8337/osu-base";
import {
DifficultyCalculationOptions,
DroidDifficultyCalculationOptions,
Expand Down Expand Up @@ -163,20 +158,6 @@ export class DifficultyCalculationParameters {
};
}

/**
* Converts this parameter to a `DifficultyStatisticsCalculatorOptions`.
*/
toDifficultyStatisticsCalculatorOptions(): DifficultyStatisticsCalculatorOptions {
return {
circleSize: this.forceCS,
approachRate: this.forceAR,
overallDifficulty: this.forceOD,
healthDrain: this.forceHP,
mods: this.mods,
customSpeedMultiplier: this.customSpeedMultiplier,
};
}

/**
* Converts any force difficulty statistics (CS, AR, OD, and HP) if they are present to a `ModDifficultyAdjust`.
*/
Expand Down
Loading

0 comments on commit 6c2ad1a

Please sign in to comment.