Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SDVX data, add flags for some filtering options, add filter by date option #260

Merged
merged 16 commits into from
Apr 25, 2024
Merged
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "node"
},
{
"type": "node",
"request": "launch",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"start": "webpack serve --env dev=true",
"build": "npm run validate && webpack",
"build": "webpack",
"build:zip": "npm run validate && webpack --env zip",
"deploy:surge": "surge ./surge-redirect https://ddrdraw.surge.sh",
"deploy:staging": "surge ./surge-redirect https://ddrdraw-staging.surge.sh",
Expand Down Expand Up @@ -42,6 +42,7 @@
"@babel/preset-env": "^7.24.4",
"@babel/preset-typescript": "^7.24",
"@blueprintjs/core": "^5.10.2",
"@blueprintjs/datetime2": "^2.3.4",
"@blueprintjs/icons": "^5.1.0",
"@blueprintjs/select": "^5.1.4",
"@lcdp/offline-plugin": "^5.0.7",
Expand All @@ -66,6 +67,7 @@
"cross-spawn": "^7.0.3",
"css-loader": "^7.1.1",
"css-minimizer-webpack-plugin": "^6.0.0",
"date-fns": "^2.28.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
Expand Down
69 changes: 59 additions & 10 deletions scripts/import-sdvx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@ import { promises as fs } from "fs";
import { resolve, join, dirname } from "path";
import { parseStringPromise } from "xml2js";
import iconv from "iconv-lite";
import { writeJsonData } from "./utils.mjs";
import { fileURLToPath } from "url";
import { writeJsonData } from "./utils.mjs";
import { SDVX_UNLOCK_IDS, UNPLAYABLE_IDS } from "./sdvx/unlocks.mjs";

const __dirname = dirname(fileURLToPath(import.meta.url));

/** @typedef {import("../src/models/SongData.js").Song} Song */
/** @typedef {import("../src/models/SongData.js").Chart} Chart */
/** @typedef {import("../src/models/SongData.js").GameData} GameData */

/**
* @template {Record<string, unknown>} T
* @param {T} object
* @returns {Array<keyof T>}
*/
function typedKeys(object) {
return Object.keys(object);
}

const OUTFILE = "src/songs/sdvx.json";
const JACKETS_PATH = "src/assets/jackets/sdvx";

Expand All @@ -32,8 +47,10 @@ async function main() {
console.log(`getting list of song jackets from ${JACKETS_PATH}`);
const availableJackets = new Set(await fs.readdir(JACKETS_PATH));

/** @type {GameData} */
const data = {
meta: {
menuParent: "more",
styles: ["single"],
difficulties: [
{ key: "novice", color: "#800080" },
Expand All @@ -46,7 +63,8 @@ async function main() {
{ key: "vivid", color: "#f52a6e" },
{ key: "exceed", color: "#0047AB" },
],
flags: [],
flags: typedKeys(SDVX_UNLOCK_IDS),
lastUpdated: Date.now(),
},
defaults: {
style: "single",
Expand Down Expand Up @@ -76,6 +94,10 @@ async function main() {
heavenly: "Heavenly",
vivid: "Vivid",
exceed: "Exceed",
omegaDimension: "Blaster Gate/Omega Dimension",
hexadiver: "Hexadiver",
otherEvents: "Time-limited & Other Events",
jpOnly: "J-Region Exclusive",
$abbr: {
novice: "NOV",
advanced: "ADV",
Expand Down Expand Up @@ -142,13 +164,7 @@ function determineDiffClass(song, chartType) {
}
}

const songIdsToSkip = new Set([
840, // Grace's Tutorial https://remywiki.com/GRACE-chan_no_chou~zetsu!!_GRAVITY_kouza_w
1219, // Maxima's Tutorial https://remywiki.com/Maxima_sensei_no_mankai!!_HEAVENLY_kouza
1259, // AUTOMATION PARADISE
1438, // AUTOMATION PARADISE, April Fools
1751, // EXCEEED GEAR April Fools https://remywiki.com/Exceed_kamen-chan_no_chotto_issen_wo_exceed_shita_EXCEED_kouza
]);
const songIdsToSkip = new Set(UNPLAYABLE_IDS);
function filterUnplayableSongs(song) {
return !songIdsToSkip.has(parseInt(song.$.id));
}
Expand All @@ -170,7 +186,23 @@ function determineChartJacket(chartType, song, availableJackets) {
return `sdvx/${jacketName}`;
}

/**
*
* @param {string} input in the format YYYYMMDD
* @returns date string with dash separators YYYY-MM-DD
*/
function reformatDate(input) {
return `${input.slice(0, 4)}-${input.slice(4, 6)}-${input.slice(-2)}`;
}

/**
*
* @param {*} song
* @param {*} availableJackets
* @returns {Song}
*/
function buildSong(song, availableJackets) {
const numericId = Number.parseInt(song.$.id, 10);
const info = song.info[0];

const bpmMax = info.bpm_max[0]._.slice(0, -2);
Expand All @@ -180,6 +212,7 @@ function buildSong(song, availableJackets) {
bpm = `${bpmMin}-${bpmMax}`;
}

/** @type {Array<Chart>} */
const charts = [];
let usesSharedJacket = false;
for (const chartType of Object.keys(song.difficulty[0])) {
Expand Down Expand Up @@ -207,16 +240,32 @@ function buildSong(song, availableJackets) {
charts.find((c) => c.diffClass === "novice").jacket = undefined;
}

return {
const flags = [];
for (const flag of typedKeys(SDVX_UNLOCK_IDS)) {
if (SDVX_UNLOCK_IDS[flag].includes(numericId)) {
flags.push(flag);
}
}

/** @type {Song} */
const ret = {
name: info.title_name[0],
search_hint: info.ascii[0],
date_added: reformatDate(info.distribution_date[0]._),
saHash: song.$.id,
artist: info.artist_name[0],
jacket: usesSharedJacket
? `sdvx/jk_${("000" + parseInt(song.$.id)).slice(-4)}_1_s.png`
: "sdvx6.png",
bpm,
charts,
};

if (flags.length) {
ret.flags = flags;
}

return ret;
}

main();
Loading