wc3maptranslator 3.0.3 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.codeclimate.yml +0 -1
  2. package/.eslintignore +0 -1
  3. package/.github/workflows/codeql-analysis.yml +54 -0
  4. package/.nycrc +1 -2
  5. package/.travis.yml +1 -2
  6. package/CHANGELOG.md +78 -0
  7. package/LICENSE.md +23 -0
  8. package/README.md +68 -75
  9. package/index.js +11 -15
  10. package/index.ts +12 -30
  11. package/lib/CommonInterfaces.ts +22 -0
  12. package/lib/HexBuffer.ts +11 -14
  13. package/lib/W3Buffer.ts +7 -3
  14. package/lib/translators/CamerasTranslator.ts +36 -41
  15. package/lib/translators/DoodadsTranslator.ts +57 -55
  16. package/lib/translators/ImportsTranslator.ts +29 -31
  17. package/lib/translators/InfoTranslator.ts +252 -204
  18. package/lib/translators/{object/ObjectsTranslator.ts → ObjectsTranslator.ts} +84 -82
  19. package/lib/translators/RegionsTranslator.ts +40 -58
  20. package/lib/translators/SoundsTranslator.ts +112 -96
  21. package/lib/translators/StringsTranslator.ts +23 -49
  22. package/lib/translators/TerrainTranslator.ts +166 -97
  23. package/lib/translators/UnitsTranslator.ts +98 -97
  24. package/lib/translators/index.ts +0 -1
  25. package/package.json +23 -16
  26. package/test/.mocharc.json +4 -0
  27. package/test/HexBufferTest.ts +11 -15
  28. package/test/TranslatorReversion.ts +104 -115
  29. package/test/W3BufferTest.ts +19 -13
  30. package/test/data/cameras.json +16 -0
  31. package/test/data/doodads.json +2730 -0
  32. package/test/data/imports.json +386 -0
  33. package/test/data/info.json +250 -0
  34. package/test/data/obj-abilities.json +4892 -0
  35. package/test/data/obj-buffs.json +38 -0
  36. package/test/data/obj-destructables.json +31 -0
  37. package/test/data/obj-doodads.json +38 -0
  38. package/test/data/obj-items.json +31 -0
  39. package/test/data/obj-units.json +40 -0
  40. package/test/data/obj-upgrades.json +38 -0
  41. package/test/data/regions.json +206 -0
  42. package/test/data/sounds.json +50 -0
  43. package/test/data/strings.json +115 -0
  44. package/test/data/terrain.json +1 -0
  45. package/test/data/units.json +452 -0
  46. package/test/data/war3map.doo +0 -0
  47. package/test/data/war3map.imp +0 -0
  48. package/test/data/war3map.j +3442 -0
  49. package/test/data/war3map.shd +0 -0
  50. package/test/data/war3map.w3a +0 -0
  51. package/test/data/war3map.w3b +0 -0
  52. package/test/data/war3map.w3c +0 -0
  53. package/test/data/war3map.w3d +0 -0
  54. package/test/data/war3map.w3e +0 -0
  55. package/test/data/war3map.w3h +0 -0
  56. package/test/data/war3map.w3i +0 -0
  57. package/test/data/war3map.w3q +0 -0
  58. package/test/data/war3map.w3r +0 -0
  59. package/test/data/war3map.w3s +0 -0
  60. package/test/data/war3map.w3t +0 -0
  61. package/test/data/war3map.w3u +0 -0
  62. package/test/data/war3map.wts +631 -0
  63. package/test/data/war3mapUnits.doo +0 -0
  64. package/examples/index.js +0 -123
  65. package/examples/index.ts +0 -134
  66. package/examples/json/cameras.json +0 -16
  67. package/examples/json/doodads.json +0 -28499
  68. package/examples/json/imports.json +0 -10
  69. package/examples/json/info.json +0 -111
  70. package/examples/json/object-abilities.json +0 -31
  71. package/examples/json/object-buffs.json +0 -24
  72. package/examples/json/object-destructables.json +0 -31
  73. package/examples/json/object-doodads.json +0 -24
  74. package/examples/json/object-items.json +0 -45
  75. package/examples/json/object-units.json +0 -45
  76. package/examples/json/object-upgrades.json +0 -31
  77. package/examples/json/regions.json +0 -36
  78. package/examples/json/sounds.json +0 -46
  79. package/examples/json/strings.json +0 -83
  80. package/examples/json/terrain.json +0 -46633
  81. package/examples/json/units.json +0 -332
  82. package/examples/package.json +0 -17
  83. package/examples/tsconfig.json +0 -27
  84. package/examples/war/war3map.doo +0 -0
  85. package/examples/war/war3map.imp +0 -0
  86. package/examples/war/war3map.w3a +0 -0
  87. package/examples/war/war3map.w3b +0 -0
  88. package/examples/war/war3map.w3c +0 -0
  89. package/examples/war/war3map.w3d +0 -0
  90. package/examples/war/war3map.w3e +0 -0
  91. package/examples/war/war3map.w3h +0 -0
  92. package/examples/war/war3map.w3i +0 -0
  93. package/examples/war/war3map.w3q +0 -0
  94. package/examples/war/war3map.w3r +0 -0
  95. package/examples/war/war3map.w3s +0 -0
  96. package/examples/war/war3map.w3t +0 -0
  97. package/examples/war/war3map.w3u +0 -0
  98. package/examples/war/war3map.wts +0 -99
  99. package/lib/translators/index.js +0 -16
  100. package/test/mocha.opts +0 -4
package/.codeclimate.yml CHANGED
@@ -9,5 +9,4 @@ ratings:
9
9
  - "**.ts"
10
10
  - "**.tsx"
11
11
  exclude_paths:
12
- - examples/
13
12
  - test/
package/.eslintignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.git/*
2
2
  /.nyc_output/*
3
3
  /coverage/*
4
- /examples/*
5
4
  /node_modules/*
6
5
  /test/*
@@ -0,0 +1,54 @@
1
+ name: "Code scanning - action"
2
+
3
+ on:
4
+ push:
5
+ branches: [master, ]
6
+ pull_request:
7
+ # The branches below must be a subset of the branches above
8
+ branches: [master]
9
+ schedule:
10
+ - cron: '0 22 * * 5'
11
+
12
+ jobs:
13
+ CodeQL-Build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout repository
19
+ uses: actions/checkout@v2
20
+ with:
21
+ # We must fetch at least the immediate parents so that if this is
22
+ # a pull request then we can checkout the head.
23
+ fetch-depth: 2
24
+
25
+ # If this run was triggered by a pull request event, then checkout
26
+ # the head of the pull request instead of the merge commit.
27
+ - run: git checkout HEAD^2
28
+ if: ${{ github.event_name == 'pull_request' }}
29
+
30
+ # Initializes the CodeQL tools for scanning.
31
+ - name: Initialize CodeQL
32
+ uses: github/codeql-action/init@v1
33
+ # Override language selection by uncommenting this and choosing your languages
34
+ # with:
35
+ # languages: go, javascript, csharp, python, cpp, java
36
+
37
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
38
+ # If this step fails, then you should remove it and run the build manually (see below)
39
+ - name: Autobuild
40
+ uses: github/codeql-action/autobuild@v1
41
+
42
+ # ℹ️ Command-line programs to run using the OS shell.
43
+ # 📚 https://git.io/JvXDl
44
+
45
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
46
+ # and modify them (or add more) to build your code if your project
47
+ # uses a compiled language
48
+
49
+ #- run: |
50
+ # make bootstrap
51
+ # make release
52
+
53
+ - name: Perform CodeQL Analysis
54
+ uses: github/codeql-action/analyze@v1
package/.nycrc CHANGED
@@ -8,8 +8,7 @@
8
8
  ],
9
9
  "exclude": [
10
10
  "**/*.d.ts",
11
- "**/coverage/**",
12
- "**/examples/**"
11
+ "**/coverage/**"
13
12
  ],
14
13
  "reporter": [
15
14
  "lcov",
package/.travis.yml CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  language: node_js
4
4
 
5
- # Run build on Node v8
6
5
  node_js:
7
- - "8"
6
+ - "14"
8
7
 
9
8
  branches:
10
9
  only:
package/CHANGELOG.md ADDED
@@ -0,0 +1,78 @@
1
+ # 4.0.1 (2023-08-06)
2
+ ## SUMMARY
3
+ ## FIXES
4
+ * Project properly builds all TS files upon installation, resolving out-of-the-box errors
5
+
6
+ # 4.0.0 (2021-02-28)
7
+ ## SUMMARY
8
+ **🔥 Breaking changes**
9
+
10
+ This major release significantly overhauls WC3MapTranslator since the release of WarCraft III: Reforged. There are a few breaking changes in this release.
11
+
12
+ 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.
13
+
14
+ 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.
15
+
16
+ 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.
17
+
18
+ Another exciting change is a new [WC3MapSpecification](https://github.com/ChiefOfGxBxL/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!
19
+
20
+ ## FEATURES
21
+ * 🔥 Improve usage contract:
22
+ * Translators are now exported by this library (e.g. `import { ObjectTranslator } from 'wc3maptranslator'`)
23
+ * Translators no longer need to be instantiated to be used
24
+ * 🔥 Change terrain format:
25
+ * Tiles are now defined via "masks", for ground height, texture, variation, etc.
26
+ * Before: `tiles` is an array of objects... `{ groundHeight, waterHeight, boundaryFlag, flags, groundTexture, groundVariation, cliffVariation, cliffTexture, layerHeight }`
27
+ * 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
28
+ * Some fields have been renamed into camelCase for consistency:
29
+ * `customtileset` -> `customTileset`
30
+ * `tilepalette` -> `tilePalette`
31
+ * `clifftilepalette` -> `cliffTilePalette`
32
+ * Upgrade to latest file formats
33
+ * Sounds version upgraded from `1` -> `3`
34
+ * Info version upgraded from `25` -> `31`
35
+ * Add more type safety:
36
+ * Translator results from `jsonToWar()` and `warToJson()` are now typed by `WarResult` and `JsonResult`, respectively
37
+ * `JsonResult` is generically typed to describe what it contains (e.g. `Sound[]`)
38
+ * Introduced new `angle` type, which is an alias for `number`; `angle`'s should always be specified in degrees, not radians
39
+ ## FIXES
40
+ * Resolve `[DEP0005] DeprecationWarning: Buffer()` warning in `HexBuffer.ts`
41
+ * Fix scoping issues on `*Translator.ts`, `HexBuffer.ts` and `W3Buffer.ts` where certain fields that should be `private` were marked as `public`
42
+ * Fix InfoTranslator reading random item table ID length as 1 instead of 4
43
+ * Fix potential null-terminator errors related to string or character-array fields
44
+ ## MAINTENANCE
45
+ * Upgrade to Node 14.x LTS
46
+ * Upgrade to npm 7.x
47
+ * Upgrade `round-to` 4.1.0 -> 5.0.0
48
+ * Upgrade `@types/fs-extra` 8.1.0 -> 9.0.7
49
+ * Upgrade `@types/mocha` 7.0.1 -> 8.2.1
50
+ * Upgrade `@types/node` 12.12.28 -> 14.14.31
51
+ * Upgrade `fs-extra` 8.1.0 -> 9.1.0
52
+ * Upgrade `mocha` 7.0.1 -> 8.3.0
53
+ * Upgrade `nyc` 15.0.0 -> 15.1.0
54
+ * Upgrade `ts-node` 8.6.2 -> 9.1.1
55
+ * Upgrade `tslint` 6.0.0 -> 6.1.3
56
+ * Upgrade `typescript` 3.8.2 -> 4.2.2
57
+ * The project structure has changed:
58
+ * `examples` sub-project directory is removed
59
+ * Refer to `USAGE.md` for how to use the code
60
+ * Add all contributors to `package.json`
61
+ * Resolve all security issues via `npm audit fix` (5 low, 1 high, 1 critical)
62
+ ## TESTING
63
+ * Travis CI will now use Node 14 LTS to build the project
64
+ * `test` directory now contains the WC3 and JSON data files the tests require
65
+ * Implement the StringsTranslator test
66
+ * Resolve all broken unit tests, most of them being reversion tests
67
+ <!--
68
+ # x.y.z (YYYY-MM-DD)
69
+ ## SUMMARY
70
+ **🔥 Breaking changes**
71
+ ## FEATURES
72
+ ## FIXES
73
+ ## MAINTENANCE
74
+ ## TESTING
75
+ -->
76
+
77
+ # Previous versions
78
+ 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.
package/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2020 ChiefOfGxBxL
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ ```
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ ```
package/README.md CHANGED
@@ -1,8 +1,17 @@
1
1
  <p align='center'>
2
- <b>WC3MapTranslator</b>
2
+ <b>WC3MapTranslator</b><br/>
3
+ Translate <code>war3map</code> ⇄ <code>json</code> formats for WarCraft III .w3x maps
3
4
  </p>
4
5
  <p align='center'>
5
- Translate <code>war3map</code> ⇄ <code>json</code> formats for WarCraft III .w3x maps
6
+ <a href='https://www.npmjs.com/package/wc3maptranslator'>
7
+ <img src='https://badge.fury.io/js/wc3maptranslator.svg?style=flat-square'/>
8
+ </a>
9
+ <a href='https://www.npmjs.com/package/wc3maptranslator'>
10
+ <img src='https://img.shields.io/npm/dt/wc3maptranslator.svg'/>
11
+ </a>
12
+ <a href='https://opensource.org/licenses/MIT'>
13
+ <img src='https://img.shields.io/badge/license-MIT-blue.svg'/>
14
+ </a>
6
15
 
7
16
  <p align='center'>
8
17
  <b>Quality</b><br/>
@@ -22,19 +31,7 @@
22
31
  <a href="https://snyk.io/test/github/chiefofgxbxl/wc3maptranslator?targetFile=package.json">
23
32
  <img src="https://snyk.io/test/github/chiefofgxbxl/wc3maptranslator/badge.svg?targetFile=package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/chiefofgxbxl/wc3maptranslator?targetFile=package.json" style="max-width:100%;">
24
33
  </a>
25
- <br/><br/>
26
- <b>Info</b><br/>
27
- <a href='https://www.npmjs.com/package/wc3maptranslator'>
28
- <img src='https://badge.fury.io/js/wc3maptranslator.svg?style=flat-square'/>
29
- </a>
30
- <a href='https://www.npmjs.com/package/wc3maptranslator'>
31
- <img src='https://img.shields.io/npm/dt/wc3maptranslator.svg'/>
32
- </a>
33
- <a href='https://opensource.org/licenses/MIT'>
34
- <img src='https://img.shields.io/badge/license-MIT-blue.svg'/>
35
- </a>
36
34
  </p>
37
-
38
35
  </p>
39
36
 
40
37
  <hr/>
@@ -42,7 +39,6 @@
42
39
  <a href="#overview"><strong>Overview</strong></a> &middot;
43
40
  <a href="#install"><strong>Install</strong></a> &middot;
44
41
  <a href="#usage"><strong>Usage</strong></a> &middot;
45
- <a href="#examples"><strong>Examples</strong></a> &middot;
46
42
  <a href="#file-support"><strong>File Support</strong></a> &middot;
47
43
  <a href="#specification"><strong>Specification</strong></a> &middot;
48
44
  <a href="#contributing"><strong>Contributing</strong></a> &middot;
@@ -51,66 +47,59 @@
51
47
  <hr/>
52
48
 
53
49
  ## Overview
54
- WC3MapTranslator is a module to convert a JSON representation of WarCraft III (.w3x) data to their `war3map` files, and vice-versa. This makes the map data readable and easily modifiable.
50
+ 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!
55
51
 
56
52
  ![TranslationExample](https://user-images.githubusercontent.com/4079034/71315302-4947fb00-2427-11ea-8f50-edf05d6e5c6a.png)
57
53
 
58
- WC3MapTranslator is written in `TypeScript` starting from version `3.0.0`, offering type safety and improved development experience.
59
-
60
54
  ## Install
61
55
  ```ts
62
56
  npm install wc3maptranslator
63
57
  ```
64
58
 
65
- **Requires Node >= 8**
66
- **Tested with tsc Version 3.7.2**
59
+ **Requires Node 14**
67
60
 
68
61
  ## Usage
69
- ### JavaScript (version < 3.0.0)
70
62
  ```ts
71
- var Translator = require('wc3maptranslator'),
72
- mapJson = { // Refer to "Specification"
73
- units: [...],
74
- doodads: [...],
75
- ...
76
- };
77
- var unitResult = new Translator.Units.jsonToWar(mapJson.units);
63
+ import {
64
+ CamerasTranslator,
65
+ DoodadsTranslator,
66
+ ImportsTranslator,
67
+ InfoTranslator,
68
+ ObjectsTranslator,
69
+ RegionsTranslator,
70
+ SoundsTranslator,
71
+ StringsTranslator,
72
+ TerrainTranslator,
73
+ UnitsTranslator
74
+ } from 'wc3maptranslator';
75
+
76
+ // E.g. let's create a camera for the map
77
+ const cameras = [
78
+ {
79
+ "target": {
80
+ "x": -319.01,
81
+ "y": -90.18
82
+ },
83
+ "offsetZ": 0,
84
+ "rotation": 90,
85
+ "aoa": 304,
86
+ "distance": 2657.34,
87
+ "roll": 5,
88
+ "fov": 70,
89
+ "farClipping": 5000,
90
+ "name": "MyCamera1"
91
+ }
92
+ ]
93
+
94
+ // Now translate the JSON into the WarCraft III format
95
+ // All translators have: `.jsonToWar` and `.warToJson` functions
96
+ const translatedResult = CamerasTranslator.jsonToWar(cameras);
97
+
98
+ // `translatedResult` contains a `buffer` which can be saved to disk
99
+ // This war3map.w3c file can now be placed inside a .w3x via an MPQ
100
+ // editor, and you should now see a camera in the Camera Palette!
101
+ fs.writeFileSync('war3map.w3c', translatedResult.buffer);
78
102
  ```
79
- ### TypeScript (version >= 3.0.0)
80
- ```js
81
- // JS import
82
- const TranslatorLib = require('wc3maptranslator');
83
- const Translator = new TranslatorLib();
84
- console.log(Translator);
85
- ```
86
- ```ts
87
- //... or TS import
88
- import { Translator } from 'wc3maptranslator';
89
- const myTranslator = new Translator();
90
- console.log(Translator);
91
- ```
92
- ### Using the Translator
93
- ```ts
94
- // e.g. unit translator
95
- const unitResult = new Translator.Units.jsonToWar(mapJson.units);
96
- // all:
97
- * Doodads
98
- * Strings
99
- * Terrain
100
- * Units
101
- * Regions
102
- * Cameras
103
- * Sounds
104
- * Objects
105
- * Imports
106
- * Info
107
- ```
108
- We can now write the `unitResult.buffer` content to a file named "war3mapUnits.doo" and put it in a .w3x archive! Using individual translators, we may convert JSON representation to generate a WC3 .w3x map file. See the Wiki for more information.
109
-
110
- ## Examples
111
- There is an `examples` directory that demonstrates how to use *each* translator, both for converting from war3map to JSON, and JSON to war3map formats. This is a great starting point to learn how to use any translator.
112
-
113
- To get started with either example, `cd` into `/examples/` and run `npm install` to install all the dependencies. Then run `npm start` which kicks off the TypeScript build and then executes the resulting JavaScript. A few output files will be written under the `/examples/` directory, but the output is purposely not comprehensive to avoid spamming the directory and because the translation process is sufficiently demonstrated using just one example of translating in each direction.
114
103
 
115
104
  ## File Support
116
105
 
@@ -157,25 +146,29 @@ To get started with either example, `cd` into `/examples/` and run `npm install`
157
146
  | Shadow map | ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) | ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) | war3map.shd |
158
147
 
159
148
 
160
- ### Not included
161
- ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) Custom Text Trigger File (war3map.wct)
162
- ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) Trigger Names File (war3map.wtg)
163
- ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) Menu Minimap (war3map.mmp)
164
- ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) Minimap Image (war3mapMap.blp)
165
- ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) Minimap Image (war3mapMap.b00
166
- ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) Minimap Image (war3mapMap.tga)
167
- ![times](https://cloud.githubusercontent.com/assets/4079034/25298707/7a883642-26c5-11e7-841c-cd3eb1425461.png) Map Preview Image (war3mapPreview.tga)
149
+ ### Not relevant
150
+ ![minus-solid](https://user-images.githubusercontent.com/4079034/108644014-16f6bb00-747b-11eb-8c2b-9e7a1d7b6f9b.png) Custom Text Trigger File (war3map.wct)
151
+ ![minus-solid](https://user-images.githubusercontent.com/4079034/108644014-16f6bb00-747b-11eb-8c2b-9e7a1d7b6f9b.png) Trigger Names File (war3map.wtg)
152
+ ![minus-solid](https://user-images.githubusercontent.com/4079034/108644014-16f6bb00-747b-11eb-8c2b-9e7a1d7b6f9b.png) Menu Minimap (war3map.mmp)
153
+ ![minus-solid](https://user-images.githubusercontent.com/4079034/108644014-16f6bb00-747b-11eb-8c2b-9e7a1d7b6f9b.png) Minimap Image (war3mapMap.blp)
154
+ ![minus-solid](https://user-images.githubusercontent.com/4079034/108644014-16f6bb00-747b-11eb-8c2b-9e7a1d7b6f9b.png) Minimap Image (war3mapMap.b00
155
+ ![minus-solid](https://user-images.githubusercontent.com/4079034/108644014-16f6bb00-747b-11eb-8c2b-9e7a1d7b6f9b.png) Minimap Image (war3mapMap.tga)
156
+ ![minus-solid](https://user-images.githubusercontent.com/4079034/108644014-16f6bb00-747b-11eb-8c2b-9e7a1d7b6f9b.png) Map Preview Image (war3mapPreview.tga)
168
157
 
169
158
  ## Specification
170
- We have a detailed [specification on our Wiki](https://github.com/ChiefOfGxBxL/WC3MapTranslator/wiki) 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.
159
+ ### WC3MapTranslator format
160
+ 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.
161
+ > 🔗 [WC3MapTranslator format](https://github.com/ChiefOfGxBxL/WC3MapTranslator/wiki)
171
162
 
172
- The underlying WarCraft map files (e.g. war3map.doo) have been documented [on our Wiki](https://github.com/ChiefOfGxBxL/WC3MapTranslator/wiki) as well. If you are curious about how a .w3x file is composed, this is the place to learn!
163
+ ### war3map format
164
+ 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!
165
+ > 🔗 [WC3MapSpecification](https://github.com/ChiefOfGxBxL/WC3MapSpecification)
173
166
 
174
167
  ## Contributing
175
168
  We encourage contributions! Generally, the process of making a change is:
176
169
  1. Fork this repo
177
170
  2. Develop your changes on a new branch
178
- 3. Submit a pull request to `master`
171
+ 3. Submit a pull request to `dev`
179
172
 
180
173
  **Your code should**:
181
174
  * **run** (your code needs to work, of course)
@@ -183,7 +176,7 @@ We encourage contributions! Generally, the process of making a change is:
183
176
  * **be linted** (run `npm run lint` and follow the project's coding standards)
184
177
  * **pass CI** (we enforce: ESLint, unit tests pass, code coverage)
185
178
 
186
- A code review is required on your PR to be accepted into `master`. 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.
179
+ 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.
187
180
 
188
181
  ## Special Thanks
189
182
  We owe a lot of thanks to *Chocobo* on [TheHelper](http://www.thehelper.net/) for the detailed documentation of the files found in a .w3x archive. Two tutorials are [here (1)](http://www.thehelper.net/threads/guide-explanation-of-w3m-and-w3x-files.35292/) and [here (2)](http://world-editor-tutorials.thehelper.net/cat_usersubmit.php?view=42787).
package/index.js CHANGED
@@ -1,19 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnitsTranslator = exports.TerrainTranslator = exports.StringsTranslator = exports.SoundsTranslator = exports.RegionsTranslator = exports.ObjectsTranslator = exports.InfoTranslator = exports.ImportsTranslator = exports.DoodadsTranslator = exports.CamerasTranslator = void 0;
3
4
  const translators_1 = require("./lib/translators");
4
- class Translator {
5
- constructor() {
6
- this.Doodads = new translators_1.DoodadsTranslator();
7
- this.Strings = new translators_1.StringsTranslator();
8
- this.Terrain = new translators_1.TerrainTranslator();
9
- this.Units = new translators_1.UnitsTranslator();
10
- this.Regions = new translators_1.RegionsTranslator();
11
- this.Cameras = new translators_1.CamerasTranslator();
12
- this.Sounds = new translators_1.SoundsTranslator();
13
- this.Objects = new translators_1.ObjectsTranslator();
14
- this.Imports = new translators_1.ImportsTranslator();
15
- this.Info = new translators_1.InfoTranslator();
16
- }
17
- }
18
- exports.Translator = Translator;
5
+ Object.defineProperty(exports, "CamerasTranslator", { enumerable: true, get: function () { return translators_1.CamerasTranslator; } });
6
+ Object.defineProperty(exports, "DoodadsTranslator", { enumerable: true, get: function () { return translators_1.DoodadsTranslator; } });
7
+ Object.defineProperty(exports, "ImportsTranslator", { enumerable: true, get: function () { return translators_1.ImportsTranslator; } });
8
+ Object.defineProperty(exports, "InfoTranslator", { enumerable: true, get: function () { return translators_1.InfoTranslator; } });
9
+ Object.defineProperty(exports, "ObjectsTranslator", { enumerable: true, get: function () { return translators_1.ObjectsTranslator; } });
10
+ Object.defineProperty(exports, "RegionsTranslator", { enumerable: true, get: function () { return translators_1.RegionsTranslator; } });
11
+ Object.defineProperty(exports, "SoundsTranslator", { enumerable: true, get: function () { return translators_1.SoundsTranslator; } });
12
+ Object.defineProperty(exports, "StringsTranslator", { enumerable: true, get: function () { return translators_1.StringsTranslator; } });
13
+ Object.defineProperty(exports, "TerrainTranslator", { enumerable: true, get: function () { return translators_1.TerrainTranslator; } });
14
+ Object.defineProperty(exports, "UnitsTranslator", { enumerable: true, get: function () { return translators_1.UnitsTranslator; } });
19
15
  //# sourceMappingURL=index.js.map
package/index.ts CHANGED
@@ -1,32 +1,14 @@
1
1
  import { CamerasTranslator, DoodadsTranslator, ImportsTranslator, InfoTranslator, ObjectsTranslator, RegionsTranslator, SoundsTranslator, StringsTranslator, TerrainTranslator, UnitsTranslator } from './lib/translators';
2
2
 
3
- export class Translator {
4
-
5
- public Doodads: DoodadsTranslator;
6
- public Strings: StringsTranslator;
7
- public Terrain: TerrainTranslator;
8
- public Units: UnitsTranslator;
9
- public Regions: RegionsTranslator;
10
- public Cameras: CamerasTranslator;
11
- public Sounds: SoundsTranslator;
12
-
13
- public Objects: ObjectsTranslator;
14
-
15
- public Imports: ImportsTranslator;
16
- public Info: InfoTranslator;
17
-
18
- constructor() {
19
- this.Doodads = new DoodadsTranslator();
20
- this.Strings = new StringsTranslator();
21
- this.Terrain = new TerrainTranslator();
22
- this.Units = new UnitsTranslator();
23
- this.Regions = new RegionsTranslator();
24
- this.Cameras = new CamerasTranslator();
25
- this.Sounds = new SoundsTranslator();
26
-
27
- this.Objects = new ObjectsTranslator();
28
-
29
- this.Imports = new ImportsTranslator();
30
- this.Info = new InfoTranslator();
31
- }
32
- }
3
+ export {
4
+ CamerasTranslator,
5
+ DoodadsTranslator,
6
+ ImportsTranslator,
7
+ InfoTranslator,
8
+ ObjectsTranslator,
9
+ RegionsTranslator,
10
+ SoundsTranslator,
11
+ StringsTranslator,
12
+ TerrainTranslator,
13
+ UnitsTranslator
14
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @type angle - An angle is measured in degrees, 0 <= angle < 360
3
+ */
4
+ export type angle = number;
5
+
6
+ // TranslationError is reserved for future use in case
7
+ // additional constraints are added to translated output,
8
+ // like if WC3 has maximum string lengths, or if certain
9
+ // values must be in a specific range
10
+ export interface TranslationError {
11
+ message: string
12
+ }
13
+
14
+ export interface WarResult {
15
+ buffer: Buffer,
16
+ errors?: TranslationError[]
17
+ }
18
+
19
+ export interface JsonResult<T = object> {
20
+ json: T,
21
+ errors?: TranslationError[]
22
+ }
package/lib/HexBuffer.ts CHANGED
@@ -17,9 +17,9 @@ const ieee754 = require('ieee754'),
17
17
  };
18
18
 
19
19
  export class HexBuffer {
20
- public _buffer = [];
20
+ private _buffer = [];
21
21
 
22
- public addString(str: string, isNullTerminated = false) {
22
+ public addString(str: string) {
23
23
  // Write each char to the buffer
24
24
  // "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2"
25
25
  // | "ucs-2" | "base64" | "latin1" | "binary" | "hex"
@@ -28,10 +28,7 @@ export class HexBuffer {
28
28
  for (let i = 0; i < buf.length; i++) {
29
29
  this._buffer.push('0x' + buf[i].toString(16));
30
30
  }
31
-
32
- if (isNullTerminated) {
33
- this.addNullTerminator();
34
- }
31
+ this.addNullTerminator();
35
32
  }
36
33
 
37
34
  public addNewLine() {
@@ -43,6 +40,12 @@ export class HexBuffer {
43
40
  this._buffer.push(charToHex(char));
44
41
  }
45
42
 
43
+ public addChars(chars: string) {
44
+ chars.split('').forEach(char => {
45
+ this.addChar(char);
46
+ });
47
+ }
48
+
46
49
  public addInt(int: number, isShort: boolean = false) {
47
50
  intToHex(int, isShort).forEach((Byte) => {
48
51
  this._buffer.push(Byte);
@@ -54,7 +57,7 @@ export class HexBuffer {
54
57
  }
55
58
 
56
59
  public addFloat(float: number) {
57
- const buf = new Buffer(4);
60
+ const buf = Buffer.alloc(4);
58
61
 
59
62
  // ieee754.write(buffer, value, buffer offset, little-endian, mantissa length, bytes);
60
63
  ieee754.write(buf, float, 0, true, 23, 4);
@@ -64,16 +67,10 @@ export class HexBuffer {
64
67
  });
65
68
  }
66
69
 
67
- public addByte(byte: number) {
70
+ public addByte(byte) {
68
71
  this._buffer.push('0x' + byte.toString(16));
69
72
  }
70
73
 
71
- public addBytes(bytes: number[]) {
72
- for (const byte of bytes) {
73
- this.addByte(byte);
74
- }
75
- }
76
-
77
74
  public addNullTerminator() {
78
75
  this._buffer.push('0x0');
79
76
  }
package/lib/W3Buffer.ts CHANGED
@@ -2,8 +2,8 @@ import roundTo from 'round-to';
2
2
 
3
3
  export class W3Buffer {
4
4
 
5
- public _offset = 0;
6
- public _buffer: Buffer;
5
+ private _offset = 0;
6
+ private _buffer: Buffer;
7
7
 
8
8
  constructor(buffer: Buffer) {
9
9
  this._buffer = buffer;
@@ -43,7 +43,7 @@ export class W3Buffer {
43
43
 
44
44
  public readChars(len: number = 1): string {
45
45
  const string = [];
46
- const numCharsToRead = len;
46
+ const numCharsToRead = len || 1;
47
47
 
48
48
  for (let i = 0; i < numCharsToRead; i++) {
49
49
  string.push(this._buffer[this._offset]);
@@ -62,4 +62,8 @@ export class W3Buffer {
62
62
  this._offset += 1;
63
63
  return byte;
64
64
  }
65
+
66
+ public isExhausted(): boolean {
67
+ return this._offset === this._buffer.length;
68
+ }
65
69
  }