@nodemod/core 1.0.0
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/README.md +60 -0
- package/dist/core/cmd.d.ts +148 -0
- package/dist/core/cmd.d.ts.map +1 -0
- package/dist/core/cmd.js +177 -0
- package/dist/core/cmd.js.map +1 -0
- package/dist/core/menu.d.ts +300 -0
- package/dist/core/menu.d.ts.map +1 -0
- package/dist/core/menu.js +449 -0
- package/dist/core/menu.js.map +1 -0
- package/dist/core/msg.d.ts +300 -0
- package/dist/core/msg.d.ts.map +1 -0
- package/dist/core/msg.js +374 -0
- package/dist/core/msg.js.map +1 -0
- package/dist/core/resource.d.ts +137 -0
- package/dist/core/resource.d.ts.map +1 -0
- package/dist/core/resource.js +171 -0
- package/dist/core/resource.js.map +1 -0
- package/dist/core/sound.d.ts +262 -0
- package/dist/core/sound.d.ts.map +1 -0
- package/dist/core/sound.js +300 -0
- package/dist/core/sound.js.map +1 -0
- package/dist/enhanced/entity.d.ts +263 -0
- package/dist/enhanced/entity.d.ts.map +1 -0
- package/dist/enhanced/entity.js +447 -0
- package/dist/enhanced/entity.js.map +1 -0
- package/dist/enhanced/events.d.ts +257 -0
- package/dist/enhanced/events.d.ts.map +1 -0
- package/dist/enhanced/events.js +350 -0
- package/dist/enhanced/events.js.map +1 -0
- package/dist/enhanced/player.d.ts +272 -0
- package/dist/enhanced/player.d.ts.map +1 -0
- package/dist/enhanced/player.js +389 -0
- package/dist/enhanced/player.js.map +1 -0
- package/dist/enhanced/trace.d.ts +198 -0
- package/dist/enhanced/trace.d.ts.map +1 -0
- package/dist/enhanced/trace.js +311 -0
- package/dist/enhanced/trace.js.map +1 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +120 -0
- package/dist/index.js.map +1 -0
- package/dist/native/cvar.d.ts +49 -0
- package/dist/native/cvar.d.ts.map +1 -0
- package/dist/native/cvar.js +169 -0
- package/dist/native/cvar.js.map +1 -0
- package/dist/native/file.d.ts +221 -0
- package/dist/native/file.d.ts.map +1 -0
- package/dist/native/file.js +353 -0
- package/dist/native/file.js.map +1 -0
- package/dist/types/dll.d.ts +109 -0
- package/dist/types/engine.d.ts +319 -0
- package/dist/types/enums.d.ts +434 -0
- package/dist/types/events.d.ts +2432 -0
- package/dist/types/index.d.ts +38 -0
- package/dist/types/structures.d.ts +1144 -0
- package/dist/utils/util.d.ts +202 -0
- package/dist/utils/util.d.ts.map +1 -0
- package/dist/utils/util.js +318 -0
- package/dist/utils/util.js.map +1 -0
- package/package.json +167 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function type for precaching operations.
|
|
3
|
+
*/
|
|
4
|
+
export type PrecacheFunction = () => void;
|
|
5
|
+
/**
|
|
6
|
+
* Callback function executed after a resource is precached.
|
|
7
|
+
*/
|
|
8
|
+
export type PrecacheCallback = (id: number) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for a resource to be precached.
|
|
11
|
+
*/
|
|
12
|
+
export interface ResourceItem {
|
|
13
|
+
/** Type of resource (model, sound, or generic file) */
|
|
14
|
+
type: 'model' | 'sound' | 'generic';
|
|
15
|
+
/** File path relative to the game directory */
|
|
16
|
+
path: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Enhanced resource management system with queuing for game assets.
|
|
20
|
+
* Handles precaching of models, sounds, and generic files with automatic queue processing on map spawn.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Precache a single sound
|
|
25
|
+
* await nodemodCore.resource.precacheSound('weapons/ak47/ak47-1.wav');
|
|
26
|
+
*
|
|
27
|
+
* // Precache a model with callback
|
|
28
|
+
* await nodemodCore.resource.precacheModel('models/player/terror/terror.mdl');
|
|
29
|
+
*
|
|
30
|
+
* // Batch precache multiple resources
|
|
31
|
+
* await nodemodCore.resource.precacheBatch([
|
|
32
|
+
* { type: 'sound', path: 'weapons/ak47/ak47-1.wav' },
|
|
33
|
+
* { type: 'model', path: 'models/w_ak47.mdl' },
|
|
34
|
+
* { type: 'generic', path: 'sprites/muzzleflash.spr' }
|
|
35
|
+
* ]);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export default class NodemodResource {
|
|
39
|
+
/** Queue of precaching functions to execute on map spawn */
|
|
40
|
+
private listToPrecache;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new NodemodResource instance and sets up event handlers.
|
|
43
|
+
* Automatically processes the precache queue when the map spawns.
|
|
44
|
+
*/
|
|
45
|
+
constructor();
|
|
46
|
+
/**
|
|
47
|
+
* Queues a sound file for precaching.
|
|
48
|
+
* The actual precaching occurs when the map spawns.
|
|
49
|
+
*
|
|
50
|
+
* @param path - Path to the sound file (relative to game directory)
|
|
51
|
+
* @param cb - Optional callback executed with the precache ID
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Basic sound precaching
|
|
56
|
+
* await nodemodCore.resource.precacheSound('weapons/ak47/ak47-1.wav');
|
|
57
|
+
*
|
|
58
|
+
* // With callback
|
|
59
|
+
* await nodemodCore.resource.precacheSound('ambient/water/water1.wav', (id) => {
|
|
60
|
+
* console.log(`Sound precached with ID: ${id}`);
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
precacheSound(path: string, cb?: PrecacheCallback): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Queues a model file for precaching.
|
|
67
|
+
* Returns a promise that resolves with the precache ID when the map spawns.
|
|
68
|
+
*
|
|
69
|
+
* @param path - Path to the model file (relative to game directory)
|
|
70
|
+
* @returns Promise resolving to the precache ID
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const modelId = await nodemodCore.resource.precacheModel('models/w_ak47.mdl');
|
|
75
|
+
* console.log(`Model precached with ID: ${modelId}`);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
precacheModel(path: string): Promise<number>;
|
|
79
|
+
/**
|
|
80
|
+
* Queues a generic file for precaching.
|
|
81
|
+
* Returns a promise that resolves with the precache ID when the map spawns.
|
|
82
|
+
*
|
|
83
|
+
* @param path - Path to the generic file (relative to game directory)
|
|
84
|
+
* @returns Promise resolving to the precache ID
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const spriteId = await nodemodCore.resource.precacheGeneric('sprites/muzzleflash.spr');
|
|
89
|
+
* console.log(`Sprite precached with ID: ${spriteId}`);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
precacheGeneric(path: string): Promise<number>;
|
|
93
|
+
/**
|
|
94
|
+
* Precaches multiple resources in batch.
|
|
95
|
+
* More efficient than precaching resources individually.
|
|
96
|
+
*
|
|
97
|
+
* @param resources - Array of resources to precache
|
|
98
|
+
* @returns Promise resolving to array of precache IDs (or void for sounds with no callback)
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const resources = [
|
|
103
|
+
* { type: 'sound', path: 'weapons/ak47/ak47-1.wav' },
|
|
104
|
+
* { type: 'model', path: 'models/w_ak47.mdl' },
|
|
105
|
+
* { type: 'generic', path: 'sprites/muzzleflash.spr' }
|
|
106
|
+
* ];
|
|
107
|
+
*
|
|
108
|
+
* const results = await nodemodCore.resource.precacheBatch(resources);
|
|
109
|
+
* console.log('All resources precached:', results);
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
precacheBatch(resources: ResourceItem[]): Promise<(number | void)[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the current number of queued precaching operations.
|
|
115
|
+
*
|
|
116
|
+
* @returns Number of items in the precache queue
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* console.log(`${nodemodCore.resource.getQueueLength()} items queued for precaching`);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
getQueueLength(): number;
|
|
124
|
+
/**
|
|
125
|
+
* Clears all queued precaching operations.
|
|
126
|
+
* Use with caution as this will prevent queued resources from being precached.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* // Clear all pending precache operations
|
|
131
|
+
* nodemodCore.resource.clearQueue();
|
|
132
|
+
* console.log('Precache queue cleared');
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
clearQueue(): void;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/core/resource.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,uDAAuD;IACvD,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IACpC,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;CACd;AAID;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,4DAA4D;IAC5D,OAAO,CAAC,cAAc,CAA0B;IAEhD;;;OAGG;;IAUH;;;;;;;;;;;;;;;;;OAiBG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAE,gBAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjF;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU5C;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAU9C;;;;;;;;;;;;;;;;;;OAkBG;IACH,aAAa,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAgBpE;;;;;;;;;OASG;IACH,cAAc,IAAI,MAAM;IAIxB;;;;;;;;;;OAUG;IACH,UAAU,IAAI,IAAI;CAGnB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Extend the nodemod namespace to include missing methods
|
|
4
|
+
/**
|
|
5
|
+
* Enhanced resource management system with queuing for game assets.
|
|
6
|
+
* Handles precaching of models, sounds, and generic files with automatic queue processing on map spawn.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Precache a single sound
|
|
11
|
+
* await nodemodCore.resource.precacheSound('weapons/ak47/ak47-1.wav');
|
|
12
|
+
*
|
|
13
|
+
* // Precache a model with callback
|
|
14
|
+
* await nodemodCore.resource.precacheModel('models/player/terror/terror.mdl');
|
|
15
|
+
*
|
|
16
|
+
* // Batch precache multiple resources
|
|
17
|
+
* await nodemodCore.resource.precacheBatch([
|
|
18
|
+
* { type: 'sound', path: 'weapons/ak47/ak47-1.wav' },
|
|
19
|
+
* { type: 'model', path: 'models/w_ak47.mdl' },
|
|
20
|
+
* { type: 'generic', path: 'sprites/muzzleflash.spr' }
|
|
21
|
+
* ]);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
class NodemodResource {
|
|
25
|
+
/** Queue of precaching functions to execute on map spawn */
|
|
26
|
+
listToPrecache = [];
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new NodemodResource instance and sets up event handlers.
|
|
29
|
+
* Automatically processes the precache queue when the map spawns.
|
|
30
|
+
*/
|
|
31
|
+
constructor() {
|
|
32
|
+
nodemod.on('dllSpawn', () => {
|
|
33
|
+
while (this.listToPrecache.length) {
|
|
34
|
+
const fn = this.listToPrecache.pop();
|
|
35
|
+
if (fn)
|
|
36
|
+
fn();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Queues a sound file for precaching.
|
|
42
|
+
* The actual precaching occurs when the map spawns.
|
|
43
|
+
*
|
|
44
|
+
* @param path - Path to the sound file (relative to game directory)
|
|
45
|
+
* @param cb - Optional callback executed with the precache ID
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Basic sound precaching
|
|
50
|
+
* await nodemodCore.resource.precacheSound('weapons/ak47/ak47-1.wav');
|
|
51
|
+
*
|
|
52
|
+
* // With callback
|
|
53
|
+
* await nodemodCore.resource.precacheSound('ambient/water/water1.wav', (id) => {
|
|
54
|
+
* console.log(`Sound precached with ID: ${id}`);
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async precacheSound(path, cb = () => { }) {
|
|
59
|
+
this.listToPrecache.push(() => {
|
|
60
|
+
const id = nodemod.eng.precacheSound(path);
|
|
61
|
+
cb(id);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Queues a model file for precaching.
|
|
66
|
+
* Returns a promise that resolves with the precache ID when the map spawns.
|
|
67
|
+
*
|
|
68
|
+
* @param path - Path to the model file (relative to game directory)
|
|
69
|
+
* @returns Promise resolving to the precache ID
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const modelId = await nodemodCore.resource.precacheModel('models/w_ak47.mdl');
|
|
74
|
+
* console.log(`Model precached with ID: ${modelId}`);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
precacheModel(path) {
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
this.listToPrecache.push(() => {
|
|
80
|
+
const id = nodemod.eng.precacheModel(path);
|
|
81
|
+
console.log(path, id);
|
|
82
|
+
resolve(id);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Queues a generic file for precaching.
|
|
88
|
+
* Returns a promise that resolves with the precache ID when the map spawns.
|
|
89
|
+
*
|
|
90
|
+
* @param path - Path to the generic file (relative to game directory)
|
|
91
|
+
* @returns Promise resolving to the precache ID
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const spriteId = await nodemodCore.resource.precacheGeneric('sprites/muzzleflash.spr');
|
|
96
|
+
* console.log(`Sprite precached with ID: ${spriteId}`);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
precacheGeneric(path) {
|
|
100
|
+
return new Promise((resolve) => {
|
|
101
|
+
this.listToPrecache.push(() => {
|
|
102
|
+
const id = nodemod.eng.precacheGeneric(path);
|
|
103
|
+
console.log(path, id);
|
|
104
|
+
resolve(id);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Precaches multiple resources in batch.
|
|
110
|
+
* More efficient than precaching resources individually.
|
|
111
|
+
*
|
|
112
|
+
* @param resources - Array of resources to precache
|
|
113
|
+
* @returns Promise resolving to array of precache IDs (or void for sounds with no callback)
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const resources = [
|
|
118
|
+
* { type: 'sound', path: 'weapons/ak47/ak47-1.wav' },
|
|
119
|
+
* { type: 'model', path: 'models/w_ak47.mdl' },
|
|
120
|
+
* { type: 'generic', path: 'sprites/muzzleflash.spr' }
|
|
121
|
+
* ];
|
|
122
|
+
*
|
|
123
|
+
* const results = await nodemodCore.resource.precacheBatch(resources);
|
|
124
|
+
* console.log('All resources precached:', results);
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
precacheBatch(resources) {
|
|
128
|
+
const promises = [];
|
|
129
|
+
resources.forEach(resource => {
|
|
130
|
+
if (resource.type === 'model') {
|
|
131
|
+
promises.push(this.precacheModel(resource.path));
|
|
132
|
+
}
|
|
133
|
+
else if (resource.type === 'sound') {
|
|
134
|
+
promises.push(this.precacheSound(resource.path));
|
|
135
|
+
}
|
|
136
|
+
else if (resource.type === 'generic') {
|
|
137
|
+
promises.push(this.precacheGeneric(resource.path));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return Promise.all(promises);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Gets the current number of queued precaching operations.
|
|
144
|
+
*
|
|
145
|
+
* @returns Number of items in the precache queue
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* console.log(`${nodemodCore.resource.getQueueLength()} items queued for precaching`);
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
getQueueLength() {
|
|
153
|
+
return this.listToPrecache.length;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Clears all queued precaching operations.
|
|
157
|
+
* Use with caution as this will prevent queued resources from being precached.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Clear all pending precache operations
|
|
162
|
+
* nodemodCore.resource.clearQueue();
|
|
163
|
+
* console.log('Precache queue cleared');
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
clearQueue() {
|
|
167
|
+
this.listToPrecache = [];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.default = NodemodResource;
|
|
171
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/core/resource.ts"],"names":[],"mappings":";;AAoBA,0DAA0D;AAE1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAqB,eAAe;IAClC,4DAA4D;IACpD,cAAc,GAAuB,EAAE,CAAC;IAEhD;;;OAGG;IACH;QACE,OAAO,CAAC,EAAE,CAAC,UAAU,E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gBACtB,OAAO,CAAC,EAAE,CAAC,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,aAAa,CAAC,SAAyB;QACrC,MAAM,QAAQ,GAA6B,EAAE,CAAC;QAE9C,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC3B,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC9B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YACnD,CAAC;iBAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBACrC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YACnD,CAAC;iBAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;OASG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;IACpC,CAAC;IAED;;;;;;;;;;OAUG;IACH,UAAU;QACR,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;IAC3B,CAAC;CACF;AAvJD,kCAuJC"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import type NodemodUtil from '../utils/util';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for emitting sounds.
|
|
4
|
+
*/
|
|
5
|
+
export interface EmitSoundOptions {
|
|
6
|
+
/** Target entity or entity index (0 for world entity) */
|
|
7
|
+
entity?: nodemod.Entity | number;
|
|
8
|
+
/** Audio channel to use */
|
|
9
|
+
channel?: number;
|
|
10
|
+
/** Path to the sound file */
|
|
11
|
+
sound: string;
|
|
12
|
+
/** Volume level (0.0 to 1.0) */
|
|
13
|
+
volume?: number;
|
|
14
|
+
/** Sound attenuation over distance */
|
|
15
|
+
attenuation?: number;
|
|
16
|
+
/** Sound transmission flags */
|
|
17
|
+
flags?: number;
|
|
18
|
+
/** Pitch adjustment (1-255, 100 = normal) */
|
|
19
|
+
pitch?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sound configuration alias for batch operations.
|
|
23
|
+
*/
|
|
24
|
+
export interface SoundConfig extends EmitSoundOptions {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result of a sound emission operation.
|
|
28
|
+
*/
|
|
29
|
+
export interface SoundResult {
|
|
30
|
+
/** Index in the batch operation */
|
|
31
|
+
index: number;
|
|
32
|
+
/** Whether the sound was successfully emitted */
|
|
33
|
+
success: boolean;
|
|
34
|
+
/** The configuration used for this sound */
|
|
35
|
+
config: SoundConfig;
|
|
36
|
+
/** Error message if emission failed */
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Audio channel constants for categorizing sounds.
|
|
41
|
+
*/
|
|
42
|
+
export declare const SoundChannel: {
|
|
43
|
+
/** Automatically select appropriate channel */
|
|
44
|
+
auto: number;
|
|
45
|
+
/** Weapon sounds */
|
|
46
|
+
weapon: number;
|
|
47
|
+
/** Voice communications */
|
|
48
|
+
voice: number;
|
|
49
|
+
/** Item interaction sounds */
|
|
50
|
+
item: number;
|
|
51
|
+
/** Body/movement sounds */
|
|
52
|
+
body: number;
|
|
53
|
+
/** Streaming audio */
|
|
54
|
+
stream: number;
|
|
55
|
+
/** Static/ambient sounds */
|
|
56
|
+
static: number;
|
|
57
|
+
/** Network voice communication base */
|
|
58
|
+
networkVoiceBase: number;
|
|
59
|
+
/** Network voice communication end */
|
|
60
|
+
networkVoiceEnd: number;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Enhanced sound system providing comprehensive audio functionality for the game server.
|
|
64
|
+
* Handles sound emission, validation, and management with improved defaults and error handling.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Play a weapon sound
|
|
69
|
+
* nodemodCore.sound.emitSound({
|
|
70
|
+
* entity: player,
|
|
71
|
+
* channel: SoundChannel.weapon,
|
|
72
|
+
* sound: 'weapons/ak47/ak47-1.wav',
|
|
73
|
+
* volume: 0.8,
|
|
74
|
+
* pitch: 110
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Broadcast ambient sound to all players
|
|
78
|
+
* nodemodCore.sound.broadcastSound('ambient/music/track1.wav', {
|
|
79
|
+
* volume: 0.5,
|
|
80
|
+
* attenuation: 0.5
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Play client-side sound command
|
|
84
|
+
* nodemodCore.sound.emitClientSound(player, 'ui/buttonclick');
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export default class NodemodSound {
|
|
88
|
+
/** Utility service for entity operations */
|
|
89
|
+
private util;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new NodemodSound instance.
|
|
92
|
+
*
|
|
93
|
+
* @param utilService - Utility service for entity operations
|
|
94
|
+
*/
|
|
95
|
+
constructor(utilService: NodemodUtil);
|
|
96
|
+
/**
|
|
97
|
+
* Emits a sound with enhanced validation and default values.
|
|
98
|
+
* Provides better parameter validation and clamping than the basic engine function.
|
|
99
|
+
*
|
|
100
|
+
* @param options - Sound emission configuration
|
|
101
|
+
* @returns True if sound was emitted successfully, false otherwise
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Basic sound emission
|
|
106
|
+
* nodemodCore.sound.emitSound({
|
|
107
|
+
* sound: 'weapons/ak47/ak47-1.wav'
|
|
108
|
+
* });
|
|
109
|
+
*
|
|
110
|
+
* // Advanced sound with all options
|
|
111
|
+
* nodemodCore.sound.emitSound({
|
|
112
|
+
* entity: player,
|
|
113
|
+
* channel: SoundChannel.weapon,
|
|
114
|
+
* sound: 'weapons/ak47/ak47-1.wav',
|
|
115
|
+
* volume: 0.8,
|
|
116
|
+
* attenuation: 1.5,
|
|
117
|
+
* flags: 0, // Normal playback
|
|
118
|
+
* pitch: 110
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
emitSound(options: EmitSoundOptions): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Sends a client-side sound command to a specific player.
|
|
125
|
+
* Uses the client's `spk` command to play sounds locally.
|
|
126
|
+
*
|
|
127
|
+
* @param entity - Target player entity or index
|
|
128
|
+
* @param soundName - Name of the sound file (with or without extension)
|
|
129
|
+
* @param extension - File extension to append if not present in soundName
|
|
130
|
+
* @returns True if command was sent successfully, false otherwise
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* // Play UI sound to player
|
|
135
|
+
* nodemodCore.sound.emitClientSound(player, 'ui/buttonclick');
|
|
136
|
+
*
|
|
137
|
+
* // Play custom sound with specific extension
|
|
138
|
+
* nodemodCore.sound.emitClientSound(player, 'custom/notification', 'mp3');
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
emitClientSound(entity: nodemod.Entity | number, soundName: string, extension?: string): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Emits an ambient sound at a specific 3D position.
|
|
144
|
+
* Useful for environmental sounds, explosions, or location-based audio.
|
|
145
|
+
*
|
|
146
|
+
* @param position - 3D coordinates [x, y, z] where the sound originates
|
|
147
|
+
* @param sound - Path to the sound file
|
|
148
|
+
* @param volume - Volume level (0.0 to 1.0)
|
|
149
|
+
* @param attenuation - How quickly sound fades with distance
|
|
150
|
+
* @param flags - Sound transmission flags
|
|
151
|
+
* @param pitch - Pitch adjustment (1-255, 100 = normal)
|
|
152
|
+
* @returns True if sound was emitted successfully, false otherwise
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* // Explosion sound at coordinates
|
|
157
|
+
* nodemodCore.sound.emitAmbientSound(
|
|
158
|
+
* [100, 200, 50],
|
|
159
|
+
* 'weapons/explode1.wav',
|
|
160
|
+
* 0.9,
|
|
161
|
+
* 2.0
|
|
162
|
+
* );
|
|
163
|
+
*
|
|
164
|
+
* // Ambient environmental sound
|
|
165
|
+
* nodemodCore.sound.emitAmbientSound(
|
|
166
|
+
* [0, 0, 0],
|
|
167
|
+
* 'ambient/wind/wind1.wav',
|
|
168
|
+
* 0.3,
|
|
169
|
+
* 0.5,
|
|
170
|
+
* nodemod.SND.SPAWNING
|
|
171
|
+
* );
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
emitAmbientSound(position: number[], sound: string, volume?: number, attenuation?: number, flags?: number, pitch?: number): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Broadcasts a sound to all players on the server.
|
|
177
|
+
* Convenient wrapper for playing sounds that everyone should hear.
|
|
178
|
+
*
|
|
179
|
+
* @param sound - Path to the sound file
|
|
180
|
+
* @param options - Optional sound configuration overrides
|
|
181
|
+
* @returns True if sound was broadcast successfully, false otherwise
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* // Simple server announcement sound
|
|
186
|
+
* nodemodCore.sound.broadcastSound('admin/announcement.wav');
|
|
187
|
+
*
|
|
188
|
+
* // Round start music with custom settings
|
|
189
|
+
* nodemodCore.sound.broadcastSound('music/roundstart.wav', {
|
|
190
|
+
* volume: 0.7,
|
|
191
|
+
* channel: SoundChannel.stream,
|
|
192
|
+
* attenuation: 0.1
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
broadcastSound(sound: string, options?: Partial<EmitSoundOptions>): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Attempts to stop a sound on a specific entity.
|
|
199
|
+
* Uses a workaround by playing a very quiet sound since direct stop may not be available.
|
|
200
|
+
*
|
|
201
|
+
* @param entity - Target entity or entity index
|
|
202
|
+
* @param channel - Audio channel to stop
|
|
203
|
+
* @param sound - Specific sound to stop (empty for all sounds on channel)
|
|
204
|
+
* @returns True if stop attempt was successful, false otherwise
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Stop all sounds on entity
|
|
209
|
+
* nodemodCore.sound.stopSound(player);
|
|
210
|
+
*
|
|
211
|
+
* // Stop weapon channel sounds
|
|
212
|
+
* nodemodCore.sound.stopSound(player, SoundChannel.weapon);
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
stopSound(entity: nodemod.Entity | number, channel?: number, sound?: string): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Validates whether a sound file path is valid.
|
|
218
|
+
* Checks for supported file extensions and proper format.
|
|
219
|
+
*
|
|
220
|
+
* @param soundPath - Path to the sound file to validate
|
|
221
|
+
* @returns True if the sound path is valid, false otherwise
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* // Valid sound files
|
|
226
|
+
* console.log(nodemodCore.sound.isValidSound('weapons/ak47-1.wav')); // true
|
|
227
|
+
* console.log(nodemodCore.sound.isValidSound('music/track.mp3')); // true
|
|
228
|
+
*
|
|
229
|
+
* // Invalid sound files
|
|
230
|
+
* console.log(nodemodCore.sound.isValidSound('invalid.txt')); // false
|
|
231
|
+
* console.log(nodemodCore.sound.isValidSound('')); // false
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
isValidSound(soundPath: string): boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Emits multiple sounds in batch with individual result tracking.
|
|
237
|
+
* Useful for playing multiple sounds simultaneously or handling bulk operations.
|
|
238
|
+
*
|
|
239
|
+
* @param soundConfigs - Array of sound configurations to emit
|
|
240
|
+
* @returns Array of results indicating success/failure for each sound
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const sounds = [
|
|
245
|
+
* { sound: 'weapons/ak47/ak47-1.wav', entity: player1, volume: 0.8 },
|
|
246
|
+
* { sound: 'weapons/deagle/deagle-1.wav', entity: player2, volume: 0.9 },
|
|
247
|
+
* { sound: 'items/ammopickup2.wav', volume: 0.5 }
|
|
248
|
+
* ];
|
|
249
|
+
*
|
|
250
|
+
* const results = nodemodCore.sound.emitMultipleSounds(sounds);
|
|
251
|
+
* results.forEach((result, i) => {
|
|
252
|
+
* if (result.success) {
|
|
253
|
+
* console.log(`Sound ${i} played successfully`);
|
|
254
|
+
* } else {
|
|
255
|
+
* console.log(`Sound ${i} failed: ${result.error}`);
|
|
256
|
+
* }
|
|
257
|
+
* });
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
emitMultipleSounds(soundConfigs: SoundConfig[]): SoundResult[];
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=sound.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sound.d.ts","sourceRoot":"","sources":["../../src/core/sound.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yDAAyD;IACzD,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IACjC,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAE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