wc3maptranslator 4.0.1 → 4.0.3

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 (117) hide show
  1. package/dist/src/AngleConverter.d.ts +3 -0
  2. package/dist/src/AngleConverter.d.ts.map +1 -0
  3. package/dist/src/AngleConverter.js +12 -0
  4. package/dist/src/AngleConverter.js.map +1 -0
  5. package/dist/src/CommonInterfaces.d.ts +17 -0
  6. package/dist/src/CommonInterfaces.d.ts.map +1 -0
  7. package/dist/src/CommonInterfaces.js +3 -0
  8. package/dist/src/CommonInterfaces.js.map +1 -0
  9. package/dist/src/HexBuffer.d.ts +15 -0
  10. package/dist/src/HexBuffer.d.ts.map +1 -0
  11. package/{lib/HexBuffer.ts → dist/src/HexBuffer.js} +32 -42
  12. package/dist/src/HexBuffer.js.map +1 -0
  13. package/dist/src/W3Buffer.d.ts +14 -0
  14. package/dist/src/W3Buffer.d.ts.map +1 -0
  15. package/{lib/W3Buffer.ts → dist/src/W3Buffer.js} +25 -31
  16. package/dist/src/W3Buffer.js.map +1 -0
  17. package/dist/src/index.d.ts +3 -0
  18. package/dist/src/index.d.ts.map +1 -0
  19. package/{index.js → dist/src/index.js} +1 -1
  20. package/dist/src/index.js.map +1 -0
  21. package/dist/src/translators/CamerasTranslator.d.ts +23 -0
  22. package/dist/src/translators/CamerasTranslator.d.ts.map +1 -0
  23. package/{lib/translators/CamerasTranslator.ts → dist/src/translators/CamerasTranslator.js} +14 -39
  24. package/dist/src/translators/CamerasTranslator.js.map +1 -0
  25. package/dist/src/translators/DoodadsTranslator.d.ts +23 -0
  26. package/dist/src/translators/DoodadsTranslator.d.ts.map +1 -0
  27. package/{lib/translators/DoodadsTranslator.ts → dist/src/translators/DoodadsTranslator.js} +33 -65
  28. package/dist/src/translators/DoodadsTranslator.js.map +1 -0
  29. package/dist/src/translators/ImportsTranslator.d.ts +16 -0
  30. package/dist/src/translators/ImportsTranslator.d.ts.map +1 -0
  31. package/{lib/translators/ImportsTranslator.ts → dist/src/translators/ImportsTranslator.js} +21 -37
  32. package/dist/src/translators/ImportsTranslator.js.map +1 -0
  33. package/dist/src/translators/InfoTranslator.d.ts +124 -0
  34. package/dist/src/translators/InfoTranslator.d.ts.map +1 -0
  35. package/{lib/translators/InfoTranslator.ts → dist/src/translators/InfoTranslator.js} +108 -270
  36. package/dist/src/translators/InfoTranslator.js.map +1 -0
  37. package/dist/src/translators/ObjectsTranslator.d.ts +23 -0
  38. package/dist/src/translators/ObjectsTranslator.d.ts.map +1 -0
  39. package/{lib/translators/ObjectsTranslator.ts → dist/src/translators/ObjectsTranslator.js} +91 -125
  40. package/dist/src/translators/ObjectsTranslator.js.map +1 -0
  41. package/dist/src/translators/RegionsTranslator.d.ts +22 -0
  42. package/dist/src/translators/RegionsTranslator.d.ts.map +1 -0
  43. package/{lib/translators/RegionsTranslator.ts → dist/src/translators/RegionsTranslator.js} +18 -45
  44. package/dist/src/translators/RegionsTranslator.js.map +1 -0
  45. package/dist/src/translators/SoundsTranslator.d.ts +35 -0
  46. package/dist/src/translators/SoundsTranslator.d.ts.map +1 -0
  47. package/{lib/translators/SoundsTranslator.ts → dist/src/translators/SoundsTranslator.js} +30 -84
  48. package/dist/src/translators/SoundsTranslator.js.map +1 -0
  49. package/dist/src/translators/StringsTranslator.d.ts +7 -0
  50. package/dist/src/translators/StringsTranslator.d.ts.map +1 -0
  51. package/{lib/translators/StringsTranslator.ts → dist/src/translators/StringsTranslator.js} +12 -17
  52. package/dist/src/translators/StringsTranslator.js.map +1 -0
  53. package/dist/src/translators/TerrainTranslator.d.ts +33 -0
  54. package/dist/src/translators/TerrainTranslator.d.ts.map +1 -0
  55. package/{lib/translators/TerrainTranslator.ts → dist/src/translators/TerrainTranslator.js} +29 -84
  56. package/dist/src/translators/TerrainTranslator.js.map +1 -0
  57. package/dist/src/translators/UnitsTranslator.d.ts +40 -0
  58. package/dist/src/translators/UnitsTranslator.d.ts.map +1 -0
  59. package/{lib/translators/UnitsTranslator.ts → dist/src/translators/UnitsTranslator.js} +33 -95
  60. package/dist/src/translators/UnitsTranslator.js.map +1 -0
  61. package/{lib/translators/index.ts → dist/src/translators/index.d.ts} +1 -0
  62. package/dist/src/translators/index.d.ts.map +1 -0
  63. package/dist/src/translators/index.js +23 -0
  64. package/dist/src/translators/index.js.map +1 -0
  65. package/package.json +5 -4
  66. package/.codeclimate.yml +0 -12
  67. package/.editorconfig +0 -8
  68. package/.eslintignore +0 -5
  69. package/.eslintrc +0 -55
  70. package/.github/workflows/codeql-analysis.yml +0 -54
  71. package/.nycrc +0 -18
  72. package/.travis.yml +0 -23
  73. package/CHANGELOG.md +0 -78
  74. package/index.ts +0 -14
  75. package/lib/AngleConverter.ts +0 -7
  76. package/lib/CommonInterfaces.ts +0 -22
  77. package/test/.mocharc.json +0 -4
  78. package/test/AngleConverterTest.ts +0 -18
  79. package/test/HexBufferTest.ts +0 -170
  80. package/test/TranslatorReversion.ts +0 -218
  81. package/test/W3BufferTest.ts +0 -50
  82. package/test/data/cameras.json +0 -16
  83. package/test/data/doodads.json +0 -2730
  84. package/test/data/imports.json +0 -386
  85. package/test/data/info.json +0 -250
  86. package/test/data/obj-abilities.json +0 -4892
  87. package/test/data/obj-buffs.json +0 -38
  88. package/test/data/obj-destructables.json +0 -31
  89. package/test/data/obj-doodads.json +0 -38
  90. package/test/data/obj-items.json +0 -31
  91. package/test/data/obj-units.json +0 -40
  92. package/test/data/obj-upgrades.json +0 -38
  93. package/test/data/regions.json +0 -206
  94. package/test/data/sounds.json +0 -50
  95. package/test/data/strings.json +0 -115
  96. package/test/data/terrain.json +0 -1
  97. package/test/data/units.json +0 -452
  98. package/test/data/war3map.doo +0 -0
  99. package/test/data/war3map.imp +0 -0
  100. package/test/data/war3map.j +0 -3442
  101. package/test/data/war3map.shd +0 -0
  102. package/test/data/war3map.w3a +0 -0
  103. package/test/data/war3map.w3b +0 -0
  104. package/test/data/war3map.w3c +0 -0
  105. package/test/data/war3map.w3d +0 -0
  106. package/test/data/war3map.w3e +0 -0
  107. package/test/data/war3map.w3h +0 -0
  108. package/test/data/war3map.w3i +0 -0
  109. package/test/data/war3map.w3q +0 -0
  110. package/test/data/war3map.w3r +0 -0
  111. package/test/data/war3map.w3s +0 -0
  112. package/test/data/war3map.w3t +0 -0
  113. package/test/data/war3map.w3u +0 -0
  114. package/test/data/war3map.wts +0 -631
  115. package/test/data/war3mapUnits.doo +0 -0
  116. package/tsconfig.json +0 -25
  117. package/tslint.json +0 -47
@@ -1,231 +1,111 @@
1
- import { HexBuffer } from '../HexBuffer';
2
- import { W3Buffer } from '../W3Buffer';
3
- import { WarResult, JsonResult } from '../CommonInterfaces'
4
-
5
- interface Map {
6
- name: string;
7
- author: string;
8
- description: string;
9
- recommendedPlayers: string;
10
- playableArea: PlayableMapArea;
11
- flags: MapFlags;
12
- mainTileType: string;
13
- }
14
-
15
- interface GameVersion {
16
- major: number;
17
- minor: number;
18
- patch: number;
19
- build: number;
20
- }
21
-
22
- interface Camera {
23
- bounds: number[];
24
- complements: number[];
25
- }
26
-
27
- interface MapFlags {
28
- hideMinimapInPreview: boolean; // 0x0001: 1=hide minimap in preview screens
29
- modifyAllyPriorities: boolean; // 0x0002: 1=modify ally priorities
30
- isMeleeMap: boolean; // 0x0004: 1=melee map
31
- // 0x0008: 1=playable map size was large and has never been reduced to medium (?)
32
- maskedPartiallyVisible: boolean; // 0x0010: 1=masked area are partially visible
33
- fixedPlayerSetting: boolean; // 0x0020: 1=fixed player setting for custom forces
34
- useCustomForces: boolean; // 0x0040: 1=use custom forces
35
- useCustomTechtree: boolean; // 0x0080: 1=use custom techtree
36
- useCustomAbilities: boolean; // 0x0100: 1=use custom abilities
37
- useCustomUpgrades: boolean; // 0x0200: 1=use custom upgrades
38
- // 0x0400: 1=map properties menu opened at least once since map creation (?)
39
- waterWavesOnCliffShores: boolean; // 0x0800: 1=show water waves on cliff shores
40
- waterWavesOnRollingShores: boolean; // 0x1000: 1=show water waves on rolling shores
41
- // 0x2000: 1=unknown
42
- // 0x4000: 1=unknown
43
- useItemClassificationSystem: boolean; // 0x8000: 1=use item classification system
44
- enableWaterTinting: boolean; // 0x10000
45
- useAccurateProbabilityForCalculations: boolean; // 0x20000
46
- useCustomAbilitySkins: boolean; // 0x40000
47
- }
48
-
49
- interface LoadingScreen {
50
- background: number;
51
- path: string;
52
- text: string;
53
- title: string;
54
- subtitle: string;
55
- }
56
-
57
- enum FogType {
58
- Linear = 0,
59
- Exponential1 = 1,
60
- Exponential2 = 2
61
- }
62
-
63
- interface Fog {
64
- type: FogType;
65
- startHeight: number;
66
- endHeight: number;
67
- density: number;
68
- color: number[]; // R G B A
69
- }
70
-
71
- interface PlayableMapArea {
72
- width: number;
73
- height: number;
74
- }
75
-
76
- interface Prologue {
77
- path: string;
78
- text: string;
79
- title: string;
80
- subtitle: string;
81
- }
82
-
83
- interface Info {
84
- saves: number;
85
- gameVersion: GameVersion;
86
- editorVersion: number;
87
- scriptLanguage: ScriptLanguage;
88
- supportedModes: SupportedModes;
89
- map: Map;
90
- camera: Camera;
91
- prologue: Prologue;
92
- loadingScreen: LoadingScreen;
93
- fog: Fog;
94
- globalWeather: string;
95
- customSoundEnvironment: string;
96
- customLightEnv: string;
97
- water: number[]; // R G B A
98
- players: Player[];
99
- forces: Force[];
100
- }
101
-
102
- interface PlayerStartingPosition {
103
- x: number;
104
- y: number;
105
- fixed: boolean;
106
- }
107
-
108
- interface Player {
109
- playerNum: number;
110
- type: number; // 1=Human, 2=Computer, 3=Neutral, 4=Rescuable
111
- race: number; // 1=Human, 2=Orc, 3=Undead, 4=Night Elf
112
-
113
- name: string;
114
- startingPos: PlayerStartingPosition;
115
- }
116
-
117
- interface ForceFlags {
118
- allied: boolean; // 0x00000001: allied (force 1)
119
- alliedVictory: boolean; // 0x00000002: allied victory
120
- // 0x00000004: share vision (the documentation has this incorrect)
121
- shareVision: boolean; // 0x00000008: share vision
122
- shareUnitControl: boolean; // 0x00000010: share unit control
123
- shareAdvUnitControl: boolean; // 0x00000020: share advanced unit control
124
- }
125
-
126
- interface Force {
127
- flags: ForceFlags;
128
- players: number; // UNSUPPORTED: (bit "x"=1 --> player "x" is in this force)
129
- name: string;
130
- }
131
-
132
- enum ScriptLanguage {
133
- JASS = 0,
134
- Lua = 1
135
- }
136
-
137
- enum SupportedModes {
138
- SD = 1,
139
- HD = 2,
140
- Both = 3
141
- }
142
-
143
- export abstract class InfoTranslator {
144
-
145
- public static jsonToWar(infoJson: Info): WarResult {
146
- const outBufferToWar = new HexBuffer();
147
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfoTranslator = void 0;
4
+ const HexBuffer_1 = require("../HexBuffer");
5
+ const W3Buffer_1 = require("../W3Buffer");
6
+ var FogType;
7
+ (function (FogType) {
8
+ FogType[FogType["Linear"] = 0] = "Linear";
9
+ FogType[FogType["Exponential1"] = 1] = "Exponential1";
10
+ FogType[FogType["Exponential2"] = 2] = "Exponential2";
11
+ })(FogType || (FogType = {}));
12
+ var ScriptLanguage;
13
+ (function (ScriptLanguage) {
14
+ ScriptLanguage[ScriptLanguage["JASS"] = 0] = "JASS";
15
+ ScriptLanguage[ScriptLanguage["Lua"] = 1] = "Lua";
16
+ })(ScriptLanguage || (ScriptLanguage = {}));
17
+ var SupportedModes;
18
+ (function (SupportedModes) {
19
+ SupportedModes[SupportedModes["SD"] = 1] = "SD";
20
+ SupportedModes[SupportedModes["HD"] = 2] = "HD";
21
+ SupportedModes[SupportedModes["Both"] = 3] = "Both";
22
+ })(SupportedModes || (SupportedModes = {}));
23
+ class InfoTranslator {
24
+ static jsonToWar(infoJson) {
25
+ const outBufferToWar = new HexBuffer_1.HexBuffer();
148
26
  outBufferToWar.addInt(31); // file version, 0x1F
149
27
  outBufferToWar.addInt(infoJson.saves || 0);
150
28
  outBufferToWar.addInt(infoJson.editorVersion || 0);
151
-
152
29
  outBufferToWar.addInt(infoJson.gameVersion.major);
153
30
  outBufferToWar.addInt(infoJson.gameVersion.minor);
154
31
  outBufferToWar.addInt(infoJson.gameVersion.patch);
155
32
  outBufferToWar.addInt(infoJson.gameVersion.build);
156
-
157
33
  // Map information
158
34
  outBufferToWar.addString(infoJson.map.name);
159
35
  outBufferToWar.addString(infoJson.map.author);
160
36
  outBufferToWar.addString(infoJson.map.description);
161
37
  outBufferToWar.addString(infoJson.map.recommendedPlayers);
162
-
163
38
  // Camera bounds (8 floats total)
164
39
  for (let cbIndex = 0; cbIndex < 8; cbIndex++) {
165
40
  outBufferToWar.addFloat(infoJson.camera.bounds[cbIndex]);
166
41
  }
167
-
168
42
  // Camera complements (4 floats total)
169
43
  for (let ccIndex = 0; ccIndex < 4; ccIndex++) {
170
44
  outBufferToWar.addInt(infoJson.camera.complements[ccIndex]);
171
45
  }
172
-
173
46
  // Playable area
174
47
  outBufferToWar.addInt(infoJson.map.playableArea.width);
175
48
  outBufferToWar.addInt(infoJson.map.playableArea.height);
176
-
177
49
  /*
178
50
  * Flags
179
51
  */
180
52
  let flags = 0;
181
53
  if (infoJson.map.flags) { // can leave out the entire flags object, all flags will default to false
182
- if (infoJson.map.flags.hideMinimapInPreview) flags |= 0x0001; // hide minimap in preview screens
183
- if (infoJson.map.flags.modifyAllyPriorities) flags |= 0x0002; // modify ally priorities
184
- if (infoJson.map.flags.isMeleeMap) flags |= 0x0004; // melee map
54
+ if (infoJson.map.flags.hideMinimapInPreview)
55
+ flags |= 0x0001; // hide minimap in preview screens
56
+ if (infoJson.map.flags.modifyAllyPriorities)
57
+ flags |= 0x0002; // modify ally priorities
58
+ if (infoJson.map.flags.isMeleeMap)
59
+ flags |= 0x0004; // melee map
185
60
  // 0x0008 - unknown; // playable map size was large and never reduced to medium (?)
186
- if (infoJson.map.flags.maskedPartiallyVisible) flags |= 0x0010; // masked area are partially visible
187
- if (infoJson.map.flags.fixedPlayerSetting) flags |= 0x0020; // fixed player setting for custom forces
188
- if (infoJson.map.flags.useCustomForces) flags |= 0x0040; // use custom forces
189
- if (infoJson.map.flags.useCustomTechtree) flags |= 0x0080; // use custom techtree
190
- if (infoJson.map.flags.useCustomAbilities) flags |= 0x0100; // use custom abilities
191
- if (infoJson.map.flags.useCustomUpgrades) flags |= 0x0200; // use custom upgrades
61
+ if (infoJson.map.flags.maskedPartiallyVisible)
62
+ flags |= 0x0010; // masked area are partially visible
63
+ if (infoJson.map.flags.fixedPlayerSetting)
64
+ flags |= 0x0020; // fixed player setting for custom forces
65
+ if (infoJson.map.flags.useCustomForces)
66
+ flags |= 0x0040; // use custom forces
67
+ if (infoJson.map.flags.useCustomTechtree)
68
+ flags |= 0x0080; // use custom techtree
69
+ if (infoJson.map.flags.useCustomAbilities)
70
+ flags |= 0x0100; // use custom abilities
71
+ if (infoJson.map.flags.useCustomUpgrades)
72
+ flags |= 0x0200; // use custom upgrades
192
73
  // 0x0400 - unknown; // map properties menu opened at least once since map creation (?)
193
- if (infoJson.map.flags.waterWavesOnCliffShores) flags |= 0x0800; // show water waves on cliff shores
194
- if (infoJson.map.flags.waterWavesOnRollingShores) flags |= 0x1000; // show water waves on rolling shores
74
+ if (infoJson.map.flags.waterWavesOnCliffShores)
75
+ flags |= 0x0800; // show water waves on cliff shores
76
+ if (infoJson.map.flags.waterWavesOnRollingShores)
77
+ flags |= 0x1000; // show water waves on rolling shores
195
78
  // 0x2000: 1=unknown
196
79
  // 0x4000: 1=unknown
197
- if (infoJson.map.flags.useItemClassificationSystem) flags |= 0x8000
198
- if (infoJson.map.flags.enableWaterTinting) flags |= 0x10000
199
- if (infoJson.map.flags.useAccurateProbabilityForCalculations) flags |= 0x20000
200
- if (infoJson.map.flags.useCustomAbilitySkins) flags |= 0x40000
80
+ if (infoJson.map.flags.useItemClassificationSystem)
81
+ flags |= 0x8000;
82
+ if (infoJson.map.flags.enableWaterTinting)
83
+ flags |= 0x10000;
84
+ if (infoJson.map.flags.useAccurateProbabilityForCalculations)
85
+ flags |= 0x20000;
86
+ if (infoJson.map.flags.useCustomAbilitySkins)
87
+ flags |= 0x40000;
201
88
  }
202
-
203
89
  // Unknown, but these seem to always be on, at least for default maps
204
90
  flags |= 0x8000;
205
91
  flags |= 0x4000;
206
92
  flags |= 0x0400;
207
-
208
93
  outBufferToWar.addInt(flags); // Add flags
209
-
210
94
  // Map main ground type
211
95
  outBufferToWar.addChar(infoJson.map.mainTileType);
212
-
213
96
  // Loading screen
214
97
  outBufferToWar.addInt(infoJson.loadingScreen.background);
215
98
  outBufferToWar.addString(infoJson.loadingScreen.path);
216
99
  outBufferToWar.addString(infoJson.loadingScreen.text);
217
100
  outBufferToWar.addString(infoJson.loadingScreen.title);
218
101
  outBufferToWar.addString(infoJson.loadingScreen.subtitle);
219
-
220
102
  // Use game data set (Unsupported)
221
103
  outBufferToWar.addInt(0);
222
-
223
104
  // Prologue
224
105
  outBufferToWar.addString(infoJson.prologue.path);
225
106
  outBufferToWar.addString(infoJson.prologue.text);
226
107
  outBufferToWar.addString(infoJson.prologue.title);
227
108
  outBufferToWar.addString(infoJson.prologue.subtitle);
228
-
229
109
  // Fog
230
110
  outBufferToWar.addInt(infoJson.fog.type);
231
111
  outBufferToWar.addFloat(infoJson.fog.startHeight);
@@ -235,27 +115,24 @@ export abstract class InfoTranslator {
235
115
  outBufferToWar.addByte(infoJson.fog.color[1]);
236
116
  outBufferToWar.addByte(infoJson.fog.color[2]);
237
117
  outBufferToWar.addByte(255); // Fog alpha - unsupported
238
-
239
118
  // Misc.
240
119
  // If globalWeather is not defined or is set to 'none', use 0 sentinel value, else add char[4]
241
120
  if (!infoJson.globalWeather || infoJson.globalWeather.toLowerCase() === 'none') {
242
121
  outBufferToWar.addInt(0);
243
- } else {
122
+ }
123
+ else {
244
124
  outBufferToWar.addChars(infoJson.globalWeather); // char[4] - lookup table
245
125
  }
246
126
  outBufferToWar.addString(infoJson.customSoundEnvironment || '');
247
127
  outBufferToWar.addChar(infoJson.customLightEnv || 'L');
248
-
249
128
  // Custom water tinting
250
129
  outBufferToWar.addByte(infoJson.water[0]);
251
130
  outBufferToWar.addByte(infoJson.water[1]);
252
131
  outBufferToWar.addByte(infoJson.water[2]);
253
132
  outBufferToWar.addByte(255); // Water alpha - unsupported
254
-
255
133
  outBufferToWar.addInt(infoJson.scriptLanguage);
256
134
  outBufferToWar.addInt(infoJson.supportedModes);
257
135
  outBufferToWar.addInt(0); // unknown
258
-
259
136
  // Players
260
137
  outBufferToWar.addInt(infoJson.players.length);
261
138
  infoJson.players.forEach((player) => {
@@ -271,44 +148,41 @@ export abstract class InfoTranslator {
271
148
  outBufferToWar.addInt(0); // enemy low prio flags - unsupported
272
149
  outBufferToWar.addInt(0); // enemy high prio flags - unsupported
273
150
  });
274
-
275
151
  // Forces
276
152
  outBufferToWar.addInt(infoJson.forces.length);
277
153
  infoJson.forces.forEach((force) => {
278
154
  // Calculate flags
279
155
  let forceFlags = 0;
280
- if (force.flags.allied) forceFlags |= 0x0001;
281
- if (force.flags.alliedVictory) forceFlags |= 0x0002;
156
+ if (force.flags.allied)
157
+ forceFlags |= 0x0001;
158
+ if (force.flags.alliedVictory)
159
+ forceFlags |= 0x0002;
282
160
  // Skip 0x0004
283
- if (force.flags.shareVision) forceFlags |= 0x0008;
284
- if (force.flags.shareUnitControl) forceFlags |= 0x0010;
285
- if (force.flags.shareAdvUnitControl) forceFlags |= 0x0020;
286
-
161
+ if (force.flags.shareVision)
162
+ forceFlags |= 0x0008;
163
+ if (force.flags.shareUnitControl)
164
+ forceFlags |= 0x0010;
165
+ if (force.flags.shareAdvUnitControl)
166
+ forceFlags |= 0x0020;
287
167
  outBufferToWar.addInt(forceFlags);
288
168
  outBufferToWar.addInt(force.players);
289
169
  outBufferToWar.addString(force.name);
290
170
  });
291
-
292
171
  // Upgrades - unsupported
293
172
  outBufferToWar.addInt(0);
294
-
295
173
  // Tech availability - unsupported
296
174
  outBufferToWar.addInt(0);
297
-
298
175
  // Unit table (random) - unsupported
299
176
  outBufferToWar.addInt(0);
300
-
301
177
  // Item table (random) - unsupported
302
178
  outBufferToWar.addInt(0);
303
-
304
179
  return {
305
180
  errors: [],
306
181
  buffer: outBufferToWar.getBuffer()
307
182
  };
308
183
  }
309
-
310
- public static warToJson(buffer: Buffer): JsonResult<Info> {
311
- const result: Info = {
184
+ static warToJson(buffer) {
185
+ const result = {
312
186
  map: {
313
187
  name: '',
314
188
  author: '',
@@ -320,22 +194,22 @@ export abstract class InfoTranslator {
320
194
  },
321
195
  mainTileType: '',
322
196
  flags: {
323
- hideMinimapInPreview: false, // 0x0001: 1=hide minimap in preview screens
324
- modifyAllyPriorities: true, // 0x0002: 1=modify ally priorities
325
- isMeleeMap: false, // 0x0004: 1=melee map
197
+ hideMinimapInPreview: false,
198
+ modifyAllyPriorities: true,
199
+ isMeleeMap: false,
326
200
  // 0x0008: 1=playable map size was large and has never been reduced to medium (?)
327
- maskedPartiallyVisible: false, // 0x0010: 1=masked area are partially visible
328
- fixedPlayerSetting: false, // 0x0020: 1=fixed player setting for custom forces
329
- useCustomForces: false, // 0x0040: 1=use custom forces
330
- useCustomTechtree: false, // 0x0080: 1=use custom techtree
331
- useCustomAbilities: false, // 0x0100: 1=use custom abilities
332
- useCustomUpgrades: false, // 0x0200: 1=use custom upgrades
201
+ maskedPartiallyVisible: false,
202
+ fixedPlayerSetting: false,
203
+ useCustomForces: false,
204
+ useCustomTechtree: false,
205
+ useCustomAbilities: false,
206
+ useCustomUpgrades: false,
333
207
  // 0x0400: 1=map properties menu opened at least once since map creation (?)
334
- waterWavesOnCliffShores: false, // 0x0800: 1=show water waves on cliff shores
335
- waterWavesOnRollingShores: false, // 0x1000: 1=show water waves on rolling shores
336
- useItemClassificationSystem: false, // 0x8000: 1=use item classification system
337
- enableWaterTinting: false, // 0x10000
338
- useAccurateProbabilityForCalculations: false, // 0x20000
208
+ waterWavesOnCliffShores: false,
209
+ waterWavesOnRollingShores: false,
210
+ useItemClassificationSystem: false,
211
+ enableWaterTinting: false,
212
+ useAccurateProbabilityForCalculations: false,
339
213
  useCustomAbilitySkins: false // 0x40000
340
214
  }
341
215
  },
@@ -359,11 +233,7 @@ export abstract class InfoTranslator {
359
233
  }, camera: {
360
234
  bounds: [],
361
235
  complements: []
362
- }, players: [
363
-
364
- ], forces: [
365
-
366
- ],
236
+ }, players: [], forces: [],
367
237
  saves: 0,
368
238
  editorVersion: 0,
369
239
  scriptLanguage: ScriptLanguage.JASS,
@@ -379,78 +249,65 @@ export abstract class InfoTranslator {
379
249
  customLightEnv: '',
380
250
  water: []
381
251
  };
382
- const outBufferToJSON = new W3Buffer(buffer);
383
-
252
+ const outBufferToJSON = new W3Buffer_1.W3Buffer(buffer);
384
253
  const fileVersion = outBufferToJSON.readInt();
385
-
386
254
  result.saves = outBufferToJSON.readInt(),
387
- result.editorVersion = outBufferToJSON.readInt();
388
-
255
+ result.editorVersion = outBufferToJSON.readInt();
389
256
  result.gameVersion = {
390
257
  major: outBufferToJSON.readInt(),
391
258
  minor: outBufferToJSON.readInt(),
392
259
  patch: outBufferToJSON.readInt(),
393
260
  build: outBufferToJSON.readInt()
394
261
  };
395
-
396
262
  result.map.name = outBufferToJSON.readString();
397
263
  result.map.author = outBufferToJSON.readString();
398
264
  result.map.description = outBufferToJSON.readString();
399
265
  result.map.recommendedPlayers = outBufferToJSON.readString();
400
-
401
266
  result.camera.bounds = [
402
267
  outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat(),
403
268
  outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat()
404
269
  ];
405
-
406
270
  result.camera.complements = [
407
271
  outBufferToJSON.readInt(), outBufferToJSON.readInt(), outBufferToJSON.readInt(), outBufferToJSON.readInt()
408
272
  ];
409
-
410
273
  result.map.playableArea = {
411
274
  width: outBufferToJSON.readInt(),
412
275
  height: outBufferToJSON.readInt()
413
276
  };
414
-
415
277
  const flags = outBufferToJSON.readInt();
416
278
  result.map.flags = {
417
- hideMinimapInPreview: !!(flags & 0x0001),
418
- modifyAllyPriorities: !!(flags & 0x0002),
419
- isMeleeMap: !!(flags & 0x0004),
279
+ hideMinimapInPreview: !!(flags & 0x0001),
280
+ modifyAllyPriorities: !!(flags & 0x0002),
281
+ isMeleeMap: !!(flags & 0x0004),
420
282
  // skip 0x008
421
- maskedPartiallyVisible: !!(flags & 0x0010),
422
- fixedPlayerSetting: !!(flags & 0x0020),
423
- useCustomForces: !!(flags & 0x0040),
424
- useCustomTechtree: !!(flags & 0x0080),
425
- useCustomAbilities: !!(flags & 0x0100),
426
- useCustomUpgrades: !!(flags & 0x0200),
427
- waterWavesOnCliffShores: !!(flags & 0x0800),
428
- waterWavesOnRollingShores: !!(flags & 0x1000),
283
+ maskedPartiallyVisible: !!(flags & 0x0010),
284
+ fixedPlayerSetting: !!(flags & 0x0020),
285
+ useCustomForces: !!(flags & 0x0040),
286
+ useCustomTechtree: !!(flags & 0x0080),
287
+ useCustomAbilities: !!(flags & 0x0100),
288
+ useCustomUpgrades: !!(flags & 0x0200),
289
+ waterWavesOnCliffShores: !!(flags & 0x0800),
290
+ waterWavesOnRollingShores: !!(flags & 0x1000),
429
291
  // skip 0x2000
430
292
  // skip 0x4000
431
293
  useItemClassificationSystem: !!(flags & 0x8000),
432
- enableWaterTinting: !!(flags & 0x10000),
294
+ enableWaterTinting: !!(flags & 0x10000),
433
295
  useAccurateProbabilityForCalculations: !!(flags & 0x20000),
434
- useCustomAbilitySkins: !!(flags & 0x40000)
296
+ useCustomAbilitySkins: !!(flags & 0x40000)
435
297
  };
436
-
437
298
  result.map.mainTileType = outBufferToJSON.readChars();
438
-
439
299
  result.loadingScreen.background = outBufferToJSON.readInt();
440
300
  result.loadingScreen.path = outBufferToJSON.readString();
441
301
  result.loadingScreen.text = outBufferToJSON.readString();
442
302
  result.loadingScreen.title = outBufferToJSON.readString();
443
303
  result.loadingScreen.subtitle = outBufferToJSON.readString();
444
-
445
304
  const gameDataSet = outBufferToJSON.readInt(); // 0 = standard
446
-
447
305
  result.prologue = {
448
306
  path: outBufferToJSON.readString(),
449
307
  text: outBufferToJSON.readString(),
450
308
  title: outBufferToJSON.readString(),
451
309
  subtitle: outBufferToJSON.readString()
452
310
  };
453
-
454
311
  result.fog = {
455
312
  type: outBufferToJSON.readInt(),
456
313
  startHeight: outBufferToJSON.readFloat(),
@@ -458,72 +315,60 @@ export abstract class InfoTranslator {
458
315
  density: outBufferToJSON.readFloat(),
459
316
  color: [outBufferToJSON.readByte(), outBufferToJSON.readByte(), outBufferToJSON.readByte(), outBufferToJSON.readByte()] // R G B A
460
317
  };
461
-
462
318
  result.globalWeather = outBufferToJSON.readChars(4);
463
319
  result.customSoundEnvironment = outBufferToJSON.readString();
464
320
  result.customLightEnv = outBufferToJSON.readChars();
465
321
  result.water = [outBufferToJSON.readByte(), outBufferToJSON.readByte(), outBufferToJSON.readByte(), outBufferToJSON.readByte()]; // R G B A
466
-
467
322
  result.scriptLanguage = outBufferToJSON.readInt();
468
323
  result.supportedModes = outBufferToJSON.readInt();
469
324
  outBufferToJSON.readInt(); // unknown
470
-
471
325
  // Struct: players
472
326
  const numPlayers = outBufferToJSON.readInt();
473
327
  for (let i = 0; i < numPlayers; i++) {
474
- const player: Player = {
328
+ const player = {
475
329
  name: '',
476
330
  startingPos: { x: 0, y: 0, fixed: false },
477
331
  playerNum: 0,
478
332
  type: 0,
479
333
  race: 0
480
334
  };
481
-
482
335
  player.playerNum = outBufferToJSON.readInt();
483
336
  player.type = outBufferToJSON.readInt(); // 1=Human, 2=Computer, 3=Neutral, 4=Rescuable
484
337
  player.race = outBufferToJSON.readInt(); // 1=Human, 2=Orc, 3=Undead, 4=Night Elf
485
-
486
- const isPlayerStartPositionFixed: boolean = outBufferToJSON.readInt() === 1; // 00000001 = fixed start position
487
-
338
+ const isPlayerStartPositionFixed = outBufferToJSON.readInt() === 1; // 00000001 = fixed start position
488
339
  player.name = outBufferToJSON.readString();
489
340
  player.startingPos = {
490
341
  x: outBufferToJSON.readFloat(),
491
342
  y: outBufferToJSON.readFloat(),
492
343
  fixed: isPlayerStartPositionFixed
493
344
  };
494
-
495
345
  outBufferToJSON.readInt(); // ally low priorities flags (bit "x"=1 --> set for player "x")
496
346
  outBufferToJSON.readInt(); // ally high priorities flags (bit "x"=1 --> set for player "x")
497
347
  outBufferToJSON.readInt(); // enemy low priorities flags
498
348
  outBufferToJSON.readInt(); // enemy high priorities flags
499
-
500
349
  result.players.push(player);
501
350
  }
502
-
503
351
  // Struct: forces
504
352
  const numForces = outBufferToJSON.readInt();
505
353
  for (let i = 0; i < numForces; i++) {
506
- const force: Force = {
354
+ const force = {
507
355
  flags: { allied: false, alliedVictory: true, shareVision: true, shareUnitControl: false, shareAdvUnitControl: false },
508
356
  players: 0,
509
357
  name: ''
510
358
  };
511
-
512
359
  const forceFlag = outBufferToJSON.readInt();
513
360
  force.flags = {
514
- allied: !!(forceFlag & 0b1), // 0x00000001: allied (force 1)
515
- alliedVictory: !!(forceFlag & 0b10), // 0x00000002: allied victory
361
+ allied: !!(forceFlag & 0b1),
362
+ alliedVictory: !!(forceFlag & 0b10),
516
363
  // 0x00000004: share vision (the documentation has this incorrect)
517
- shareVision: !!(forceFlag & 0b1000), // 0x00000008: share vision
518
- shareUnitControl: !!(forceFlag & 0b10000), // 0x00000010: share unit control
364
+ shareVision: !!(forceFlag & 0b1000),
365
+ shareUnitControl: !!(forceFlag & 0b10000),
519
366
  shareAdvUnitControl: !!(forceFlag & 0b100000) // 0x00000020: share advanced unit control
520
367
  };
521
368
  force.players = outBufferToJSON.readInt(); // UNSUPPORTED: (bit "x"=1 --> player "x" is in this force; but carried over for accurate translation
522
369
  force.name = outBufferToJSON.readString();
523
-
524
370
  result.forces.push(force);
525
371
  }
526
-
527
372
  // UNSUPPORTED: Struct: upgrade avail.
528
373
  const numUpgrades = outBufferToJSON.readInt();
529
374
  for (let i = 0; i < numUpgrades; i++) {
@@ -532,24 +377,20 @@ export abstract class InfoTranslator {
532
377
  outBufferToJSON.readInt(); // Level of the upgrade for which the availability is changed (this is actually the level - 1, so 1 => 0)
533
378
  outBufferToJSON.readInt(); // Availability (0 = unavailable, 1 = available, 2 = researched)
534
379
  }
535
-
536
380
  // UNSUPPORTED: Struct: tech avail.
537
381
  const numTech = outBufferToJSON.readInt();
538
382
  for (let i = 0; i < numTech; i++) {
539
383
  outBufferToJSON.readInt(); // Player Flags (bit "x"=1 if this change applies for player "x")
540
384
  outBufferToJSON.readChars(4); // tech id (this can be an item, unit or ability)
541
385
  }
542
-
543
386
  // UNSUPPORTED: Struct: random unit table
544
387
  const numUnitTable = outBufferToJSON.readInt();
545
388
  for (let i = 0; i < numUnitTable; i++) {
546
389
  outBufferToJSON.readInt(); // Group number
547
390
  outBufferToJSON.readString(); // Group name
548
-
549
391
  const numPositions = outBufferToJSON.readInt(); // Number "m" of positions
550
392
  for (let j = 0; j < numPositions; j++) {
551
393
  outBufferToJSON.readInt(); // unit table (=0), a building table (=1) or an item table (=2)
552
-
553
394
  const numLinesInTable = outBufferToJSON.readInt();
554
395
  for (let k = 0; k < numLinesInTable; k++) {
555
396
  outBufferToJSON.readInt(); // Chance of the unit/item (percentage)
@@ -557,28 +398,25 @@ export abstract class InfoTranslator {
557
398
  }
558
399
  }
559
400
  }
560
-
561
401
  // UNSUPPORTED: Struct: random item table
562
402
  const numItemTable = outBufferToJSON.readInt();
563
403
  for (let i = 0; i < numItemTable; i++) {
564
404
  outBufferToJSON.readInt(); // Table number
565
405
  outBufferToJSON.readString(); // Table name
566
-
567
406
  const itemSetsCurrentTable = outBufferToJSON.readInt(); // Number "m" of item sets on the current item table
568
407
  for (let j = 0; j < itemSetsCurrentTable; j++) {
569
-
570
408
  const itemsInItemSet = outBufferToJSON.readInt(); // Number "i" of items on the current item set
571
409
  for (let k = 0; k < itemsInItemSet; k++) {
572
410
  outBufferToJSON.readInt(); // Percentual chance
573
411
  outBufferToJSON.readChars(4); // Item id (as in ItemData.slk)
574
412
  }
575
-
576
413
  }
577
414
  }
578
-
579
415
  return {
580
416
  errors: [],
581
417
  json: result
582
418
  };
583
419
  }
584
420
  }
421
+ exports.InfoTranslator = InfoTranslator;
422
+ //# sourceMappingURL=InfoTranslator.js.map