[chore] Add support for mapinfo v3 (which is essentially the same thing as version 2)

(cherry picked from commit 83f23c5c16)
This commit is contained in:
MathieuG-P
2024-11-04 17:09:15 +01:00
parent da40448ca1
commit 64ed9d24b1
5 changed files with 54 additions and 4 deletions
@@ -1,8 +1,9 @@
import { BsvMapCharacteristic, BsvMapDifficultyType } from "../beat-saver.model";
import { RawMapInfoDataV2 } from "./raw-map-info-v2.model";
import { RawMapInfoDataV3 } from "./raw-map-info-v3.model";
import { RawMapInfoDataV4 } from "./raw-map-info-v4.model";
export type AnyRawMapInfo = RawMapInfoDataV2 | RawMapInfoDataV4;
export type AnyRawMapInfo = RawMapInfoDataV2 | RawMapInfoDataV3 | RawMapInfoDataV4;
// interfaces/mapInfo.ts
export interface MapInfo {
@@ -1,7 +1,7 @@
import { BsvMapCharacteristic, BsvMapDifficultyType } from "../beat-saver.model";
export interface RawMapInfoDataV2 {
_version: string;
_version: `2.${number}.${number}`;
_songName: string;
_songSubName: string;
_songAuthorName: string;
@@ -0,0 +1,39 @@
import { SongDetailDiffCharactertistic, SongDiffName } from "../song-details-cache/song-details-cache.model";
export interface RawMapInfoDataV3 {
_version: `3.${number}.${number}`;
_songName: string;
_songSubName: string;
_songAuthorName: string;
_levelAuthorName: string;
_beatsPerMinute: number;
_songTimeOffset: number;
_shuffle: number;
_shufflePeriod: number;
_previewStartTime: number;
_previewDuration: number;
_songFilename: string;
_coverImageFilename: string;
_environmentName: string;
_environmentNames?: string[];
_allDirectionsEnvironmentName: string;
_difficultyBeatmapSets: RawDifficultySetV3[];
}
interface RawDifficultySetV3 {
_beatmapCharacteristicName: SongDetailDiffCharactertistic;
_difficultyBeatmaps: RawMapDifficultyV3[];
}
interface RawMapDifficultyV3 {
_difficulty: SongDiffName;
_difficultyRank: number;
_beatmapFilename: string;
_noteJumpMovementSpeed: number;
_noteJumpStartBeatOffset: number;
_beatmapColorSchemeIdx?: number;
_environmentNameIdx?: number;
_customData?: {
_difficultyLabel?: string;
}
}
@@ -2,7 +2,7 @@ import { BsvMapCharacteristic, BsvMapDifficultyType } from "../beat-saver.model"
// interfaces/version4.ts
export interface RawMapInfoDataV4 {
version: string;
version: `4.${number}.${number}`;
song: {
title: string;
subTitle: string;
+11 -1
View File
@@ -1,5 +1,6 @@
import { MapDifficulty, MapInfo, AnyRawMapInfo } from "shared/models/maps/info/map-info.model";
import { RawMapInfoDataV2 } from "shared/models/maps/info/raw-map-info-v2.model";
import { RawMapInfoDataV3 } from "shared/models/maps/info/raw-map-info-v3.model";
import { RawMapInfoDataV4 } from "shared/models/maps/info/raw-map-info-v4.model";
function parseVersion2(data: RawMapInfoDataV2): MapInfo {
@@ -34,6 +35,11 @@ function parseVersion2(data: RawMapInfoDataV2): MapInfo {
};
}
function parseVersion3(data: RawMapInfoDataV3): MapInfo {
// It's the same treatment as the version 2
return parseVersion2(data as unknown as RawMapInfoDataV2)
}
function parseVersion4(data: RawMapInfoDataV4): MapInfo {
return {
version: data.version,
@@ -64,7 +70,7 @@ function parseVersion4(data: RawMapInfoDataV4): MapInfo {
}
export function parseMapInfoDat(info: AnyRawMapInfo): MapInfo | never {
const version = (info as RawMapInfoDataV2)?._version || (info as RawMapInfoDataV4)?.version;
const version = (info as RawMapInfoDataV2)?._version || (info as RawMapInfoDataV3)?._version || (info as RawMapInfoDataV4)?.version;
if(!version) {
throw new Error('Cannot determine info.dat version');
@@ -74,6 +80,10 @@ export function parseMapInfoDat(info: AnyRawMapInfo): MapInfo | never {
return parseVersion2(info as RawMapInfoDataV2);
}
if (version.startsWith('3.')) {
return parseVersion3(info as RawMapInfoDataV3);
}
if (version.startsWith('4.')) {
return parseVersion4(info as RawMapInfoDataV4);
}