mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-30 02:48:01 +03:00
42 lines
971 B
JavaScript
42 lines
971 B
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const collections = fs.readdirSync(path.join(__dirname, "../collections"));
|
|
|
|
function ChartSort(a, b) {
|
|
if (a.songID !== b.songID) {
|
|
return a.songID - b.songID;
|
|
}
|
|
|
|
if (a.playtype !== b.playtype) {
|
|
return a.playtype.localeCompare(b.playtype);
|
|
}
|
|
|
|
if (a.difficulty !== b.difficulty) {
|
|
return a.difficulty.localeCompare(b.difficulty);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
function DeterministicCollectionSort() {
|
|
for (const collection of collections) {
|
|
const collPath = path.join(__dirname, "../collections", collection);
|
|
const content = JSON.parse(fs.readFileSync(collPath));
|
|
|
|
if (collection.startsWith("charts-")) {
|
|
content.sort(ChartSort);
|
|
}
|
|
if (collection.startsWith("songs-")) {
|
|
content.sort((a, b) => a.id - b.id);
|
|
}
|
|
|
|
fs.writeFileSync(collPath, JSON.stringify(content, null, "\t"));
|
|
}
|
|
}
|
|
|
|
if (require.main === module) {
|
|
DeterministicCollectionSort();
|
|
}
|
|
|
|
module.exports = DeterministicCollectionSort |