quake 3 | Does TrenchBroom really require everything be in 1 folder | scale quake map | Search

This code defines a function convertMap that modifies Quake 3 map files by replacing entities, classes, and textures, scaling the map, and optionally adding a skybox. The modified map is then saved to a new file.

Run example

npm run import -- "convert quake 2 map to quake 3"

convert quake 2 map to quake 3

var fs = require('fs')
var path = require('path')
var importer = require('../Core')
var replaceClasses = importer.import("replace known classes in map")
var replaceEntities = importer.import("replace entities in map")
var replaceTextures = importer.import("replace common textures in map")
var scaleMap = importer.import("scale quake map")
var {addSkybox} = importer.import("add skybox to map")
var {MAPS_HINTS, addHints} = importer.import("draw hints in map")

function convertMap(fileName) {
    var file;
    if(typeof fileName === 'string' && fs.existsSync(fileName)) {
        file = fs.readFileSync(fileName).toString('utf-8')
    }
    
    file = replaceEntities(file)
    
    file = replaceClasses(file)
    
    // replace water with foggy water
    
    // replace message with target print
    
    // replace duplicate textures / don't interfere with basepack
    file = replaceTextures(file)
    
    // replace barrels with rocket launchers
    
    // replace animations and generate proper shaders
    // scale map 1.2x
    file = scaleMap(file, 1.15)
    
    //file = addSkybox(file)
    
    // scale lighting with q3map2 bsp options
    var newFile = fileName.substr(0, fileName.length - path.extname(fileName).length) + '.map'
    console.log(`writing ${newFile}`)
    fs.writeFileSync(newFile, file)
}

module.exports = convertMap;

What the code could have been:

const fs = require('fs');
const path = require('path');
const importer = require('../Core');

// Import modules lazily to avoid loading them when not used
const modules = {
  replaceClasses: importer.import('replace known classes in map'),
  replaceEntities: importer.import('replace entities in map'),
  replaceTextures: importer.import('replace common textures in map'),
  scaleMap: importer.import('scale quake map'),
  addSkybox: importer.import('add skybox to map'),
  hints: importer.import('draw hints in map'),
};

function convertMap(fileName) {
  // Check if file exists
  if (typeof fileName!=='string' ||!fs.existsSync(fileName)) {
    throw new Error(`File does not exist: ${fileName}`);
  }

  // Read file content
  let file = fs.readFileSync(fileName, 'utf-8');

  // Replace entities
  file = modules.replaceEntities(file);

  // Replace classes
  file = modules.replaceClasses(file);

  // Replace textures
  file = modules.replaceTextures(file);

  // Scale map
  file = modules.scaleMap(file, 1.15);

  // Note: addSkybox and drawHints are not implemented yet
  // To-do: implement addSkybox and drawHints
  // const newFile = addSkybox(file);
  // const hints = modules.hints;

  // Write new map file
  const newFile = fileName.substr(0, fileName.length - path.extname(fileName).length) + '.map';
  console.log(`Writing ${newFile}`);
  fs.writeFileSync(newFile, file);
}

module.exports = convertMap;

This code snippet defines a function convertMap that modifies Quake 3 map files.

Here's a breakdown:

  1. Dependencies:

  2. convertMap Function:

  3. Exports: The code exports the convertMap function, making it available for use in other parts of the project.

Functionality Breakdown:

  1. Dependencies:

  2. Importing Functions:

  3. convertMap Function:

Purpose:

This code snippet is a script for converting Quake map files. It reads a map file, applies various modifications (entity, class, texture replacements, scaling), and writes the modified map to a new file. The script is designed to be modular, allowing for easy addition or removal of modification functions.