[NodeMod Core]
/ .. / default
Class: default
Defined in: src/core/resource.ts:43
Enhanced resource management system with queuing for game assets. Handles precaching of models, sounds, and generic files with automatic queue processing on map spawn.
Example
// Precache a single sound
await nodemodCore.resource.precacheSound('weapons/ak47/ak47-1.wav');
// Precache a model with callback
await nodemodCore.resource.precacheModel('models/player/terror/terror.mdl');
// Batch precache multiple resources
await nodemodCore.resource.precacheBatch([
{ type\: 'sound', path\: 'weapons/ak47/ak47-1.wav' },
{ type\: 'model', path\: 'models/w_ak47.mdl' },
{ type\: 'generic', path\: 'sprites/muzzleflash.spr' }
]);
Constructors
Constructor
new default():
NodemodResource
Defined in: src/core/resource.ts:51
Creates a new NodemodResource instance and sets up event handlers. Automatically processes the precache queue when the map spawns.
Returns
NodemodResource
Properties
listToPrecache
private
listToPrecache:PrecacheFunction
[] =[]
Defined in: src/core/resource.ts:45
Queue of precaching functions to execute on map spawn
Methods
precacheSound()
precacheSound(
path
,cb
):Promise
<void
>
Defined in: src/core/resource.ts:78
Queues a sound file for precaching. The actual precaching occurs when the map spawns.
Parameters
path
string
Path to the sound file (relative to game directory)
cb
PrecacheCallback
= ...
Optional callback executed with the precache ID
Returns
Promise
<void
>
Example
// Basic sound precaching
await nodemodCore.resource.precacheSound('weapons/ak47/ak47-1.wav');
// With callback
await nodemodCore.resource.precacheSound('ambient/water/water1.wav', (id) => {
console.log(`Sound precached with ID\: ${id}`);
});
precacheModel()
precacheModel(
path
):Promise
<number
>
Defined in: src/core/resource.ts:98
Queues a model file for precaching. Returns a promise that resolves with the precache ID when the map spawns.
Parameters
path
string
Path to the model file (relative to game directory)
Returns
Promise
<number
>
Promise resolving to the precache ID
Example
const modelId = await nodemodCore.resource.precacheModel('models/w_ak47.mdl');
console.log(`Model precached with ID\: ${modelId}`);
precacheGeneric()
precacheGeneric(
path
):Promise
<number
>
Defined in: src/core/resource.ts:121
Queues a generic file for precaching. Returns a promise that resolves with the precache ID when the map spawns.
Parameters
path
string
Path to the generic file (relative to game directory)
Returns
Promise
<number
>
Promise resolving to the precache ID
Example
const spriteId = await nodemodCore.resource.precacheGeneric('sprites/muzzleflash.spr');
console.log(`Sprite precached with ID\: ${spriteId}`);
precacheBatch()
precacheBatch(
resources
):Promise
<(number
|void
)[]>
Defined in: src/core/resource.ts:150
Precaches multiple resources in batch. More efficient than precaching resources individually.
Parameters
resources
Array of resources to precache
Returns
Promise
<(number
| void
)[]>
Promise resolving to array of precache IDs (or void for sounds with no callback)
Example
const resources = [
{ type\: 'sound', path\: 'weapons/ak47/ak47-1.wav' },
{ type\: 'model', path\: 'models/w_ak47.mdl' },
{ type\: 'generic', path\: 'sprites/muzzleflash.spr' }
];
const results = await nodemodCore.resource.precacheBatch(resources);
console.log('All resources precached\:', results);
getQueueLength()
getQueueLength():
number
Defined in: src/core/resource.ts:176
Gets the current number of queued precaching operations.
Returns
number
Number of items in the precache queue
Example
console.log(`${nodemodCore.resource.getQueueLength()} items queued for precaching`);
clearQueue()
clearQueue():
void
Defined in: src/core/resource.ts:191
Clears all queued precaching operations. Use with caution as this will prevent queued resources from being precached.
Returns
void
Example
// Clear all pending precache operations
nodemodCore.resource.clearQueue();
console.log('Precache queue cleared');