@r2o3/rgchart-browser 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright © 2025 menvae
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,328 @@
1
+ # rgchart
2
+ A library for parsing and writing charts for various rhythm games. It supports cross-platform usage including Web and Node.js environments via WebAssembly (WASM).
3
+
4
+ ## Table of Contents
5
+
6
+ - [Rust Usage](#rust-usage)
7
+ - [Installation](#installation)
8
+ - [API Reference](#api-reference)
9
+ - [Parsing Charts](#parsing-charts)
10
+ - [Writing Charts](#writing-charts)
11
+ - [Chart Structure](#chart-structure)
12
+ - [JavaScript/TypeScript Usage](#javascripttypescript-usage)
13
+ - [Installation](#installation-1)
14
+ - [API Reference](#api-reference-1)
15
+ - [Initialization](#initialization)
16
+ - [Parsing Charts](#parsing-charts-1)
17
+ - [Writing Charts](#writing-charts-1)
18
+ - [TypeScript Types](#typescript-types)
19
+ - [Building](#building)
20
+ - [Rust Library](#rust-library)
21
+ - [WASM Bindings](#wasm-bindings)
22
+ - [License](#license)
23
+
24
+ ## Rust Usage
25
+
26
+ ### Installation
27
+ Add this to your `Cargo.toml`:
28
+ ```toml
29
+ [dependencies]
30
+ rgchart = "0.0.11"
31
+ ```
32
+
33
+ Or run:
34
+ ```sh
35
+ cargo add rgchart
36
+ ```
37
+
38
+ ### API Reference
39
+
40
+ #### Parsing Charts
41
+ ```rust
42
+ use rgchart::parse;
43
+
44
+ // Parse an osu! chart from string to a generic mania chart
45
+ let osu_chart = parse::from_osu_generic(raw_osu_string).expect("Failed to parse osu! chart");
46
+
47
+ // Parse a Stepmania chart from string to a generic mania chart
48
+ let sm_chart = parse::from_sm_generic(raw_sm_string).expect("Failed to parse Stepmania chart");
49
+
50
+ // Parse a Quaver chart from string to a generic mania chart
51
+ let qua_chart = parse::from_qua_generic(raw_qua_string).expect("Failed to parse Quaver chart");
52
+
53
+ // Parse a fluXis chart from string to a generic mania chart
54
+ let fsc_chart = parse::from_fsc_generic(raw_qua_string).expect("Failed to parse fluXis chart");
55
+ ```
56
+
57
+ to parse charts in their original structures:
58
+ ```rust
59
+ use rgchart::FscFile;
60
+ use rgchart::OsuFile;
61
+ use rgchart::QuaFile;
62
+
63
+ // Parse an osu! chart from string
64
+ let osu_chart = OsuFile::from_str(raw_osu_string).expect("Failed to parse osu! chart");
65
+
66
+ // Parse a Quaver chart from string
67
+ let qua_chart = QuaFile::from_str(raw_qua_string).expect("Failed to parse Quaver chart");
68
+
69
+ // Parse a fluXis chart from string
70
+ let fsc_chart = FscFile::from_str(raw_fsc_string).expect("Failed to parse fluXis chart");
71
+ ```
72
+
73
+ #### Writing Charts
74
+ ```rust
75
+ use rgchart::parse;
76
+ use rgchart::write;
77
+ use rgchart::GenericManiaChart;
78
+
79
+ let chart: GenericManiaChart = parse::from_osu_generic(raw_osu_string).expect("Failed to parse osu! chart");
80
+
81
+ // Write from generic mania chart to to osu! format
82
+ let osu_string = write::to_osu_generic(&chart);
83
+
84
+ // Write from generic mania chart to Stepmania format
85
+ let sm_string = write::to_sm_generic(&chart);
86
+
87
+ // Write from generic mania chart to Quaver format
88
+ let qua_string = write::to_qua_generic(&chart);
89
+
90
+ // Write from generic mania chart to fluXis format
91
+ let fsc_string = write::To_fsc_generic(&chart);
92
+ ```
93
+
94
+ to write charts from their original structures:
95
+ ```rust
96
+ use rgchart::FscFile;
97
+ use rgchart::OsuFile;
98
+ use rgchart::QuaFile;
99
+
100
+ // Write from OsuFile to to osu! format
101
+ let osu_string = osu_chart.to_osu_format_mania(soundbank);
102
+
103
+ // assuming you don't have a soundbank
104
+ let osu_string = osu_chart.to_osu_format_mania_no_soundbank();
105
+
106
+ // other modes for osu!, it will interprete the hit objects values as is for the mode you're writing to.
107
+ let osu_string = osu_chart.to_osu_format();
108
+ // or
109
+ let osu_string = osu_chart.to_osu_format_standard(soundbank);
110
+
111
+ let osu_string = osu_chart.to_osu_format_taiko(soundbank);
112
+ let osu_string = osu_chart.to_osu_format_catch(soundbank);
113
+
114
+ // Write from QuaFile to Quaver format
115
+ let qua_string = qua_chart.to_str().expect("Failed to write Quaver chart");
116
+
117
+ // Write from FscFile to fluXis format
118
+ let fsc_string = fsc_chart.to_str().expect("Failed to write fluXis chart");
119
+ ```
120
+
121
+ as of now you can't parse/write Sm files in their original structures.
122
+
123
+ #### Generic Mania Chart Structure
124
+ The `GenericManiaChart` contains all the relevant chart information:
125
+ ```rust
126
+ pub struct GenericManiaChart {
127
+ pub metadata: Metadata,
128
+ pub chartinfo: ChartInfo,
129
+ pub timing_points: TimingPoints,
130
+ pub hitobjects: HitObjects,
131
+ pub soundbank: Option<SoundBank>,
132
+ }
133
+ ```
134
+
135
+ The `Metadata` contains all the metadata related information about a specific chart, a lot of all of these can be empty:
136
+ ```rust
137
+ pub struct Metadata {
138
+ pub title: String,
139
+ pub alt_title: String,
140
+ pub artist: String,
141
+ pub alt_artist: String,
142
+ pub creator: String,
143
+ pub genre: String,
144
+ pub tags: Vec<String>,
145
+ pub source: String,
146
+ }
147
+ ```
148
+
149
+ The `ChartInfo` contains all the gameplay information about a specific chart:
150
+ ```rust
151
+ pub struct ChartInfo {
152
+ pub difficulty_name: String,
153
+ pub od: f32,
154
+ pub hp: f32,
155
+ pub bg_path: String,
156
+ pub video_path: String,
157
+ pub song_path: String,
158
+ pub audio_offset: i32,
159
+ pub preview_time: i32,
160
+ pub key_count: u8,
161
+ }
162
+ ```
163
+
164
+ The `TimingPoints` contains all the timing information such as bpm changes and sv:
165
+ ```rust
166
+ pub enum TimingChangeType {
167
+ Bpm,
168
+ Sv,
169
+ Stop
170
+ }
171
+
172
+ pub struct TimingChange {
173
+ pub change_type: TimingChangeType,
174
+ pub value: f32,
175
+ }
176
+
177
+ pub struct TimingPoint {
178
+ pub time: i32,
179
+ pub beat: f32,
180
+ pub change: TimingChange,
181
+ }
182
+
183
+ pub struct TimingPoints {
184
+ pub points: Vec<TimingPoint>,
185
+ }
186
+ ```
187
+
188
+ The `HitObjects` struct contains all the hitobject information:
189
+ ```rust
190
+ pub struct HitObject {
191
+ pub time: i32,
192
+ pub beat: f32,
193
+ pub keysound: KeySound,
194
+ pub key: Key,
195
+ pub lane: u8,
196
+ }
197
+
198
+ pub struct HitObjects {
199
+ pub objects: Vec<HitObject>,
200
+ }
201
+ ```
202
+
203
+ Here is how sounds are handled for Mania.
204
+ ``SoundBank`` contains all the sounds effects as well as a lookup for samples, it's done this way to be compatible with Quaver.
205
+ ```rust
206
+ pub enum HitSoundType {
207
+ Normal,
208
+ Clap,
209
+ Whistle,
210
+ Finish,
211
+ }
212
+
213
+ pub struct SoundEffect {
214
+ pub time: i32,
215
+ pub volume: u8,
216
+ pub sample: usize,
217
+ }
218
+ pub struct KeySound {
219
+ pub volume: u8,
220
+ pub hitsound_type: HitSoundType,
221
+ pub sample: Option<usize>,
222
+ pub has_custom: bool,
223
+ }
224
+
225
+ pub struct SoundBank {
226
+ pub audio_tracks: Vec<String>,
227
+ sound_sample_paths: Vec<String>,
228
+ pub sound_effects: Vec<SoundEffect>,
229
+ sample_map: HashMap<String, usize>,
230
+ }
231
+ ```
232
+
233
+ ## JavaScript/TypeScript Usage
234
+
235
+ ### Installation
236
+ For Node.js:
237
+ ```sh
238
+ npm install @r2o3/rgchart-nodejs
239
+ ```
240
+
241
+ For web projects:
242
+ ```html
243
+ <script src="https://unpkg.com/@r2o3/rgchart-browser@latest/rgchart.js"></script>
244
+ ```
245
+ or
246
+ ```javascript
247
+ npm install @r2o3/rgchart-browser
248
+ ```
249
+ then use as an ES module
250
+
251
+ ### API Reference
252
+
253
+ #### Initialization
254
+ ```javascript
255
+ // For ES modules
256
+ import * as rgchart from '@r2o3/rgchart'; // or if not on node use the path to rgchart.js
257
+
258
+ // or alternatively
259
+ const rgchart = await import('path/to/rgchart.js')
260
+
261
+ // For CommonJS
262
+ const rgchart = require('rgchart');
263
+ ```
264
+
265
+ you may need to do ``await rgchart.default()`` after importing if you've imported it in a script tag (with type="module") or you get an error like ``Uncaught TypeError: Cannot read properties of undefined (reading '__wbindgen_malloc')``
266
+
267
+ As of now you can't parse/write using the original structures in JS/TS, will be supported in the *near* future.
268
+
269
+ #### Parsing Charts
270
+ ```javascript
271
+ // Parse an osu! chart from string to a generic mania chart
272
+ const OsuChart = rgchart.parseFromOsuGeneric(rawOsuString);
273
+
274
+ // Parse a Stepmania chart from string to a generic mania chart
275
+ const SmChart = rgchart.parseFromSmGeneric(rawSmString);
276
+
277
+ // Parse a Quaver chart from string to a generic mania chart
278
+ const QuaChart = rgchart.parseFromQuaGeneric(rawQuaString);
279
+
280
+ // Parse a fluXis chart from string to a generic mania chart
281
+ const FscChart = rgchart.parseFromFscGeneric(rawFscString);
282
+ ```
283
+
284
+ #### Writing Charts
285
+ ```javascript
286
+ // write from generic mania chart to osu! format
287
+ const osuString = rgchart.writeToOsuGeneric(chart);
288
+
289
+ // write from generic mania chart to Stepmania format
290
+ const smString = rgchart.writeToSmGeneric(chart);
291
+
292
+ // write from generic mania chart to Quaver format
293
+ const quaString = rgchart.writeToQuaGeneric(chart);
294
+
295
+ // write from generic mania chart to fluXis format
296
+ const fscString = rgchart.writeToFscGeneric(chart);
297
+ ```
298
+
299
+ #### TypeScript Types
300
+ The core chart library is written in Rust, but *most* types in the WASM bindings are generated for TypeScript.
301
+
302
+ [See Chart Structure](#chart-structure).
303
+ ## Building
304
+
305
+ ### Rust Library
306
+ ```sh
307
+ cargo build
308
+ ```
309
+
310
+ ### WASM Bindings
311
+ 1. Install wasm-pack:
312
+ ```sh
313
+ cargo install wasm-pack
314
+ ```
315
+ > [!IMPORTANT]
316
+ > It's really recommended to have [wasm-opt](https://github.com/WebAssembly/binaryen) installed and added to path for the wasm build.
317
+
318
+ 2. Build the package:
319
+ ```sh
320
+ npm run build # debug build
321
+ npm run build-release # release build
322
+ ```
323
+
324
+ 3. This will build it for both node and browser and the output will be in `dist-web` and `dist-node` directory.
325
+
326
+ ## License
327
+ RGC uses the MIT License for all its sibiling projects.
328
+ See [LICENSE](https://github.com/menvae/rgchart/blob/master/LICENSE) for more information
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@r2o3/rgchart-browser",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "menvae <menvaedev@gmail.com>"
6
+ ],
7
+ "description": "A library for parsing and writing rhythm game charts.",
8
+ "version": "0.0.11",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/R2O3/rgchart"
13
+ },
14
+ "files": [
15
+ "rgchart_bg.wasm",
16
+ "rgchart.js",
17
+ "rgchart.d.ts"
18
+ ],
19
+ "main": "rgchart.js",
20
+ "types": "rgchart.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ],
24
+ "keywords": [
25
+ "wasm",
26
+ "rust",
27
+ "rhythm-game",
28
+ "osu",
29
+ "stepmania",
30
+ "parser",
31
+ "converter",
32
+ "writer"
33
+ ]
34
+ }