8000 Parse subtitles by vlnguyen · Pull Request #258 · noahm/simfile-parser · GitHub
[go: up one dir, main page]

Skip to content
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.9.0

- Exposed the subtitle tag in parsed results for better noCmod support (thanks Vincent!)

## v0.8.1

- Added support for parsing individual simfiles via HTMLInputElement selection in Firefox.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simfile-parser",
"version": "0.8.1",
"version": "0.9.0",
"description": "Read stepmania charts with javascript!",
"type": "module",
"main": "./dist/main.js",
Expand Down
61 changes: 61 additions & 0 deletions src/__tests__/parseSimfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ describe("parseSong", () => {
"maxBpm": 200,
"minBpm": 200,
"stopCount": 0,
"subtitle": {
"subtitleName": "",
"translitSubtitleName": null,
},
"title": {
"banner": "AFRONOVA.png",
"bg": "AFRONOVA-bg.png",
Expand Down Expand Up @@ -1434,6 +1438,10 @@ describe("parseSong", () => {
"maxBpm": 154,
"minBpm": 124,
"stopCount": 0,
"subtitle": {
"subtitleName": "",
"translitSubtitleName": null,
},
"title": {
"banner": "Silly Love.png",
"bg": "Silly Love-bg.png",
Expand Down Expand Up @@ -2795,6 +2803,10 @@ describe("parseSong", () => {
"maxBpm": 138,
"minBpm": 138,
"stopCount": 0,
"subtitle": {
"subtitleName": "",
"translitSubtitleName": null,
},
"title": {
"banner": "bn.png",
"bg": "bg.png",
Expand Down Expand Up @@ -3112,6 +3124,10 @@ describe("parseSong", () => {
"maxBpm": 205,
"minBpm": 150,
"stopCount": 0,
"subtitle": {
"subtitleName": "",
"translitSubtitleName": null,
},
"title": {
"banner": "bn.png",
"bg": "bg.png",
Expand Down Expand Up @@ -3544,6 +3560,10 @@ describe("parseSong", () => {
"maxBpm": 100,
"minBpm": 17,
"stopCount": 0,
"subtitle": {
"subtitleName": "",
"translitSubtitleName": null,
},
"title": {
"banner": "fracture-bn.png",
"bg": "fracture-bg.png",
Expand All @@ -3563,4 +3583,45 @@ describe("parseSong", () => {
scrubDataForSnapshot(simfile, false);
expect(simfile.title.titleName).toBe("[T07] Ants (No CMOD)");
});

test("songs with subtitle", () => {
const shoes = parseSong(
path.join(
packsRoot,
"Club Fantastic Season 1",
"Shoes (Club Fantastic Edit)",
),
)!;
expect(shoes.title.titleName).toBe("Shoes");
expect(shoes.subtitle).toEqual({
subtitleName: "(Club Fantastic Edit)",
translitSubtitleName: null,
});

const bossy = parseSong(
path.join(
packsRoot,
"Club Fantastic Season 2",
"BOSSY (Jorts Speedy Mix)",
),
)!;
expect(bossy.title.titleName).toBe("BOSSY");
expect(bossy.subtitle).toEqual({
subtitleName: "(Jorts Speedy Mix)",
translitSubtitleName: null,
});

const oceania = parseSong(
path.join(
packsRoot,
"Club Fantastic Season 2",
"Oceania 909 (T2KAZUYA Remix)",
),
)!;
expect(oceania.title.titleName).toBe("Oceania 909");
expect(oceania.subtitle).toEqual({
subtitleName: "(T2KAZUYA Remix)",
translitSubtitleName: null,
});
});
});
4 changes: 4 additions & 0 deletions src/browser/parseSong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ export async function parseSong(
titleDir: songDirOrFile.name,
...finalImages,
},
subtitle: {
subtitleName: rawStepchart.subtitle ?? "",
translitSubtitleName: rawStepchart.subtitletranslit ?? null,
},
minBpm,
maxBpm,
displayBpm,
Expand Down
4 changes: 4 additions & 0 deletions src/parseSong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export function parseSong(songDirPath: string): Simfile | null {
titleDir: songDirPath,
...guessImages(songDirPath, images),
},
subtitle: {
subtitleName: rawStepchart.subtitle ?? "",
translitSubtitleName: rawStepchart.subtitletranslit ?? null,
},
minBpm,
maxBpm,
displayBpm,
Expand Down
17 changes: 15 additions & 2 deletions src/parsers/parseSm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ import {
// Ref: https://github.com/stepmania/stepmania/wiki/sm

// eslint-disable-next-line jsdoc/require-jsdoc
function isMetaTag(tag: string): tag is "title" | "titletranslit" | "artist" {
return ["title", "titletranslit", "artist"].includes(tag);
function isMetaTag(
tag: string,
): tag is
| "title"
| "titletranslit"
| "subtitle"
| "subtitletranslit"
| "artist" {
return [
"title",
"titletranslit",
"subtitle",
"subtitletranslit",
"artist",
].includes(tag);
}
// eslint-disable-next-line jsdoc/require-jsdoc
function isImageTag(tag: string): tag is "banner" | "background" | "jacket" {
Expand Down
17 changes: 15 additions & 2 deletions src/parsers/parseSsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ import { findFirstNonEmptyMeasure } from "./parseSm.js";
// Ref: https://github.com/stepmania/stepmania/wiki/ssc

// eslint-disable-next-line jsdoc/require-jsdoc
function isMetaTag(tag: string): tag is "title" | "titletranslit" | "artist" {
return ["title", "titletranslit", "artist"].includes(tag);
function isMetaTag(
tag: string,
): tag is
| "title"
| "titletranslit"
| "subtitle"
| "subtitletranslit"
| "artist" {
return [
"title",
"titletranslit",
"subtitle",
"subtitletranslit",
"artist",
].includes(tag);
}
// eslint-disable-next-line jsdoc/require-jsdoc
function isImageTag(tag: string): tag is "banner" | "background" | "jacket" {
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import type { Simfile } from "../types.js";

export type RawSimfile = Omit<
Simfile,
"mix" | "title" | "minBpm" | "maxBpm"
"mix" | "title" | "subtitle" | "minBpm" | "maxBpm"
> & {
title: string;
titletranslit: string | null;
subtitle: string | undefined;
subtitletranslit: string | null;
displayBpm: string | undefined;
images: ParsedImages;
};
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface Stepchart {
export interface Simfile {
/** metadata about the song */
title: Title;
subtitle: Subtitle;
artist: string;
/** metadata about the song's parent pack */
pack: Pack;
Expand Down Expand Up @@ -102,3 +103,8 @@ export interface Title {
bg: string | null;
jacket: string | null;
}

export interface Subtitle {
subtitleName: string;
translitSubtitleName: string | null;
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"rootDir": "./src",
"outDir": "./dist/",
"types": ["node", "jest", "wicg-file-system-access"],
"lib": ["ES2022", "DOM"]
Expand Down
0