This code analyzes Quake game maps stored in JSON format, identifying and logging any missing textures for each map.
npm run import -- "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
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:
Dependencies:
path
: Node.js module for working with file paths.fs
: Node.js module for file system operations.glob
: Node.js module for finding files matching a pattern.os
: Node.js module for interacting with the operating system.asset.game.js
: Custom module containing functions for loading Quake game data and handling textures.Constants:
GRAPH_PATH
: Defines the directory where map graphs are stored. It uses environment variables to determine the user's home directory.findMissingTextures
Function:
loadDefaultDirectories
..json
files in the GRAPH_PATH
directory using glob.sync
.graphGame
to analyze the map graph and identify missing textures.Exports:
findMissingTextures
function for use in other parts of the application.Let me know if you have any more questions!