Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lchzh3473 committed Nov 23, 2023
1 parent 4cd85f9 commit 65bbebc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 32 additions & 1 deletion src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,35 @@ export interface BetterMessage {
name: string;
message: string;
target: string;
}
}
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 });
}
}
23 changes: 21 additions & 2 deletions src/pec/index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof parse$> {
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<typeof parseRPE$> {
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;

0 comments on commit 65bbebc

Please sign in to comment.