Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

wc3maptranslator

ChiefOfGxBxL156MIT4.0.4TypeScript support: included

Module to translate between war3map and json formats for WarCraft III .w3x maps

wc3, warcraft, reforged, frozen throne, reign of chaos, war3map, translator, json, w3x

readme

WC3MapTranslator
Translate war3mapjson formats for WarCraft III .w3x maps

Quality

Known Vulnerabilities


Overview · Install · Usage · File Support · Specification · Contributing · Special Thanks


Overview

WC3MapTranslator is a TypeScript module to convert between JSON and WarCraft III (.w3x) war3map formats. This makes the map data readable and easily modifiable, a perfect format for storing WC3 maps in Git repositories and inspecting diffs!

TranslationExample

Install

npm install wc3maptranslator

Requires Node ≥ 14

Usage

import {
  CamerasTranslator,
  DoodadsTranslator,
  ImportsTranslator,
  InfoTranslator,
  ObjectsTranslator,
  RegionsTranslator,
  SoundsTranslator,
  StringsTranslator,
  TerrainTranslator,
  UnitsTranslator
} from 'wc3maptranslator';

// E.g. let's create a camera for the map
const cameras = [
  {
    "target": {
      "x": -319.01,
      "y": -90.18
    },
    "offsetZ": 0,
    "rotation": 90,
    "aoa": 304,
    "distance": 2657.34,
    "roll": 5,
    "fov": 70,
    "farClipping": 5000,
    "name": "MyCamera1"
  }
]

// Now translate the JSON into the WarCraft III format
// All translators have: `.jsonToWar` and `.warToJson` functions
const translatedResult = CamerasTranslator.jsonToWar(cameras);

// `translatedResult` contains a `buffer` which can be saved to disk
// This war3map.w3c file can now be placed inside a .w3x via an MPQ
// editor, and you should now see a camera in the Camera Palette!
fs.writeFileSync('war3map.w3c', translatedResult.buffer);

File Support

World files

Type Json → War War → Json File
Terrain check times war3map.w3e
Units check check war3mapUnits.doo
Doodads check check war3map.doo
Regions check check war3map.w3r
Cameras check check war3map.w3c
Sounds (definitions) check check war3map.w3s

Object data files

Type Json → War War → Json File
Units - Objects check check war3map.w3u
Items - Objects check check war3map.w3t
Abilities - Objects check check war3map.w3a
Destructables - Objects check check war3map.w3b
Doodads - Objects check check war3map.w3d
Upgrades - Objects check check war3map.w3q
Buffs - Objects check check war3map.w3h

Trigger files

Type Json → War War → Json File
LUA times times war3map.lua
JASS times times war3map.j
Strings check check war3map.wts

Map files

Type Json → War War → Json File
Info File check check war3map.w3i
Imported Files check check war3map.imp
Pathing times times war3map.wpm
Shadow map times times war3map.shd

Not relevant

minus-solid Custom Text Trigger File (war3map.wct)
minus-solid Trigger Names File (war3map.wtg)
minus-solid Menu Minimap (war3map.mmp)
minus-solid Minimap Image (war3mapMap.blp)
minus-solid Minimap Image (war3mapMap.b00
minus-solid Minimap Image (war3mapMap.tga)
minus-solid Map Preview Image (war3mapPreview.tga)

Specification

WC3MapTranslator format

We have a detailed explaining how to format a map in JSON. It explains everything from the high-level map object, all the way down to creating individual units, tiles, or custom objects.

🔗 WC3MapTranslator format

war3map format

The underlying WarCraft map files (e.g. war3map.doo) have been documented in a separate repository. If you are curious about how a .w3x file is composed, this is the place to learn!

🔗 WC3MapSpecification

Contributing

We encourage contributions! Generally, the process of making a change is:

  1. Fork this repo
  2. Develop your changes on a new branch
  3. Submit a pull request to dev

Your code should:

  • run (your code needs to work, of course)
  • include tests (write unit tests to demonstrate your code works under different conditions)
  • be linted (run npm run lint and follow the project's coding standards)
  • pass CI (we enforce: ESLint, unit tests pass, code coverage)

A code review is required on your PR to be accepted into dev. A project member will get back to you within one week. If you haven't heard from someone regarding your PR, feel free to ping @chiefofgxbxl.

Special Thanks

We owe a lot of thanks to Chocobo on TheHelper for the detailed documentation of the files found in a .w3x archive. Two tutorials are here (1) and here (2).

changelog

4.0.3 (2023-08-06)

SUMMARY

FIXES

  • Fix dependency ieee754 being listed as devDependency instead of regular dependency, breaking some translators

4.0.2 (2023-08-06)

SUMMARY

FIXES

  • Fix build issues from previous release

4.0.1 (2023-08-06)

SUMMARY

FIXES

  • Project properly builds all TS files upon installation, resolving out-of-the-box errors

4.0.0 (2021-02-28)

SUMMARY

🔥 Breaking changes

This major release significantly overhauls WC3MapTranslator since the release of WarCraft III: Reforged. There are a few breaking changes in this release.

The two largest changes include a new usage contract and changes to the terrain .json format, both of which are detailed below. This release also integrates the latest file formats, after a few changes to the war3map formats to support Reforged.

The old usage contract meant that developers had to instantiate translators, which didn't make much sense. Now translators are static classes that can be used directly after importing.

The .json format for terrain gets rid of the bulky tile objects and returns to a one-dimensional mask array for things like ground height, boundary flags, etc. In an older version of WC3MapTranslator, terrain used to be a multi-dimensional array of rows, followed by the tile object format. The problems with the tile object format were two-fold: (1) file size would blow up (e.g. a 29kB .w3e file would become a 1199kB .json terrain file); and (2) the bulky tile objects did not lend themselves to the spirit of having a diff-able JSON file. We believe that a single-dimensional array will allow developers to more easily see differences between JSONs.

Another exciting change is a new WC3MapSpecification repository for documenting the war3map specifications. This is a living document, meaning it may be updated in-place as our understanding of the file formats improves!

FEATURES

  • 🔥 Improve usage contract:
    • Translators are now exported by this library (e.g. import { ObjectTranslator } from 'wc3maptranslator')
    • Translators no longer need to be instantiated to be used
  • 🔥 Change terrain format:
    • Tiles are now defined via "masks", for ground height, texture, variation, etc.
      • Before: tiles is an array of objects... { groundHeight, waterHeight, boundaryFlag, flags, groundTexture, groundVariation, cliffVariation, cliffTexture, layerHeight }
      • After: a one-dimensional array for each of the above fields... e.g. for a 64x64 map, groundHeight is an array of 65*65=4225 tile points
    • Some fields have been renamed into camelCase for consistency:
      • customtileset -> customTileset
      • tilepalette -> tilePalette
      • clifftilepalette -> cliffTilePalette
  • Upgrade to latest file formats
    • Sounds version upgraded from 1 -> 3
    • Info version upgraded from 25 -> 31
  • Add more type safety:
    • Translator results from jsonToWar() and warToJson() are now typed by WarResult and JsonResult, respectively
    • JsonResult is generically typed to describe what it contains (e.g. Sound[])
    • Introduced new angle type, which is an alias for number; angle's should always be specified in degrees, not radians

      FIXES

  • Resolve [DEP0005] DeprecationWarning: Buffer() warning in HexBuffer.ts
  • Fix scoping issues on *Translator.ts, HexBuffer.ts and W3Buffer.ts where certain fields that should be private were marked as public
  • Fix InfoTranslator reading random item table ID length as 1 instead of 4
  • Fix potential null-terminator errors related to string or character-array fields

    MAINTENANCE

  • Upgrade to Node 14.x LTS
  • Upgrade to npm 7.x
  • Upgrade round-to 4.1.0 -> 5.0.0
  • Upgrade @types/fs-extra 8.1.0 -> 9.0.7
  • Upgrade @types/mocha 7.0.1 -> 8.2.1
  • Upgrade @types/node 12.12.28 -> 14.14.31
  • Upgrade fs-extra 8.1.0 -> 9.1.0
  • Upgrade mocha 7.0.1 -> 8.3.0
  • Upgrade nyc 15.0.0 -> 15.1.0
  • Upgrade ts-node 8.6.2 -> 9.1.1
  • Upgrade tslint 6.0.0 -> 6.1.3
  • Upgrade typescript 3.8.2 -> 4.2.2
  • The project structure has changed:
    • examples sub-project directory is removed
    • Refer to USAGE.md for how to use the code
  • Add all contributors to package.json
  • Resolve all security issues via npm audit fix (5 low, 1 high, 1 critical)

    TESTING

  • Travis CI will now use Node 14 LTS to build the project
  • test directory now contains the WC3 and JSON data files the tests require
  • Implement the StringsTranslator test
  • Resolve all broken unit tests, most of them being reversion tests

Previous versions

The CHANGELOG.md file was introduced with the 4.x release. For details on previous changes, please refer to https://github.com/ChiefOfGxBxL/WC3MapTranslator/releases.