first commit

This commit is contained in:
sim1222 2024-01-17 17:28:08 +09:00
commit 108146ce53
Signed by: sim1222
GPG Key ID: D1AE30E316E44E5D
10 changed files with 2699 additions and 0 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

20
.eslintrc.json Normal file
View File

@ -0,0 +1,20 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}

130
.gitignore vendored Normal file
View File

@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

11
.prettierrc.json Normal file
View File

@ -0,0 +1,11 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": true,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid"
}

29
package.json Normal file
View File

@ -0,0 +1,29 @@
{
"name": "sparebeat-osu-comverter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "tsx src/index.ts",
"dev": "tsx watch src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.2.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@types/node": "^20.11.4",
"@types/prompts": "^2.4.9",
"jszip": "^3.10.1",
"prompts": "^2.4.2",
"tsx": "^4.7.0"
}
}

1355
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

696
src/index.ts Normal file
View File

@ -0,0 +1,696 @@
import prompts from 'prompts';
import {
HitObject,
HitObjectType,
HitSoundType,
OsuFileFormat,
SampleSet,
SampleSetTimingPoint,
TimingPoint,
buildBeatmap,
maniaNote,
} from './osu/format';
import { SparebeatMap } from './sparebeat/format';
import fs from 'fs';
import JSZip from 'jszip';
const spmap: SparebeatMap = {
title: 'Kirakirize World',
artist: 'kooridori',
url: 'https://soundcloud.com/kooridori',
bgColor: ['#1F96E7', '#486AE7'],
bpm: 195,
startTime: 3660,
level: {
easy: 3,
normal: 6,
hard: 11,
},
map: {
easy: [
'23,,,,,,,,4,,,,,,,',
'1,,,,,,,,3,,,,,,,',
'2,,,,,,,,4,,,,,,,',
'1,,,,,,,,3,,,,,,,',
'1,,2,,3,,,,2,,3,,4,,,',
'3,,2,,1,,,,4,,3,,2,,,',
'1,,2,,3,,,,2,,3,,4,,,',
'1,,,,2,,,,d,,,,,,,',
'56h,,,3,,,2,,,,4,,3,,2,',
'1,,,2,,,3,,,,4,,3,,2,',
'1,,,3,,,2,,,,1,,2,,3,',
'4,,,3,,,2,,4,,3,,2,,1,',
'2,,,3,,,2,,,,4,,3,,2,',
'1,,,2,,,3,,,,4,,3,,2,',
'1,,,3,,,2,,,,1,,2,,3,',
'4,,,2,,,3,,4,,3,,2,,1,',
',,4,,3,,,,1,,b,,,,f3,',
'4,,3,,2,,1,,,,2,,3,,2,',
',,1,,2,,,,4,,c,,,,2g,',
'1,,2,,3,,4,,,,3,,2,,3,',
',,1,,2,,,,3,,2,,1,,2,',
',,4,,3,,,,1,,2,,3,,4,',
',,2,,3,,,,4,,3,,1,,2,',
'3,,,,4,,,,1,,2,,3,,,',
'12,,4,,3,,,,1,,b,,,,f3,',
'4,,3,,2,,1,,,,2,,3,,2,',
',,1,,2,,,,4,,c,,,,2g,',
'1,,2,,3,,4,,,,3,,2,,3,',
',,1,,2,,,,3,,2,,1,,2,',
',,4,,3,,,,1,,2,,3,,4,',
',,2,,3,,,,1,,2,,4,,3,',
'a,,,,,,ed,,,,,,1h,,2,',
'34,,,1,,,2,,,3,,,4,,,',
'23,,,4,,,3,,,2,,,1,,,',
'34,,,1,,,3,,,2,,,4,,,',
'23,,,4,,,3,,,1,,,2,,,',
'34,,,2,,,1,,,3,,,4,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,4,,,2,,,4,,,',
'2,,,3,,,2,,,1,,,4,,3,',
'12,,,3,,,1,,,2,,,4,,,',
'23,,,1,,,2,,,3,,,4,,,',
'12,,,3,,,4,,,1,,,2,,,',
'34,,,2,,,1,,,3,,,4,,,',
'12,,,,,,34,,,,,,12,,,',
',,23,,,,,,34,,,,12,,,',
'67,,,,,,,,,,,,,,,',
'23,,,34,,,a,,,,e2,,78,,,',
'12,,,,4,,3,,12,,34,,12,,34,',
'56,,3,,2,,d,,,,3h,,2,,1,',
'4,,3,2,1,,4,,3,,1,,2,,d,',
',,,,3h,,b,,,,,,f3,,,',
'1,2,3,,2,3,4,,1,,3,,2,,d,',
',,2h,,1,,b,,,,f3,,4,,,',
'12,,,34,,,12,,4,3,2,,1,,2,',
'34,,,12,,,34,,,,1,,78,,,',
'67,,,,4,,3,,1,2,3,,2,3,4,',
'1,,2,,3,,d,,,,3h,,2,,1,',
'4,,3,2,1,,4,,3,,2,,3,,a,',
',,e2,,4,,c,,,,,,2g,,,',
'34,,1,2,3,,2,3,4,,2,,1,2,3,',
'4,,,3,,,a,,,,,,e2,,,',
'34,,,12,,,34,,1,2,3,,2,3,4,',
'12,,,34,,,12,,4,3,2,,3,2,1,',
'34,,,12,,,23,,1,2,3,,2,3,4,',
'12,,,34,,,23,,,12,,,d,,,',
'3h,,,,2,,,,3,,1,2,78,,,',
'56,,,3,,,4,,,,3,2,1,,2,',
'34,,,1,,,2,,,,4,3,2,,4,',
'12,,,4,,,3,,,,1,2,3,,4,',
'23,,,4,,,1,,4,,3,2,1,,4,',
'12,,,34,,,2,,4,3,2,,1,,2,',
'34,,,12,,,3,,4,3,2,,1,,4,',
'12,,,34,,,2,,1,2,3,,4,,1,',
'23,,,1,,,2,,34,,,12,,,34,',
',,,,67,,,,,,,,,,,',
',,,,,,,,,,,,,,,',
],
hard: [
'23,,4,,,,4,,,,4,,,,4,',
'1,,3,,,,3,,,,3,,,,3,',
'2,,4,,,,4,,,,4,,,,4,',
'1,,3,,,,3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3,4,1,2,3,4,,2,1,3,4,1,2',
'34,,,23,,,a2,,,,,,e3,,4,3',
'12,,,23,,,34,,1,,3,2,4,3,2,1',
'34,,,12,,,23,,1,,4,3,2,1,4,3',
'12,,,34,,,23,,1,,3,4,2,1,4,3',
'12,,,34,,,23,,,12,,,cd,,,',
'12gh,,,,23,,,,34,,1,2,78,,,',
'56,,,3,2,,3,,,,4,3,1,,2,',
'34,,,2,3,,4,,,,3,2,1,,4,',
'12,,,3,4,,3,,,,1,2,3,,4,',
'23,,,4,3,,1,,4,,3,2,1,,4,',
'12,,,23,,,34,,1,2,4,3,1,,2,',
'34,,,23,,,12,,4,2,1,3,4,,3,',
'12,,,34,,,23,,4,3,1,2,3,,4,',
'23,,4,3,2,1,4,3,12,,,23,,,34,',
',,,,67,,,,,,,,,,,',
',,,,(1,2,4,3,2,1,),,,,,,,',
],
},
};
function sparebeatToOsu(sparebeatMap: SparebeatMap): OsuFileFormat[] {
const bpm = sparebeatMap.bpm;
const startTime = sparebeatMap.startTime;
const beats = sparebeatMap.beats ?? 4;
type SparebeatNote = {
time: number;
note?: string;
endTime?: number;
speed?: number;
barLine?: boolean;
};
return Object.keys(sparebeatMap.map).map(key => {
let timingPoints: TimingPoint[] = [
{
Time: startTime,
BeatLength: (1000 * 60) / bpm,
Meter: beats,
SampleSet: SampleSetTimingPoint.Default,
SampleIndex: 0,
Volume: 60,
Inherited: 1,
KiaiMode: 0,
},
];
const tempNotes: SparebeatNote[] = [];
let hitObjects: HitObject<any>[] = [];
sparebeatMap.map[key].forEach(
(
measure:
| string
| {
speed?: number;
barLine?: boolean;
},
measureI: number,
) => {
const measureOffset = startTime + measureI * ((60000 / bpm) * beats);
if (typeof measure === 'object') {
tempNotes.push({
time: measureOffset,
...measure,
});
return;
}
// console.log(measureOffset);
// beat group
measure.split(',').forEach((beat, beatI) => {
const beatOffset = measureOffset + beatI * (60000 / bpm / beats);
// 1/(beats * 4) group
const time = Math.floor(beatOffset);
beat.split('').forEach((note: string, noteI) => {
// note
if (note.includes('(') || note.includes(')')) {
return;
}
tempNotes.push({
time: time,
note: note,
});
return;
let collumIndex = 0;
if (note.match(/[a-d]/)) {
// long note start
collumIndex = note.charCodeAt(0) - 97;
// console.log(collumIndex);
const endnote = String.fromCharCode(note.charCodeAt(0) + 4);
// find next endnote through measure
let endTime = 0;
for (let i = beatI; i < measure.length; i++) {
if (measure[i] === endnote) {
endTime = Math.floor(measureOffset + (i - 6) * (60000 / bpm / beats));
break;
}
}
hitObjects.push(
maniaNote({
x: collumIndex,
time: time,
type: HitObjectType.ManiaHold,
hitSound: HitSoundType.Clap,
holdParams: [endTime],
HitSample: {
SampleSet: SampleSetTimingPoint.Default,
AdditionSet: 0,
CustomIndex: 0,
Volume: 0,
Filename: '',
},
}),
);
return;
} else if (note.match(/[e-h]/)) {
// long note end
collumIndex = note.charCodeAt(0) - 101;
return;
}
if (note > 4) {
collumIndex = note - 4;
} else {
collumIndex = note;
}
hitObjects.push(
maniaNote({
x: collumIndex,
time: time,
type: HitObjectType.Slider,
hitSound: HitSoundType.Clap,
holdParams: undefined,
HitSample: {
SampleSet: SampleSetTimingPoint.Default,
AdditionSet: 0,
CustomIndex: 0,
Volume: 0,
Filename: '',
},
}),
);
return;
});
});
},
);
// search for long notes and add endTime
tempNotes.forEach((note, i) => {
if (!note.note) return;
if (note.note.match(/[a-d]/)) {
// long note start
const endnote = String.fromCharCode(note.note.charCodeAt(0) + 4);
// find next endnote through measure
let endTime = 0;
for (let j = i; j < tempNotes.length; j++) {
if (tempNotes[j].note === endnote) {
endTime = tempNotes[j].time;
tempNotes.splice(j, 1);
break;
}
}
tempNotes[i].endTime = endTime;
}
});
tempNotes.forEach(note => {
if (note.note) {
if (note.endTime) {
hitObjects.push(
maniaNote({
x: note.note.charCodeAt(0) - 96,
time: note.time,
type: HitObjectType.ManiaHold,
hitSound: HitSoundType.Clap,
holdParams: [note.endTime],
HitSample: {
SampleSet: SampleSetTimingPoint.Default,
AdditionSet: 0,
CustomIndex: 0,
Volume: 0,
Filename: '',
},
}),
);
} else {
let x = Number(note.note);
if (x > 4) {
x -= 4;
}
hitObjects.push(
maniaNote({
x: x,
time: note.time,
type: HitObjectType.Slider,
hitSound: HitSoundType.Clap,
HitSample: {
SampleSet: SampleSetTimingPoint.Default,
AdditionSet: 0,
CustomIndex: 0,
Volume: 0,
Filename: '',
},
}),
);
}
}
});
hitObjects.forEach((hitObject, i) => {
// remove NaN x notes
if (isNaN(hitObject.X)) {
hitObjects.splice(i, 1);
}
});
// console.log(
// buildBeatmap({
// General: {
// AudioFilename: 'audio.mp3',
// AudioLeadIn: 0,
// PreviewTime: 0,
// Countdown: 0,
// SampleSet: SampleSet.Normal,
// StackLeniency: 0.7,
// Mode: 3, // mania
// LetterboxInBreaks: 0,
// SpecialStyle: 0,
// WidescreenStoryboard: 1,
// },
// Metadata: {
// Title: sparebeatMap.title,
// TitleUnicode: sparebeatMap.title,
// Artist: sparebeatMap.artist ?? '',
// ArtistUnicode: sparebeatMap.artist ?? '',
// Creator: 'converter',
// Version: key,
// Source: '',
// Tags: [],
// BeatmapID: '',
// BeatmapSetID: '',
// },
// Difficulty: {
// HPDrainRate: 7,
// CircleSize: 4,
// OverallDifficulty: 7,
// ApproachRate: 5,
// SliderMultiplier: 1.4,
// SliderTickRate: 1,
// },
// TimingPoints: timingPoints,
// HitObjects: hitObjects,
// }),
// );
return {
General: {
AudioFilename: 'audio.mp3',
AudioLeadIn: 0,
PreviewTime: 0,
Countdown: 0,
SampleSet: SampleSet.Normal,
StackLeniency: 0.7,
Mode: 3, // mania
LetterboxInBreaks: 0,
SpecialStyle: 0,
WidescreenStoryboard: 1,
},
Editor: {
DistanceSpacing: 1,
BeatDivisor: 3,
GridSize: 4,
TimelineZoom: 1,
},
Metadata: {
Title: sparebeatMap.title,
TitleUnicode: sparebeatMap.title,
Artist: sparebeatMap.artist ?? '',
ArtistUnicode: sparebeatMap.artist ?? '',
Creator: 'converter',
Version: key,
Source: '',
Tags: [],
BeatmapID: '0',
BeatmapSetID: '-1',
},
Difficulty: {
HPDrainRate: 7,
CircleSize: 4, // 4k
OverallDifficulty: 7,
ApproachRate: 5,
SliderMultiplier: 1.4,
SliderTickRate: 1,
},
TimingPoints: timingPoints,
HitObjects: hitObjects,
};
});
}
async function createOsz(maps: OsuFileFormat[], audio: ArrayBuffer) {
const zip = new JSZip();
zip.file('audio.mp3', audio);
maps.forEach((map, i) => {
zip.file(`${map.Metadata.Title}-${map.Metadata.Artist} [${map.Metadata.Version}].osu`, buildBeatmap(map));
});
const content = await zip.generateAsync({ type: 'uint8array' });
return {
content: content,
fileName: `${maps[0].Metadata.Title}-${maps[0].Metadata.Artist}.osz`,
};
}
(async () => {
const promptRes = await prompts({
type: 'text',
name: 'sparebeatMapUrl',
message: 'Enter the sparebeat map url',
validate: (input: string) => {
if (input.startsWith('https://sparebeat.com/play/') || input.startsWith('https://beta.sparebeat.com/play/')) {
return true;
}
return 'Invalid url';
},
});
// https://beta.sparebeat.com/play/17188236
const sparebeatMapId = promptRes.sparebeatMapUrl.split('/').pop();
const mapApiRes = await fetch(`https://beta.sparebeat.com/api/tracks/${sparebeatMapId}/map`).then(
res => res.json() as Promise<SparebeatMap>,
);
const audioApiRes = await fetch(`https://beta.sparebeat.com/api/tracks/${sparebeatMapId}/audio`).then(res =>
res.arrayBuffer(),
);
const osuMaps = sparebeatToOsu(mapApiRes);
const osz = await createOsz(osuMaps, audioApiRes);
fs.writeFileSync(osz.fileName, Buffer.from(osz.content));
})();

303
src/osu/format.ts Normal file
View File

@ -0,0 +1,303 @@
export const header = 'osu file format v14';
export enum SampleSet {
Normal = 'Normal',
Soft = 'Soft',
Drum = 'Drum',
}
export enum SampleSetTimingPoint {
Default = 0,
Normal = 1,
Soft = 2,
Drum = 3,
}
export type TimingPoint = {
Time: number;
BeatLength: number;
Meter: number;
SampleSet: SampleSetTimingPoint;
SampleIndex: number;
Volume: number;
Inherited: 1 | 0;
KiaiMode: 1 | 0;
};
export enum HitObjectType {
Circle = 0,
Slider = 1,
NewCombo = 2,
Spinner = 3,
ComboSkip1 = 4,
ComboSkip2 = 5,
ComboSkip3 = 6,
ManiaHold = 128,
}
export enum HitSoundType {
Normal = 0,
Whistle = 2,
Finish = 4,
Clap = 8,
}
export type ManiaHoldObjectParams = [number];
export type HitSample = {
SampleSet: SampleSetTimingPoint;
AdditionSet: number;
CustomIndex: number;
Volume: number;
Filename: string;
};
export type HitObject<T> = {
X: number;
Y: number;
Time: number;
Type: HitObjectType;
HitSound: number;
ObjectParams?: T;
HitSample?: HitSample;
};
export type BeatmapGeneralData = {
AudioFilename: string;
AudioLeadIn: number;
PreviewTime: number;
Countdown: number;
SampleSet: SampleSet;
StackLeniency: number;
Mode: number;
LetterboxInBreaks: number;
SpecialStyle: number;
WidescreenStoryboard: number;
};
export type BeatmapMetadata = {
Title: string;
TitleUnicode: string;
Artist: string;
ArtistUnicode: string;
Creator: string;
Version: string;
Source: string;
Tags: string[];
BeatmapID: string;
BeatmapSetID: string;
};
export type BeatmapDifficulty = {
HPDrainRate: number;
CircleSize: number;
OverallDifficulty: number;
ApproachRate: number;
SliderMultiplier: number;
SliderTickRate: number;
};
export type EditorData = {
DistanceSpacing: number;
BeatDivisor: number;
GridSize: number;
TimelineZoom: number;
};
export type OsuFileFormat = {
General: BeatmapGeneralData;
Editor: EditorData;
Metadata: BeatmapMetadata;
Difficulty: BeatmapDifficulty;
// Events: {};
TimingPoints: TimingPoint[];
HitObjects: HitObject<any>[];
};
export function maniaNote({
x,
time,
type,
hitSound,
holdParams,
HitSample,
}: {
x: number;
time: number;
type: HitObjectType;
hitSound: HitSoundType;
holdParams?: ManiaHoldObjectParams;
HitSample?: HitSample;
}): HitObject<ManiaHoldObjectParams> {
if (holdParams) {
return {
X: Math.floor((512 / 4) * x) - 64,
Y: 192,
Time: time,
Type: type,
HitSound: hitSound,
// ObjectParams: holdParams,
HitSample: {
HoldTime: holdParams[0],
...HitSample
},
};
} else {
return {
X: Math.floor((512 / 4) * x) - 64,
Y: 192,
Time: time,
Type: type,
HitSound: hitSound,
HitSample: HitSample,
};
}
}
function addString(target: string, value: string) {
return (target += value + '\n');
}
export function parseBeatmap(beatmap: string): OsuFileFormat {
if (!beatmap.startsWith(header)) {
throw new Error('Invalid beatmap format');
}
function parseMetadatas(s: string) {
const result: any = {};
const lines = s.split('\n').filter(line => line.length > 0);
lines.forEach(line => {
const [key, value] = line.split(':');
if (key === 'Tags') {
result[key] = value.split(' ');
} else {
result[key] = value;
}
});
return result;
}
function parseHitObjects(s: string) {
const result: HitObject<any>[] = [];
const lines = s.split('\n').filter(line => line.length > 0);
lines.forEach(line => {
const [x, y, time, type, hitSound, ...params] = line.split(',');
const hitObject: HitObject<any> = {
X: parseInt(x, 10),
Y: parseInt(y, 10),
Time: parseInt(time, 10),
Type: parseInt(type, 10),
HitSound: parseInt(hitSound, 10),
ObjectParams: params,
};
result.push(hitObject);
});
return result;
}
function parseTimingPoints(s: string) {
const result: TimingPoint[] = [];
const lines = s.split('\n').filter(line => line.length > 0);
lines.forEach(line => {
const [time, beatLength, meter, sampleSet, sampleIndex, volume, inherited, kiaiMode] = line.split(',');
const timingPoint: TimingPoint = {
Time: parseFloat(time),
BeatLength: parseFloat(beatLength),
Meter: parseInt(meter, 10),
SampleSet: sampleSet as SampleSet,
SampleIndex: parseInt(sampleIndex, 10),
Volume: parseInt(volume, 10),
Inherited: parseInt(inherited, 10) as 1 | 0,
KiaiMode: parseInt(kiaiMode, 10) as 1 | 0,
};
result.push(timingPoint);
});
return result;
}
function sectionExtractor(section: string) {
const start = beatmap.indexOf('[' + section + ']');
const end = beatmap.substring(start + section.length + 2).match(/\n\[.*\]/)?.index + start + section.length + 2;
return beatmap.substring(start, end);
}
const generalStr = sectionExtractor('General');
const metadataStr = sectionExtractor('Metadata');
const difficultyStr = sectionExtractor('Difficulty');
const timingPointsStr = sectionExtractor('TimingPoints');
const hitObjectsStr = sectionExtractor('HitObjects');
const result: OsuFileFormat = {
General: parseMetadatas(generalStr),
Metadata: parseMetadatas(metadataStr),
Difficulty: parseMetadatas(difficultyStr),
TimingPoints: parseTimingPoints(timingPointsStr),
HitObjects: parseHitObjects(hitObjectsStr),
};
return result;
}
export function buildBeatmap(data: OsuFileFormat): string {
let beatmap = '';
beatmap = addString(beatmap, header + '\n');
Object.keys(data).forEach(key => {
beatmap = addString(beatmap, '[' + key + ']');
if (Array.isArray(data[key as keyof OsuFileFormat])) {
// TimingPoints[] | HitObject<any>[]
if (key === 'TimingPoints') {
data[key as keyof OsuFileFormat].forEach((timingPoint: TimingPoint) => {
beatmap = addString(
beatmap,
`${Object.keys(timingPoint)
.map(k => {
if (k === 'SampleSet') {
return timingPoint[k as keyof TimingPoint].toString();
}
return timingPoint[k as keyof TimingPoint].toString();
})
.join(',')}`,
);
});
} else if (key === 'HitObjects') {
data[key as keyof OsuFileFormat].forEach((hitObject: HitObject<any>) => {
// console.log(hitObject);
beatmap = addString(
beatmap,
`${Object.keys(hitObject)
.map(k => {
if (k === 'ObjectParams') {
// console.log(hitObject[k as keyof HitObject<any>].map((param: any) => param.toString()).join(':'));
return hitObject[k as keyof HitObject<any>].map((param: any) => param.toString()).join(':');
}
if (k === 'HitSample') {
return Object.keys(hitObject[k as keyof HitObject<any>]) // HitSample
.map((k2: string) => {
return hitObject[k as keyof HitObject<any>][k2 as keyof HitSample].toString();
})
.join(':');
}
return hitObject[k as keyof HitObject<any>]?.toString();
})
.join(',')}`,
);
});
}
} else if (key === 'Metadata') {
Object.keys(data[key as keyof OsuFileFormat]).forEach(k => {
if (k === 'Tags') {
beatmap = addString(beatmap, k + ':' + data[key][k].join(' '));
} else {
beatmap = addString(beatmap, k + ':' + data[key][k]);
}
});
} else {
Object.keys(data[key as keyof OsuFileFormat]).forEach(k => {
beatmap = addString(beatmap, k + ':' + data[key][k]);
});
}
beatmap = addString(beatmap, '');
});
// console.log(beatmap);
return beatmap;
}

37
src/sparebeat/format.ts Normal file
View File

@ -0,0 +1,37 @@
export type SparebeatMap = {
title: string;
artist?: string;
url?: string;
bgColor?: `#${string}`[];
beats?: number;
bpm: number;
startTime: number;
level: {
easy?: number;
normal?: number;
hard?: number;
};
map: {
easy?: (
| string
| {
speed?: number;
barLine?: boolean;
}
)[];
normal?: (
| string
| {
speed?: number;
barLine?: boolean;
}
)[];
hard?: (
| string
| {
speed?: number;
barLine?: boolean;
}
)[];
};
};

109
tsconfig.json Normal file
View File

@ -0,0 +1,109 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"rootDir": "src", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}