aboutsummaryrefslogtreecommitdiffstats
path: root/usc/seeds/nautica/add-usc-nautica.js
blob: d1a359eedb819565ea9fc629e0687b95267a240e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const { Command } = require("commander");
const sqlite3 = require("better-sqlite3");
const fs = require("fs");
const {
	CreateChartID,
	ReadCollection,
	WriteCollection,
	GetFreshSongIDGenerator,
} = require("../../util");

const program = new Command();
program.requiredOption("-d, --db <maps.db>");
program.requiredOption("-f, --filter <path_filter>");
program.option("--debug", "Show debug logs", false);
program.parse(process.argv);
const options = program.opts();

const DEBUG = options.debug;
const db = sqlite3(options.db);
const dbRows = db.prepare(`SELECT * FROM Charts WHERE path LIKE '%${options.filter}%'`).all();
console.log(`Found ${dbRows.length} charts.`);

const songs = ReadCollection("songs-usc.json");
const charts = ReadCollection("charts-usc.json");
const folderIdToSongId = {};

let newSongs = 0;
let newCharts = 0;

const getFreshSongID = GetFreshSongIDGenerator("usc");
const log = DEBUG ? console.log : () => undefined;

function makeUscEditionName(title, artist) {
	return `${title} (${artist} Nautica Edition)`;
}

for (const chart of dbRows) {
	// 1️⃣ Skip if chart already exists (same hash)
	const existingChart = charts.find((c) => c.data.hashSHA1 === chart.hash);
	if (existingChart) {
		log(
			`Chart ${chart.title} ${existingChart.difficulty} already exists (hash match, internalId=${chart.internalId}).`
		);
		continue;
	}

	// 2️⃣ Determine song
	if (!folderIdToSongId[chart.folderid]) {
		const splitPath = chart.path.replaceAll("\\", "/").split("/");
		const folderName = splitPath[splitPath.length - 2];

		const matchingSongs = songs.filter(
			(s) => s.title === chart.title && s.artist === chart.artist
		);

		let songID;
		if (matchingSongs.length === 0) {
			// normal song
			songID = getFreshSongID();
			songs.push({
				id: songID,
				title: chart.title,
				altTitles: [],
				artist: chart.artist,
				data: {},
				searchTerms: [folderName],
			});
			newSongs++;
			log(`Added song ${songID} for folder ${folderName}.`);
		} else {
			// duplicate name/artist → make USC Edition
			const effectorName = chart.effector ? chart.effector : "Unknown Effector";
			const uscTitle = makeUscEditionName(chart.title, effectorName);

			const existingUsc = songs.find((s) => s.title === uscTitle && s.artist === chart.artist);
			if (existingUsc) {
				songID = existingUsc.id;
				log(`Found existing USC edition song for ${chart.title}.`);
			} else {
				songID = getFreshSongID();
				songs.push({
					id: songID,
					title: uscTitle,
					altTitles: [chart.title],
					artist: chart.artist,
					data: {},
					searchTerms: [folderName],
				});
				newSongs++;
				log(`Duplicate name detected → created USC edition song ${uscTitle} (ID ${songID}).`);
			}
		}

		folderIdToSongId[chart.folderid] = songID;
	}

	const songID = folderIdToSongId[chart.folderid];

	// 3️⃣ Add charts, skip duplicates
	for (const playtype of ["Controller", "Keyboard"]) {
		const duplicate = charts.find(
			(c) =>
				c.songID === songID &&
				c.playtype === playtype &&
				c.difficulty === chart.diff_shortname &&
				c.isPrimary === true
		);

		if (duplicate) {
			log(
				`Skipped duplicate chart: ${chart.title} ${chart.diff_shortname} (${playtype}, songID=${songID}, internalId=${chart.internalId}).`
			);
			continue;
		}

		charts.push({
			chartID: CreateChartID(),
			data: {
				effector: chart.effector,
				hashSHA1: chart.hash,
				isOfficial: false,
				tableFolders: [],
			},
			difficulty: chart.diff_shortname,
			isPrimary: true,
			level: chart.level.toString(),
			levelNum: 0,
			playtype,
			songID,
			versions: [],
		});

		newCharts++;
		log(
			`Added chart ${chart.title} ${chart.diff_shortname} (${playtype}, internalId=${chart.internalId}).`
		);
	}
}

console.log(`Added ${newSongs} new songs and ${newCharts} new charts.`);

WriteCollection("songs-usc.json", songs);
WriteCollection("charts-usc.json", charts);
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage