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/examples/index.js DELETED
@@ -1,123 +0,0 @@
1
- "use strict";
2
- /**
3
- * WC3MapTranslator examples using TypeScript
4
- *
5
- * Learn how to translate between JSON and war3map
6
- * formats using the TypeScript library.
7
- *
8
- * To use regular JavaScript, `import`s need to be changed
9
- * to `require()`s, and you'd build WC3MapTranslator and
10
- * require the `index.js` file instead of the .ts one.
11
- */
12
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- // Import the translator class - in your own code
17
- // you'd want to `npm install wc3maptranslator` and
18
- // then import it from node_modules. These examples
19
- // load from '../index' to avoid versioning issues.
20
- const index_1 = require("../index");
21
- // NodeJS file system library for writing output files
22
- const fs_1 = __importDefault(require("fs"));
23
- // Define the translators to be used. We'll demonstrate
24
- // how to use all of them, but your use-case may vary,
25
- // so there may not be a need to define all of them.
26
- const UnitsTranslator = new index_1.Translator().Units;
27
- const DoodadsTranslator = new index_1.Translator().Doodads;
28
- const TerrainTranslator = new index_1.Translator().Terrain;
29
- const RegionsTranslator = new index_1.Translator().Regions;
30
- const CamerasTranslator = new index_1.Translator().Cameras;
31
- const SoundsTranslator = new index_1.Translator().Sounds;
32
- const ObjectsTranslator = new index_1.Translator().Objects;
33
- const ImportsTranslator = new index_1.Translator().Imports;
34
- const InfoTranslator = new index_1.Translator().Info;
35
- const StringsTranslator = new index_1.Translator().Strings;
36
- /* * * * * * * * * * * * * * *
37
- * *
38
- * JSON --> War3map *
39
- * *
40
- * * * * * * * * * * * * * * */
41
- // Taking JSON and converting it into the war3map format is easy!
42
- // Just use the appropriate translator to call `.jsonToWar()`,
43
- // providing the JSON input. Here, the JSON is saved in a subdirectory,
44
- // and NodeJS can read in JSON using `require()` with the path.
45
- //
46
- // The `.jsonToWar()` function returns an object containing:
47
- // * buffer (Buffer)
48
- // * errors (array)
49
- // The `buffer` contains the data you'll write to a war3map file,
50
- // and `errors` is an array of errors in case the JSON is incorrect.
51
- const unitResults = UnitsTranslator.jsonToWar(require('./json/units.json'));
52
- DoodadsTranslator.jsonToWar(require('./json/doodads.json'));
53
- TerrainTranslator.jsonToWar(require('./json/terrain.json'));
54
- RegionsTranslator.jsonToWar(require('./json/regions.json'));
55
- CamerasTranslator.jsonToWar(require('./json/cameras.json'));
56
- SoundsTranslator.jsonToWar(require('./json/sounds.json'));
57
- ImportsTranslator.jsonToWar(require('./json/imports.json'));
58
- InfoTranslator.jsonToWar(require('./json/info.json'));
59
- StringsTranslator.jsonToWar(require('./json/strings.json'));
60
- // The ObjectTranslator `.jsonToWar()` function needs to be given the
61
- // type of object it is translating, e.g. units, items, buffs, etc.
62
- // This is done by using the ObjectType enum under the ObjectsTranslator
63
- // instance.
64
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Units, require('./json/object-units.json'));
65
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Items, require('./json/object-items.json'));
66
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Destructables, require('./json/object-destructables.json'));
67
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Doodads, require('./json/object-doodads.json'));
68
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Abilities, require('./json/object-abilities.json'));
69
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Buffs, require('./json/object-buffs.json'));
70
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Upgrades, require('./json/object-upgrades.json'));
71
- // Above you learned how easy it is to use the `.jsonToWar()` function
72
- // to get an output buffer in the war3map format. Now all we have to
73
- // do is save the buffer to a file. This is the file you'd put into
74
- // a .w3x WarCraft III map file (e.g. using an MPQ Editor). You may
75
- // also consider using an asynchronous method for performance.
76
- fs_1.default.writeFileSync('war3mapUnits.doo', unitResults.buffer);
77
- // `war3mapUnits.doo` is the file name that WC3 uses for units that
78
- // are placed on the map (not to be confused with `war3map.w3u`, which
79
- // is for units defined in the object editor).
80
- // Now that you know how to write the buffer results from the `.jsonToWar()`
81
- // function, give it a try on some other files! Then use an MPQ Editor
82
- // to drag and drop the war3map files into a map and check it out using
83
- // World Editor!
84
- /* * * * * * * * * * * * * * *
85
- * *
86
- * War3map --> JSON *
87
- * *
88
- * * * * * * * * * * * * * * */
89
- // Now that you're familiar with how to convert JSON to war3map
90
- // as detailed above, converting war3map files to JSON is easy!
91
- // The only difference is that we'll use the `.warToJson()` function,
92
- // and what it returns will be:
93
- // * json (object)
94
- // * errors (array)
95
- // so we have JSON instead of a buffer.
96
- UnitsTranslator.warToJson(fs_1.default.readFileSync('./war/war3mapUnits.doo'));
97
- DoodadsTranslator.warToJson(fs_1.default.readFileSync('./war/war3map.doo'));
98
- TerrainTranslator.warToJson(fs_1.default.readFileSync('./war/war3map.w3e'));
99
- // Regions, Cameras, Sounds, Imports, Info, and Strings have purposely
100
- // been omitted for learning. The process is the same as the above lines.
101
- // Give it a try!
102
- // Moving on to translating object editor data from war3map to JSON format:
103
- ObjectsTranslator.warToJson(ObjectsTranslator.ObjectType.Units, fs_1.default.readFileSync('./war/war3map.w3u'));
104
- const objectItemsResult = ObjectsTranslator.warToJson(ObjectsTranslator.ObjectType.Items, fs_1.default.readFileSync('./war/war3map.w3t'));
105
- ObjectsTranslator.warToJson(ObjectsTranslator.ObjectType.Destructables, fs_1.default.readFileSync('./war/war3map.w3b'));
106
- // Note that the object translation examples for Doodads, Abilities, Buffs
107
- // and Upgrades have purposely been omitted for learning. Try your hand at
108
- // using the ObjectsTranslator to translate the files in the `./war` directory
109
- // into JSON format!
110
- // For file names and extensions, see: https://github.com/ChiefOfGxBxL/WC3MapTranslator#file-support
111
- // We can use the result of `.warToJson()` to save our JSON file:
112
- // Caution: the value in `.json` might yield [object Object]
113
- // depending on where you're printing or saving it, because that is the
114
- // default .toString() representation of JSON. You'll want to stringify
115
- // the JSON to get the actual readable format.
116
- fs_1.default.writeFileSync('objectEditorItems.json', JSON.stringify(objectItemsResult.json, null, 4));
117
- console.info('\n[v] [WC3MapTranslator examples]');
118
- console.info(' Demonstrates how to translate between JSON and war3map');
119
- console.info(' ✔ Success! Output files written to ./examples/');
120
- console.info(' * war3mapUnits.doo');
121
- console.info(' * objectEditorItems.json');
122
- console.info('[^] [WC3MapTranslator examples]\n');
123
- //# sourceMappingURL=index.js.map
package/examples/index.ts DELETED
@@ -1,134 +0,0 @@
1
- /**
2
- * WC3MapTranslator examples using TypeScript
3
- *
4
- * Learn how to translate between JSON and war3map
5
- * formats using the TypeScript library.
6
- *
7
- * To use regular JavaScript, `import`s need to be changed
8
- * to `require()`s, and you'd build WC3MapTranslator and
9
- * require the `index.js` file instead of the .ts one.
10
- */
11
-
12
- // Import the translator class - in your own code
13
- // you'd want to `npm install wc3maptranslator` and
14
- // then import it from node_modules. These examples
15
- // load from '../index' to avoid versioning issues.
16
- import { Translator } from '../index';
17
-
18
- // NodeJS file system library for writing output files
19
- import fs from 'fs';
20
-
21
- // Define the translators to be used. We'll demonstrate
22
- // how to use all of them, but your use-case may vary,
23
- // so there may not be a need to define all of them.
24
- const UnitsTranslator = new Translator().Units;
25
- const DoodadsTranslator = new Translator().Doodads;
26
- const TerrainTranslator = new Translator().Terrain;
27
- const RegionsTranslator = new Translator().Regions;
28
- const CamerasTranslator = new Translator().Cameras;
29
- const SoundsTranslator = new Translator().Sounds;
30
- const ObjectsTranslator = new Translator().Objects;
31
- const ImportsTranslator = new Translator().Imports;
32
- const InfoTranslator = new Translator().Info;
33
- const StringsTranslator = new Translator().Strings;
34
-
35
- /* * * * * * * * * * * * * * *
36
- * *
37
- * JSON --> War3map *
38
- * *
39
- * * * * * * * * * * * * * * */
40
-
41
- // Taking JSON and converting it into the war3map format is easy!
42
- // Just use the appropriate translator to call `.jsonToWar()`,
43
- // providing the JSON input. Here, the JSON is saved in a subdirectory,
44
- // and NodeJS can read in JSON using `require()` with the path.
45
- //
46
- // The `.jsonToWar()` function returns an object containing:
47
- // * buffer (Buffer)
48
- // * errors (array)
49
- // The `buffer` contains the data you'll write to a war3map file,
50
- // and `errors` is an array of errors in case the JSON is incorrect.
51
- const unitResults = UnitsTranslator.jsonToWar(require('./json/units.json'));
52
- DoodadsTranslator.jsonToWar(require('./json/doodads.json'));
53
- TerrainTranslator.jsonToWar(require('./json/terrain.json'));
54
- RegionsTranslator.jsonToWar(require('./json/regions.json'));
55
- CamerasTranslator.jsonToWar(require('./json/cameras.json'));
56
- SoundsTranslator.jsonToWar(require('./json/sounds.json'));
57
- ImportsTranslator.jsonToWar(require('./json/imports.json'));
58
- InfoTranslator.jsonToWar(require('./json/info.json'));
59
- StringsTranslator.jsonToWar(require('./json/strings.json'));
60
-
61
- // The ObjectTranslator `.jsonToWar()` function needs to be given the
62
- // type of object it is translating, e.g. units, items, buffs, etc.
63
- // This is done by using the ObjectType enum under the ObjectsTranslator
64
- // instance.
65
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Units, require('./json/object-units.json'));
66
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Items, require('./json/object-items.json'));
67
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Destructables, require('./json/object-destructables.json'));
68
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Doodads, require('./json/object-doodads.json'));
69
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Abilities, require('./json/object-abilities.json'));
70
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Buffs, require('./json/object-buffs.json'));
71
- ObjectsTranslator.jsonToWar(ObjectsTranslator.ObjectType.Upgrades, require('./json/object-upgrades.json'));
72
-
73
- // Above you learned how easy it is to use the `.jsonToWar()` function
74
- // to get an output buffer in the war3map format. Now all we have to
75
- // do is save the buffer to a file. This is the file you'd put into
76
- // a .w3x WarCraft III map file (e.g. using an MPQ Editor). You may
77
- // also consider using an asynchronous method for performance.
78
- fs.writeFileSync('war3mapUnits.doo', unitResults.buffer);
79
-
80
- // `war3mapUnits.doo` is the file name that WC3 uses for units that
81
- // are placed on the map (not to be confused with `war3map.w3u`, which
82
- // is for units defined in the object editor).
83
-
84
- // Now that you know how to write the buffer results from the `.jsonToWar()`
85
- // function, give it a try on some other files! Then use an MPQ Editor
86
- // to drag and drop the war3map files into a map and check it out using
87
- // World Editor!
88
-
89
- /* * * * * * * * * * * * * * *
90
- * *
91
- * War3map --> JSON *
92
- * *
93
- * * * * * * * * * * * * * * */
94
-
95
- // Now that you're familiar with how to convert JSON to war3map
96
- // as detailed above, converting war3map files to JSON is easy!
97
-
98
- // The only difference is that we'll use the `.warToJson()` function,
99
- // and what it returns will be:
100
- // * json (object)
101
- // * errors (array)
102
- // so we have JSON instead of a buffer.
103
- UnitsTranslator.warToJson(fs.readFileSync('./war/war3mapUnits.doo'));
104
- DoodadsTranslator.warToJson(fs.readFileSync('./war/war3map.doo'));
105
- TerrainTranslator.warToJson(fs.readFileSync('./war/war3map.w3e'));
106
-
107
- // Regions, Cameras, Sounds, Imports, Info, and Strings have purposely
108
- // been omitted for learning. The process is the same as the above lines.
109
- // Give it a try!
110
-
111
- // Moving on to translating object editor data from war3map to JSON format:
112
- ObjectsTranslator.warToJson(ObjectsTranslator.ObjectType.Units, fs.readFileSync('./war/war3map.w3u'));
113
- const objectItemsResult = ObjectsTranslator.warToJson(ObjectsTranslator.ObjectType.Items, fs.readFileSync('./war/war3map.w3t'));
114
- ObjectsTranslator.warToJson(ObjectsTranslator.ObjectType.Destructables, fs.readFileSync('./war/war3map.w3b'));
115
-
116
- // Note that the object translation examples for Doodads, Abilities, Buffs
117
- // and Upgrades have purposely been omitted for learning. Try your hand at
118
- // using the ObjectsTranslator to translate the files in the `./war` directory
119
- // into JSON format!
120
- // For file names and extensions, see: https://github.com/ChiefOfGxBxL/WC3MapTranslator#file-support
121
-
122
- // We can use the result of `.warToJson()` to save our JSON file:
123
- // Caution: the value in `.json` might yield [object Object]
124
- // depending on where you're printing or saving it, because that is the
125
- // default .toString() representation of JSON. You'll want to stringify
126
- // the JSON to get the actual readable format.
127
- fs.writeFileSync('objectEditorItems.json', JSON.stringify(objectItemsResult.json, null, 4));
128
-
129
- console.info('\n[v] [WC3MapTranslator examples]');
130
- console.info(' Demonstrates how to translate between JSON and war3map');
131
- console.info(' ✔ Success! Output files written to ./examples/');
132
- console.info(' * war3mapUnits.doo');
133
- console.info(' * objectEditorItems.json');
134
- console.info('[^] [WC3MapTranslator examples]\n');
@@ -1,16 +0,0 @@
1
- [
2
- {
3
- "target": {
4
- "x": 77.53,
5
- "y": 428.42
6
- },
7
- "offsetZ": 0,
8
- "rotation": 90,
9
- "aoa": 304,
10
- "distance": 4707.64,
11
- "roll": 0,
12
- "fov": 70,
13
- "farClipping": 6050,
14
- "name": "StartingCamera"
15
- }
16
- ]