@rel-packages/osu-beatmap-parser 0.1.7 → 0.1.9
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/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare function get_property(location: string, key: OsuKey): string;
|
|
|
3
3
|
export declare function get_properties(input: string | OsuInput, keys: OsuKey[]): Record<OsuKey, string> & {
|
|
4
4
|
id?: string;
|
|
5
5
|
};
|
|
6
|
-
export declare function process_beatmaps(inputs: (string | OsuInput)[], keys: OsuKey[]): Promise<(Record<OsuKey, string> & {
|
|
6
|
+
export declare function process_beatmaps(inputs: (string | OsuInput)[], keys: OsuKey[], update_fn?: (index: number) => void): Promise<(Record<OsuKey, string> & {
|
|
7
7
|
id?: string;
|
|
8
8
|
})[]>;
|
|
9
9
|
export declare function get_duration(location: string): number;
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,9 @@ exports.get_properties = get_properties;
|
|
|
8
8
|
exports.process_beatmaps = process_beatmaps;
|
|
9
9
|
exports.get_duration = get_duration;
|
|
10
10
|
exports.get_audio_duration = get_audio_duration;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const node_gyp_build_1 = __importDefault(require("node-gyp-build"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const native = (0, node_gyp_build_1.default)(path_1.default.join(__dirname, ".."));
|
|
13
14
|
function get_property(location, key) {
|
|
14
15
|
return native.get_property(location, key);
|
|
15
16
|
}
|
|
@@ -23,9 +24,9 @@ function get_properties(input, keys) {
|
|
|
23
24
|
return result;
|
|
24
25
|
}
|
|
25
26
|
;
|
|
26
|
-
async function process_beatmaps(inputs, keys) {
|
|
27
|
+
async function process_beatmaps(inputs, keys, update_fn) {
|
|
27
28
|
const locations = inputs.map(i => typeof i === "string" ? i : i.path);
|
|
28
|
-
const results = await native.process_beatmaps(locations, keys);
|
|
29
|
+
const results = await native.process_beatmaps(locations, keys, update_fn);
|
|
29
30
|
return results.map((res, i) => {
|
|
30
31
|
const input = inputs[i];
|
|
31
32
|
if (typeof input !== "string" && input.id) {
|
package/dist/types.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface OsuInput {
|
|
|
6
6
|
export interface INativeExporter {
|
|
7
7
|
get_property(location: string, key: string): string;
|
|
8
8
|
get_properties(location: string, keys: string[]): Record<string, string>;
|
|
9
|
-
process_beatmaps(locations: string[], keys: string[]): Promise<Record<string, string>[]>;
|
|
9
|
+
process_beatmaps(locations: string[], keys: string[], callback?: (index: number) => void): Promise<Record<string, string>[]>;
|
|
10
10
|
get_duration(location: string): number;
|
|
11
11
|
get_audio_duration(location: string): number;
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rel-packages/osu-beatmap-parser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": ".osu parser for nodejs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"homepage": "https://github.com/mezleca/osu-beatmap-parser",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"install": "prebuild-install || npm run compile",
|
|
10
9
|
"dev": "npm run compile:native && tsx scripts/verify.ts",
|
|
11
10
|
"compile": "npm run compile:native && npm run compile:tsc",
|
|
12
11
|
"compile:tsc": "tsc",
|
|
@@ -19,24 +18,16 @@
|
|
|
19
18
|
"repository": {
|
|
20
19
|
"url": "https://github.com/mezleca/osu-beatmap-parser.git"
|
|
21
20
|
},
|
|
22
|
-
"binary": {
|
|
23
|
-
"module_name": "osu-beatmap-parser",
|
|
24
|
-
"module_path": "./build/Release/",
|
|
25
|
-
"host": "https://github.com/mezleca/osu-beatmap-parser/releases/download/",
|
|
26
|
-
"remote_path": "{version}"
|
|
27
|
-
},
|
|
28
21
|
"type": "commonjs",
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"bindings": "^1.5.0",
|
|
31
|
-
"prebuild-install": "^7.1.2"
|
|
32
|
-
},
|
|
33
22
|
"devDependencies": {
|
|
34
23
|
"@types/bindings": "^1.5.5",
|
|
35
24
|
"@types/node": "^24.10.1",
|
|
36
25
|
"cmake-js": "^7.4.0",
|
|
37
26
|
"node-addon-api": "^8.5.0",
|
|
38
|
-
"prebuild": "^13.0.1",
|
|
39
27
|
"tsx": "^4.21.0",
|
|
40
28
|
"typescript": "^5.9.3"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"node-gyp-build": "^4.8.4"
|
|
41
32
|
}
|
|
42
33
|
}
|
|
Binary file
|
|
Binary file
|
package/src/native/addon.cpp
CHANGED
|
@@ -92,7 +92,14 @@ Napi::Value ParserAddon::get_properties(const Napi::CallbackInfo& info) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
return obj;
|
|
95
|
-
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
struct CallbackContext {
|
|
98
|
+
Napi::ThreadSafeFunction tsfn;
|
|
99
|
+
std::atomic<size_t> current_index = 0;
|
|
100
|
+
|
|
101
|
+
CallbackContext() {}
|
|
102
|
+
};
|
|
96
103
|
|
|
97
104
|
struct BatchContext {
|
|
98
105
|
std::vector<std::string> paths;
|
|
@@ -100,6 +107,7 @@ struct BatchContext {
|
|
|
100
107
|
std::vector<std::unordered_map<std::string, std::string>> results;
|
|
101
108
|
std::atomic<size_t> completed_count{0};
|
|
102
109
|
Napi::ThreadSafeFunction tsfn;
|
|
110
|
+
CallbackContext *callback_ctx;
|
|
103
111
|
Napi::Promise::Deferred deferred;
|
|
104
112
|
bool needs_duration = false;
|
|
105
113
|
|
|
@@ -107,6 +115,8 @@ struct BatchContext {
|
|
|
107
115
|
};
|
|
108
116
|
|
|
109
117
|
void process_chunk(BatchContext* context, size_t start, size_t end) {
|
|
118
|
+
auto callback_ctx = context->callback_ctx;
|
|
119
|
+
|
|
110
120
|
for (size_t i = start; i < end; i++) {
|
|
111
121
|
std::string content = read_file(context->paths[i]);
|
|
112
122
|
if (!content.empty()) {
|
|
@@ -120,13 +130,30 @@ void process_chunk(BatchContext* context, size_t start, size_t end) {
|
|
|
120
130
|
context->results[i]["Duration"] = std::to_string(duration);
|
|
121
131
|
}
|
|
122
132
|
}
|
|
133
|
+
|
|
134
|
+
// only increment and call if file was actually processed
|
|
135
|
+
if (callback_ctx != nullptr) {
|
|
136
|
+
size_t current = callback_ctx->current_index.fetch_add(1) + 1;
|
|
137
|
+
callback_ctx->tsfn.NonBlockingCall([current](Napi::Env env, Napi::Function js_callback) {
|
|
138
|
+
js_callback.Call({
|
|
139
|
+
Napi::Number::New(env, static_cast<double>(current))
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
123
143
|
}
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
size_t completed = context->completed_count.fetch_add(end - start) + (end - start);
|
|
127
147
|
|
|
148
|
+
// last thread to finish resolves
|
|
128
149
|
if (completed == context->paths.size()) {
|
|
129
|
-
|
|
150
|
+
// release callback
|
|
151
|
+
if (context->callback_ctx != nullptr) {
|
|
152
|
+
context->callback_ctx->tsfn.Release();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// then resolve the promise
|
|
156
|
+
context->tsfn.BlockingCall([context](Napi::Env env, Napi::Function) {
|
|
130
157
|
Napi::Array result_array = Napi::Array::New(env, context->results.size());
|
|
131
158
|
|
|
132
159
|
for (size_t i = 0; i < context->results.size(); i++) {
|
|
@@ -138,9 +165,8 @@ void process_chunk(BatchContext* context, size_t start, size_t end) {
|
|
|
138
165
|
}
|
|
139
166
|
|
|
140
167
|
context->deferred.Resolve(result_array);
|
|
141
|
-
};
|
|
168
|
+
});
|
|
142
169
|
|
|
143
|
-
context->tsfn.BlockingCall(callback);
|
|
144
170
|
context->tsfn.Release();
|
|
145
171
|
}
|
|
146
172
|
}
|
|
@@ -171,8 +197,27 @@ Napi::Value ParserAddon::process_beatmaps(const Napi::CallbackInfo& info) {
|
|
|
171
197
|
}
|
|
172
198
|
}
|
|
173
199
|
|
|
200
|
+
if (info[2].IsFunction()) {
|
|
201
|
+
Napi::Function callback_fn = info[2].As<Napi::Function>();
|
|
202
|
+
auto callback_ctx = new CallbackContext();
|
|
203
|
+
|
|
204
|
+
callback_ctx = new CallbackContext();
|
|
205
|
+
callback_ctx->tsfn = Napi::ThreadSafeFunction::New(
|
|
206
|
+
callback_fn.Env(),
|
|
207
|
+
callback_fn,
|
|
208
|
+
"ProcessBeatmapsUpdate",
|
|
209
|
+
0,
|
|
210
|
+
1,
|
|
211
|
+
[callback_ctx](Napi::Env) {
|
|
212
|
+
delete callback_ctx;
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
context->callback_ctx = callback_ctx;
|
|
217
|
+
}
|
|
218
|
+
|
|
174
219
|
context->results.resize(context->paths.size());
|
|
175
|
-
|
|
220
|
+
|
|
176
221
|
context->tsfn = Napi::ThreadSafeFunction::New(
|
|
177
222
|
env,
|
|
178
223
|
NOOP_FUNC(env),
|
package/src/types.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface OsuInput {
|
|
|
42
42
|
export interface INativeExporter {
|
|
43
43
|
get_property(location: string, key: string): string;
|
|
44
44
|
get_properties(location: string, keys: string[]): Record<string, string>;
|
|
45
|
-
process_beatmaps(locations: string[], keys: string[]): Promise<Record<string, string>[]>;
|
|
45
|
+
process_beatmaps(locations: string[], keys: string[], callback?: (index: number) => void): Promise<Record<string, string>[]>;
|
|
46
46
|
get_duration(location: string): number;
|
|
47
47
|
get_audio_duration(location: string): number;
|
|
48
48
|
}
|