quake 3 | Cell 27 | list textures in quake 3 map | Search

This code analyzes a Quake 2 map file to find missing sound files referenced by "noise" entities.

Run example

npm run import -- "list noises in a quake 3 map"

list noises in a quake 3 map

var fs = require('fs')
var path = require('path')
var importer = require('../Core')

function listNoise() {
    var contents = fs.readFileSync('/Users/briancullinan/.q3a/baseq3/baseq2.pk3dir/maps/base1.map').toString('utf8')
    var noises = importer.regexToArray(/noise.*?"\s*"(.*?)"/ig, contents, 1)
    return {all: noises, missing: noises.filter(n => {
        return !fs.existsSync(path.join('/Users/briancullinan/.q3a/baseq3/baseq2.pk3dir/sound/', n))
    })}
}

module.exports = listNoise

What the code could have been:

// Import required modules
const fs = require('fs').promises; // Use promises for asynchronous I/O
const path = require('path');
constImporter = require('../Core'); // PascalCase for consistency

// Constants for better readability
const Q3A_SOUND_DIR = '/Users/briancullinan/.q3a/baseq3/baseq2.pk3dir/sound/';
const BASE1_MAP_FILE = '/Users/briancullinan/.q3a/baseq3/baseq2.pk3dir/maps/base1.map';

/**
 * Lists all noise names from the base1.map file and checks if the corresponding sound files exist.
 * @returns {{all: string[], missing: string[]}} An object with two properties: all and missing noise names.
 */
async function listNoise() {
    // Read the base1.map file asynchronously for better performance
    const contents = await fs.readFile(BASE1_MAP_FILE, 'utf8');

    // Use the importer module to extract noise names from the file contents
    const noises = Importer.regexToArray(/noise.*?"\s*"(.*?)"/ig, contents, 1);

    // Filter the noise names to get the missing ones
    const soundFiles = await fs.readdir(Q3A_SOUND_DIR);
    const missing = noises.filter(n =>!soundFiles.includes(n));

    // Return the combined result
    return { all: noises, missing };
}

module.exports = listNoise;

This code snippet analyzes a Quake 2 map file (base1.map) to identify missing sound files referenced by "noise" entities.

Here's a breakdown:

  1. Initialization:

  2. listNoise Function:

  3. Export:

Purpose:

This code likely serves as a tool for identifying missing sound files in a Quake 2 map. It analyzes the map file, extracts references to sound files, and then checks if those files exist in the expected location. This can be useful for debugging or ensuring that all necessary sound files are present for a map to function correctly.