quake 3 | test crc file | convert nonalpha | Search

This code analyzes Quake game maps stored in JSON format, identifying and logging any missing textures for each map.

Run example

npm run import -- "scan map graphs"

scan map graphs

var path = require('path')
var fs = require('fs')
var glob = require('glob')
var os = require('os')
var {graphGame, loadDefaultDirectories, entities, TEMP_NAME, BASEMOD, BASEMOD_LOWER, BASEMOD_DIRS} = require('../../planet_quake/code/xquakejs/lib/asset.game.js')

var GRAPH_PATH = path.join(process.env.HOME || process.env.HOMEPATH 
  || process.env.USERPROFILE || os.tmpdir(), '/Collections/lvlworld')

console.log(entities)

async function findMissingTextures() {
    await loadDefaultDirectories()
    var mapGraphs = glob.sync('*.json', {cwd: GRAPH_PATH})
    for(var i = 0; i < mapGraphs.length; i++) {
        var previous = JSON.parse(fs.readFileSync(path.join(GRAPH_PATH, mapGraphs[i])).toString('utf-8'))
        var game = await graphGame(previous, null, console.log)
        console.log(game.notfound)
    }
}

module.exports = findMissingTextures

What the code could have been:

const path = require('path');
const fs = require('fs').promises; // Use promises for async file operations
const glob = require('glob');
const os = require('os');
const { graphGame, loadDefaultDirectories, entities, TEMP_NAME, BASEMOD, BASEMOD_LOWER, BASEMOD_DIRS } = require('../../planet_quake/code/xquakejs/lib/asset.game.js');

/**
 * Default path for the graph collection
 * @type {string}
 */
const GRAPH_PATH = path.join(
  (process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE) || os.tmpdir(),
  '/Collections/lvlworld'
);

/**
 * Log entities for debugging purposes
 * @type {object}
 */
console.log(entities);

/**
 * Find missing textures in map graphs
 * @async
 * @returns {Promise}
 */
async function findMissingTextures() {
  try {
    // Load default directories to ensure necessary assets are available
    await loadDefaultDirectories();
    const mapGraphs = await glob.promise('*.json', { cwd: GRAPH_PATH });
    for (const mapGraph of mapGraphs) {
      // Read the map graph file and parse its contents
      const previous = JSON.parse(await fs.readFile(path.join(GRAPH_PATH, mapGraph), 'utf-8'));
      // Run the game logic for the current map graph
      const game = await graphGame(previous, null, console.log);
      // Log the missing textures for the current game
      console.log(game.notfound);
    }
  } catch (error) {
    // Catch and log any errors that occur during the process
    console.error(error);
  }
}

module.exports = findMissingTextures;

This code snippet analyzes Quake game maps for missing textures.

Here's a breakdown:

  1. Dependencies:

  2. Constants:

  3. findMissingTextures Function:

  4. Exports:

Let me know if you have any more questions!