From 65bbebcec1a7fdfef4cb970d801ecda14b7f6127 Mon Sep 17 00:00:00 2001 From: lchzh3473 Date: Fri, 24 Nov 2023 00:27:23 +0800 Subject: [PATCH] v0.3.0 --- package.json | 2 +- src/format.ts | 33 ++++++++++++++++++++++++++++++++- src/pec/index.ts | 23 +++++++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9792177..dbe57fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sim-phi/extends", - "version": "0.2.2", + "version": "0.3.0", "description": "Third-party chart format conversion functions for sim-phi.", "type": "module", "main": "dist/index.js", diff --git a/src/format.ts b/src/format.ts index b060718..0592934 100644 --- a/src/format.ts +++ b/src/format.ts @@ -52,4 +52,35 @@ export interface BetterMessage { name: string; message: string; target: string; -} \ No newline at end of file +} +export function normalizeSpeedEvents(events: SpeedEventPGS[]): void { + if (events.length) { + const maxEndTime = events.reduce((max, e) => Math.max(max, e.endTime), 0); + if (maxEndTime < 1e9) { + events.push({ + startTime: maxEndTime, + endTime: 1e9, + value: events[events.length - 1].value + }); + } + } else { + events.push({ startTime: 0, endTime: 1e9, value: 1 }); + } +} +export function normalizeLineEvents(events: JudgeLineEventPGS[]): void { + if (events.length) { + const maxEndTime = events.reduce((max, e) => Math.max(max, e.endTime), 0); + if (maxEndTime < 1e9) { + events.push({ + startTime: maxEndTime, + endTime: 1e9, + start: events[events.length - 1].start, + end: events[events.length - 1].end, + start2: events[events.length - 1].start2, + end2: events[events.length - 1].end2 + }); + } + } else { + events.push({ startTime: 0, endTime: 1e9, start: 0, end: 0, start2: 0, end2: 0 }); + } +} diff --git a/src/pec/index.ts b/src/pec/index.ts index 1d65801..61db5b1 100644 --- a/src/pec/index.ts +++ b/src/pec/index.ts @@ -1,9 +1,28 @@ import { parse as parse$ } from './pec2json'; import { parse as parseRPE$ } from './rpe2json'; import { readInfo as readInfo$ } from './readInfo'; +import { normalizeLineEvents, normalizeSpeedEvents } from '../format'; namespace PEC { - export const parse = parse$; - export const parseRPE = parseRPE$; + export function parse(pec: string, filename: string): ReturnType { + const result = parse$(pec, filename); + for (const line of result.data.judgeLineList) { + normalizeSpeedEvents(line.speedEvents); + normalizeLineEvents(line.judgeLineDisappearEvents); + normalizeLineEvents(line.judgeLineMoveEvents); + normalizeLineEvents(line.judgeLineRotateEvents); + } + return result; + } + export function parseRPE(pec: string, filename: string): ReturnType { + const result = parseRPE$(pec, filename); + for (const line of result.data.judgeLineList) { + normalizeSpeedEvents(line.speedEvents); + normalizeLineEvents(line.judgeLineDisappearEvents); + normalizeLineEvents(line.judgeLineMoveEvents); + normalizeLineEvents(line.judgeLineRotateEvents); + } + return result; + } export const readInfo = readInfo$; } export default PEC;