diff --git a/typescript/common/src/utils/tachi-id.ts b/typescript/common/src/utils/tachi-id.ts index 4c6aa42b1..8bc20a22b 100644 --- a/typescript/common/src/utils/tachi-id.ts +++ b/typescript/common/src/utils/tachi-id.ts @@ -1,4 +1,4 @@ -function randomHex(byteLength: number): string { +export function randomHex(byteLength: number): string { const buf = new Uint8Array(byteLength); globalThis.crypto.getRandomValues(buf); diff --git a/typescript/seeds-scripts/rerunners/iidx/iidx-mdb-parse/merge-mdb.ts b/typescript/seeds-scripts/rerunners/iidx/iidx-mdb-parse/merge-mdb.ts index 198d4a99e..37041ebfe 100644 --- a/typescript/seeds-scripts/rerunners/iidx/iidx-mdb-parse/merge-mdb.ts +++ b/typescript/seeds-scripts/rerunners/iidx/iidx-mdb-parse/merge-mdb.ts @@ -3,18 +3,20 @@ import { Command } from "commander"; import fs from "fs"; import path from "path"; import { - type ChartDocument, + type SEEDS_ChartDocument, type Difficulties, type GamesForGroup, type integer, - LEGACY_GetGamePTConfig, - type SongDocument, + GetGameConfig, + type SEEDS_SongDocument, type Versions, } from "tachi-common"; import { CreateChartID, + CreateSongID, GetFreshSongIDGenerator, + randomHex, ReadCollection, WriteCollection, } from "../../../util"; @@ -46,7 +48,7 @@ const options = program.opts() as { version: Versions["iidx-sp"]; }; -const iidxConfig = LEGACY_GetGamePTConfig("iidx", "SP"); +const iidxConfig = GetGameConfig("iidx-sp"); if (!Object.keys(iidxConfig.versions).includes(options.version)) { throw new Error( @@ -62,9 +64,10 @@ if (options.index !== "0" && options.index !== "1") { throw new Error(`Expected an --index of 0 or 1. Got ${options.index}.`); } -const existingCharts: ChartDocument[] = ReadCollection("charts-iidx.json"); +const existingChartsSP: SEEDS_ChartDocument<"iidx-sp">[] = ReadCollection("charts-iidx-sp.json"); +const existingChartsDP: SEEDS_ChartDocument<"iidx-dp">[] = ReadCollection("charts-iidx-dp.json"); -const existingSongs: SongDocument<"iidx">[] = ReadCollection("songs-iidx.json"); +const existingSongs: SEEDS_SongDocument<"iidx">[] = ReadCollection("songs-iidx.json"); const blacklist = fs .readFileSync(path.join(__dirname, "blacklist.txt"), "utf-8") @@ -99,17 +102,17 @@ async function ParseIIDXMDB() { options.alwaysExtract, ); - const chartMap = new Map>(); - const songMap = new Map>(); - const songTitleMap = new Map>(); - const chartDiffMap = new Map>(); + const chartMap = new Map>(); + const songMap = new Map>(); + const songTitleMap = new Map>(); + const chartDiffMap = new Map>(); for (const song of existingSongs) { songMap.set(song.id, song); songTitleMap.set(song.title, song); } - for (const chart of existingCharts) { + for (const chart of [...existingChartsSP, ...existingChartsDP]) { // what, you thought this was easy? if (Array.isArray(chart.data.inGameID)) { for (const igid of chart.data.inGameID) { @@ -120,17 +123,27 @@ async function ParseIIDXMDB() { } } - for (const chart of existingCharts) { + for (const chart of existingChartsSP) { if (Array.isArray(chart.data.inGameID)) { for (const igid of chart.data.inGameID) { - chartDiffMap.set(`${igid}-${chart.playtype}-${chart.difficulty}`, chart); + chartDiffMap.set(`${igid}-SP-${chart.difficulty}`, chart); } } else { - chartDiffMap.set(`${chart.data.inGameID}-${chart.playtype}-${chart.difficulty}`, chart); + chartDiffMap.set(`${chart.data.inGameID}-SP-${chart.difficulty}`, chart); } } - const getFreeSongID = GetFreshSongIDGenerator("iidx"); + for (const chart of existingChartsDP) { + if (Array.isArray(chart.data.inGameID)) { + for (const igid of chart.data.inGameID) { + chartDiffMap.set(`${igid}-DP-${chart.difficulty}`, chart); + } + } else { + chartDiffMap.set(`${chart.data.inGameID}-DP-${chart.difficulty}`, chart); + } + } + + const getFreeLegacySongID = GetFreshSongIDGenerator("iidx"); for (const inp of mdbCharts) { if (isInBlacklist(`S${inp.songID}`)) { @@ -141,7 +154,7 @@ async function ParseIIDXMDB() { } const anySongIDMatch = chartMap.get(inp.songID); - let song: SongDocument<"iidx">; + let song: SEEDS_SongDocument<"iidx">; if (!anySongIDMatch) { // new song? @@ -168,8 +181,9 @@ async function ParseIIDXMDB() { searchTerms.push(inp.marquee); } - const tachiSong: SongDocument<"iidx"> = { - id: getFreeSongID(), + const tachiSong: SEEDS_SongDocument<"iidx"> = { + id: CreateSongID(), + legacySongID: getFreeLegacySongID(), artist: inp.artist, title: inp.title, data: { @@ -241,15 +255,13 @@ async function ParseIIDXMDB() { // otherwise, make new chart? const playtypeStr = diffName.split("-")[0] as "DP" | "SP"; - const game: GamesForGroup["iidx"] = playtypeStr === "SP" ? "iidx-sp" : "iidx-dp"; - const tachiChart: ChartDocument = { - game, - chartID: CreateChartID(), + const tachiChart: SEEDS_ChartDocument = { + id: CreateChartID(), + legacyChartID: randomHex(20), difficulty: diffName.split("-")[1] as Difficulties[GamesForGroup["iidx"]], level: level.toString(), levelNum: level, isPrimary: true, - playtype: playtypeStr, songID: song.id, versions: [options.version], @@ -265,7 +277,11 @@ async function ParseIIDXMDB() { }; log.info(`Inserting new chart ${inp.title} ${diffName}.`); - existingCharts.push(tachiChart); + if (playtypeStr === "SP") { + existingChartsSP.push(tachiChart); + } else { + existingChartsDP.push(tachiChart); + } } else { if (!notecount) { log.warn( @@ -304,7 +320,8 @@ async function ParseIIDXMDB() { } WriteCollection("songs-iidx.json", existingSongs); - WriteCollection("charts-iidx.json", existingCharts); + WriteCollection("charts-iidx-sp.json", existingChartsSP); + WriteCollection("charts-iidx-dp.json", existingChartsDP); } ParseIIDXMDB(); diff --git a/typescript/seeds-scripts/util.js b/typescript/seeds-scripts/util.js index 1600f11e8..9fd63d9a7 100644 --- a/typescript/seeds-scripts/util.js +++ b/typescript/seeds-scripts/util.js @@ -9,6 +9,7 @@ import { CreateQuestID, CreateSongID, CreateTableID, + randomHex, } from "tachi-common"; import DeterministicCollectionSort from "./sort-seeds.js"; @@ -135,4 +136,5 @@ export { CreateSongID, CreateTableID, GetSongCollectionGameGroup as GetSongCollectionGame, + randomHex, };