feat: predict_tja script

This commit is contained in:
2026-04-25 16:19:30 +09:00
parent df82515a33
commit 4f6ce49704
5 changed files with 201 additions and 38 deletions

View File

@@ -1,51 +1,45 @@
import tjaParser, { Bar, Branch, Course } from 'tja-parser'
export function parseTja(tja: string): Partial<Record<'oni' | 'edit', Course>> | null {
try {
const song = tjaParser.Song.parse(tja);
export function parseTja(tja: string): Partial<Record<'oni' | 'edit', Course>> {
const song = tjaParser.Song.parse(tja);
let oni: Course | undefined = undefined;
let edit: Course | undefined = undefined;
let oni: Course | undefined = undefined;
let edit: Course | undefined = undefined;
if (song.course?.oni) {
const noteGroups = song.course.oni.noteGroups;
oni = song.course.oni;
oni.noteGroups = []
if (song.course?.oni) {
const noteGroups = song.course.oni.noteGroups;
oni = song.course.oni;
oni.noteGroups = []
for (const noteGroup of noteGroups) {
if (noteGroup instanceof Bar) {
oni.pushNoteGroups(noteGroup)
}
else if (noteGroup instanceof Branch) {
const bar = noteGroup.master || noteGroup.advanced || noteGroup.normal;
if (bar) {
oni.pushNoteGroups(...bar)
}
for (const noteGroup of noteGroups) {
if (noteGroup instanceof Bar) {
oni.pushNoteGroups(noteGroup)
}
else if (noteGroup instanceof Branch) {
const bar = noteGroup.master || noteGroup.advanced || noteGroup.normal;
if (bar) {
oni.pushNoteGroups(...bar)
}
}
}
if (song.course?.edit) {
const noteGroups = song.course.edit.noteGroups;
edit = song.course.edit;
edit.noteGroups = []
}
if (song.course?.edit) {
const noteGroups = song.course.edit.noteGroups;
edit = song.course.edit;
edit.noteGroups = []
for (const noteGroup of noteGroups) {
if (noteGroup instanceof Bar) {
edit.pushNoteGroups(noteGroup)
}
else if (noteGroup instanceof Branch) {
const bar = noteGroup.master || noteGroup.advanced || noteGroup.normal;
if (bar) {
edit.pushNoteGroups(...bar)
}
for (const noteGroup of noteGroups) {
if (noteGroup instanceof Bar) {
edit.pushNoteGroups(noteGroup)
}
else if (noteGroup instanceof Branch) {
const bar = noteGroup.master || noteGroup.advanced || noteGroup.normal;
if (bar) {
edit.pushNoteGroups(...bar)
}
}
}
}
return { oni, edit }
}
catch (err){
console.error(err)
return null;
}
return { oni, edit }
}