Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brunohpaiva/osu-parser
A library to read and write osu files for Node.js
https://github.com/brunohpaiva/osu-parser
npm-package osu osu-libraries parser-library
Last synced: 18 days ago
JSON representation
A library to read and write osu files for Node.js
- Host: GitHub
- URL: https://github.com/brunohpaiva/osu-parser
- Owner: brunohpaiva
- License: mit
- Created: 2020-09-10T12:34:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-17T20:17:48.000Z (over 4 years ago)
- Last Synced: 2024-12-11T04:41:34.852Z (29 days ago)
- Topics: npm-package, osu, osu-libraries, parser-library
- Language: TypeScript
- Homepage: https://brunohpaiva.github.io/osu-parser
- Size: 370 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# osu-parser
[![npm version](https://img.shields.io/npm/v/@brunohpaiva/osu-parser.svg?style=flat)](https://www.npmjs.org/package/@brunohpaiva/osu-parser)
[![npm downloads](https://img.shields.io/npm/dm/@brunohpaiva/osu-parser.svg?style=flat)](http://npm-stat.com/charts.html?package=@brunohpaiva/osu-parser)
[![npm bundle size](https://img.shields.io/bundlephobia/min/@brunohpaiva/osu-parser?style=flat)](https://www.npmjs.org/package/@brunohpaiva/osu-parser)A library to read and write osu files for Node.js
## Installing
Using npm:
```bash
$ npm install @brunohpaiva/osu-parser
```Using yarn:
```bash
$ yarn add @brunohpaiva/osu-parser
```## Examples
#### Replay file (.osr)
Reading from a file
```ts
import { OsuReplay } from '@brunohpaiva/osu-parser';
import fs from 'fs';// Path of local .osr file
const filePath = './osu-replay-input.osr';
// Read file contents synchronously and stores it in a buffer
const buffer = fs.readFileSync(filePath);
// Parses the buffer to a OsuReplay
const replay = OsuReplay.parse(buffer);console.log(replay);
```Writing to a file
```ts
import { OsuReplay } from '@brunohpaiva/osu-parser';
import fs from 'fs';// Creates a new replay
const replay = new OsuReplay();// Set some data to it
replay.type = 0; // osu! standard
replay.gameVersion = 20200724;
replay.beatmapHash = 'hash';
replay.playerName = 'player';
replay.replayHash = 'hash';
replay.count300s = 100;
replay.count100s = 50;
replay.count50s = 25;
replay.countGekis = 0;
replay.countKatus = 5;
replay.countMisses = 1;
replay.totalScore = 1953902;
replay.greatestCombo = 328;
replay.perfectCombo = false;
replay.modsUsed = ['DoubleTime'];
replay.lifeBarGraph = 'lifeBar';
replay.windowsTicks = 637321042198407465n;
replay.actions = [
{
timestamp: 10, // Time in milliseconds since previous action
x: 10, // x coordinate from 0 to 512
y: 23, // y coordinate from 0 to 384
buttons: ['KeyboardOne'],
},
// More actions
];
replay.onlineScoreId = 98247527n;const osuBuffer = replay.writeToOsuBuffer();
const buffer = osuBuffer.buffer;// Path to store the generated .osr file
const filePath = './osu-replay-output.osr';
// Writes the buffer to a file synchronously
fs.writeFileSync(filePath, buffer);
```#### OsuBuffer
Reading and writing with a `OsuBuffer`
```ts
import { OsuBuffer } from '@brunohpaiva/osu-parser';// Initialize a empty buffer.
const osuBuffer = new OsuBuffer();
osuBuffer.writeInt(10);
osuBuffer.writeVarChar('A text');
osuBuffer.writeByte(5);console.log(osuBuffer.buffer);
// Output:console.log(osuBuffer.readInt());
// Output: 10console.log(osuBuffer.readVarChar());
// Output: A text
```