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
@@ -1,14 +1,15 @@
1
1
  import { HexBuffer } from '../HexBuffer';
2
2
  import { W3Buffer } from '../W3Buffer';
3
+ import { WarResult, JsonResult, angle } from '../CommonInterfaces'
3
4
 
4
5
  interface Camera {
5
6
  target: CameraTarget;
6
7
  offsetZ: number;
7
- rotation: number; // in degrees
8
- aoa: number; // angle of attack, in degrees
8
+ rotation: angle;
9
+ aoa: angle; // angle of attack
9
10
  distance: number;
10
11
  roll: number;
11
- fov: number; // field of view, in degrees
12
+ fov: angle; // field of view
12
13
  farClipping: number;
13
14
  name: string;
14
15
  }
@@ -18,54 +19,48 @@ interface CameraTarget {
18
19
  y: number;
19
20
  }
20
21
 
21
- export class CamerasTranslator {
22
+ export abstract class CamerasTranslator {
22
23
 
23
- private _outBufferToWar: HexBuffer;
24
- private _outBufferToJSON: W3Buffer;
25
-
26
- constructor() { }
27
-
28
- public jsonToWar(cameras: Camera[]) {
29
- this._outBufferToWar = new HexBuffer();
24
+ public static jsonToWar(cameras: Camera[]): WarResult {
25
+ const outBufferToWar = new HexBuffer();
30
26
 
31
27
  /*
32
28
  * Header
33
29
  */
34
- this._outBufferToWar.addInt(0); // file version
35
- this._outBufferToWar.addInt(cameras.length); // number of cameras
30
+ outBufferToWar.addInt(0); // file version
31
+ outBufferToWar.addInt(cameras.length); // number of cameras
36
32
 
37
33
  /*
38
34
  * Body
39
35
  */
40
36
  cameras.forEach((camera) => {
41
- this._outBufferToWar.addFloat(camera.target.x);
42
- this._outBufferToWar.addFloat(camera.target.y);
43
- this._outBufferToWar.addFloat(camera.offsetZ);
44
- this._outBufferToWar.addFloat(camera.rotation || 0); // optional
45
- this._outBufferToWar.addFloat(camera.aoa);
46
- this._outBufferToWar.addFloat(camera.distance);
47
- this._outBufferToWar.addFloat(camera.roll || 0);
48
- this._outBufferToWar.addFloat(camera.fov); // in degrees
49
- this._outBufferToWar.addFloat(camera.farClipping);
50
- this._outBufferToWar.addFloat(100); // (?) unknown - usually set to 100
37
+ outBufferToWar.addFloat(camera.target.x);
38
+ outBufferToWar.addFloat(camera.target.y);
39
+ outBufferToWar.addFloat(camera.offsetZ);
40
+ outBufferToWar.addFloat(camera.rotation || 0); // optional
41
+ outBufferToWar.addFloat(camera.aoa);
42
+ outBufferToWar.addFloat(camera.distance);
43
+ outBufferToWar.addFloat(camera.roll || 0);
44
+ outBufferToWar.addFloat(camera.fov);
45
+ outBufferToWar.addFloat(camera.farClipping);
46
+ outBufferToWar.addFloat(100); // (?) unknown - usually set to 100
51
47
 
52
48
  // Camera name - must be null-terminated
53
- this._outBufferToWar.addString(camera.name);
54
- this._outBufferToWar.addNullTerminator();
49
+ outBufferToWar.addString(camera.name);
55
50
  });
56
51
 
57
52
  return {
58
53
  errors: [],
59
- buffer: this._outBufferToWar.getBuffer()
54
+ buffer: outBufferToWar.getBuffer()
60
55
  };
61
56
  }
62
57
 
63
- public warToJson(buffer: Buffer) {
58
+ public static warToJson(buffer: Buffer): JsonResult<Camera[]> {
64
59
  const result = [];
65
- this._outBufferToJSON = new W3Buffer(buffer);
60
+ const outBufferToJSON = new W3Buffer(buffer);
66
61
 
67
- const fileVersion = this._outBufferToJSON.readInt(), // File version
68
- numCameras = this._outBufferToJSON.readInt(); // # of cameras
62
+ const fileVersion = outBufferToJSON.readInt(), // File version
63
+ numCameras = outBufferToJSON.readInt(); // # of cameras
69
64
 
70
65
  for (let i = 0; i < numCameras; i++) {
71
66
  const camera: Camera = {
@@ -83,17 +78,17 @@ export class CamerasTranslator {
83
78
  name: ''
84
79
  };
85
80
 
86
- camera.target.x = this._outBufferToJSON.readFloat();
87
- camera.target.y = this._outBufferToJSON.readFloat();
88
- camera.offsetZ = this._outBufferToJSON.readFloat();
89
- camera.rotation = this._outBufferToJSON.readFloat(); // in degrees
90
- camera.aoa = this._outBufferToJSON.readFloat(); // angle of attack, in degrees
91
- camera.distance = this._outBufferToJSON.readFloat();
92
- camera.roll = this._outBufferToJSON.readFloat();
93
- camera.fov = this._outBufferToJSON.readFloat(); // field of view, in degrees
94
- camera.farClipping = this._outBufferToJSON.readFloat();
95
- this._outBufferToJSON.readFloat(); // consume this unknown float field
96
- camera.name = this._outBufferToJSON.readString();
81
+ camera.target.x = outBufferToJSON.readFloat();
82
+ camera.target.y = outBufferToJSON.readFloat();
83
+ camera.offsetZ = outBufferToJSON.readFloat();
84
+ camera.rotation = outBufferToJSON.readFloat();
85
+ camera.aoa = outBufferToJSON.readFloat(); // angle of attack
86
+ camera.distance = outBufferToJSON.readFloat();
87
+ camera.roll = outBufferToJSON.readFloat();
88
+ camera.fov = outBufferToJSON.readFloat(); // field of view
89
+ camera.farClipping = outBufferToJSON.readFloat();
90
+ outBufferToJSON.readFloat(); // consume this unknown float field
91
+ camera.name = outBufferToJSON.readString();
97
92
 
98
93
  result.push(camera);
99
94
  }
@@ -1,13 +1,15 @@
1
- import { deg2Rad, rad2Deg } from '../AngleConverter';
2
1
  import { HexBuffer } from '../HexBuffer';
3
2
  import { W3Buffer } from '../W3Buffer';
3
+ import { rad2Deg, deg2Rad } from '../AngleConverter';
4
+ import { WarResult, JsonResult, angle } from '../CommonInterfaces'
4
5
 
5
6
  interface Doodad {
6
7
  type: string;
7
8
  variation: number;
8
9
  position: number[];
9
- angle: number; // degrees
10
+ angle: angle;
10
11
  scale: number[];
12
+ skinId: string;
11
13
  flags: DoodadFlag;
12
14
  life: number;
13
15
  id: number;
@@ -27,44 +29,42 @@ enum flag {
27
29
  solid = 3
28
30
  }
29
31
 
30
- export class DoodadsTranslator {
31
- private _outBufferToWar: HexBuffer;
32
- private _outBufferToJSON: W3Buffer;
32
+ export abstract class DoodadsTranslator {
33
33
 
34
- constructor() { }
35
-
36
- public jsonToWar(doodadsJson: Doodad[]) {
37
- this._outBufferToWar = new HexBuffer();
34
+ public static jsonToWar(doodadsJson: Doodad[]): WarResult {
35
+ const outBufferToWar = new HexBuffer();
38
36
  /*
39
37
  * Header
40
38
  */
41
- this._outBufferToWar.addString('W3do'); // file id
42
- this._outBufferToWar.addInt(8); // file version
43
- this._outBufferToWar.addInt(11); // subversion 0x0B
44
- this._outBufferToWar.addInt(doodadsJson.length); // num of trees
39
+ outBufferToWar.addChars('W3do'); // file id
40
+ outBufferToWar.addInt(8); // file version
41
+ outBufferToWar.addInt(11); // subversion 0x0B
42
+ outBufferToWar.addInt(doodadsJson.length); // num of trees
45
43
 
46
44
  /*
47
45
  * Body
48
46
  */
49
47
  doodadsJson.forEach((tree) => {
50
- this._outBufferToWar.addString(tree.type);
51
- this._outBufferToWar.addInt(tree.variation || 0); // optional - default value 0
52
- this._outBufferToWar.addFloat(tree.position[0]);
53
- this._outBufferToWar.addFloat(tree.position[1]);
54
- this._outBufferToWar.addFloat(tree.position[2]);
48
+ outBufferToWar.addChars(tree.type);
49
+ outBufferToWar.addInt(tree.variation || 0); // optional - default value 0
50
+ outBufferToWar.addFloat(tree.position[0]);
51
+ outBufferToWar.addFloat(tree.position[1]);
52
+ outBufferToWar.addFloat(tree.position[2]);
55
53
 
56
54
  // Angle
57
55
  // Doodads format is unique because it uses radians for angles, as opposed
58
56
  // to angles in any other file which use degrees. Hence conversion is needed.
59
57
  // war3map: Expects angle in RADIANS
60
58
  // JSON: Spec defines angle in DEGREES
61
- this._outBufferToWar.addFloat(deg2Rad(tree.angle) || 0); // optional - default value 0
59
+ outBufferToWar.addFloat(deg2Rad(tree.angle) || 0); // optional - default value 0
62
60
 
63
61
  // Scale
64
62
  if (!tree.scale) tree.scale = [1, 1, 1];
65
- this._outBufferToWar.addFloat(tree.scale[0] || 1);
66
- this._outBufferToWar.addFloat(tree.scale[1] || 1);
67
- this._outBufferToWar.addFloat(tree.scale[2] || 1);
63
+ outBufferToWar.addFloat(tree.scale[0] || 1);
64
+ outBufferToWar.addFloat(tree.scale[1] || 1);
65
+ outBufferToWar.addFloat(tree.scale[2] || 1);
66
+
67
+ outBufferToWar.addChars(tree.skinId);
68
68
 
69
69
  // Tree flags
70
70
  /* | Visible | Solid | Flag value |
@@ -77,34 +77,34 @@ export class DoodadsTranslator {
77
77
  else if (tree.flags.visible && !tree.flags.solid) treeFlag = 1;
78
78
  else if (tree.flags.visible && tree.flags.solid) treeFlag = 2;
79
79
  // Note: invisible and solid is not an option
80
- this._outBufferToWar.addByte(treeFlag);
80
+ outBufferToWar.addByte(treeFlag);
81
81
 
82
- this._outBufferToWar.addByte(tree.life || 100);
83
- this._outBufferToWar.addInt(0); // NOT SUPPORTED: random item table pointer: fixed to 0
84
- this._outBufferToWar.addInt(0); // NOT SUPPORTED: number of items dropped for item table
85
- this._outBufferToWar.addInt(tree.id);
82
+ outBufferToWar.addByte(tree.life || 100);
83
+ outBufferToWar.addInt(0); // NOT SUPPORTED: random item table pointer: fixed to 0
84
+ outBufferToWar.addInt(0); // NOT SUPPORTED: number of items dropped for item table
85
+ outBufferToWar.addInt(tree.id);
86
86
  });
87
87
 
88
88
  /*
89
89
  * Footer
90
90
  */
91
- this._outBufferToWar.addInt(0); // special doodad format number, fixed at 0x00
92
- this._outBufferToWar.addInt(0); // NOT SUPPORTED: number of special doodads
91
+ outBufferToWar.addInt(0); // special doodad format number, fixed at 0x00
92
+ outBufferToWar.addInt(0); // NOT SUPPORTED: number of special doodads
93
93
 
94
94
  return {
95
95
  errors: [],
96
- buffer: this._outBufferToWar.getBuffer()
96
+ buffer: outBufferToWar.getBuffer()
97
97
  };
98
98
  }
99
99
 
100
- public warToJson(buffer: Buffer) {
100
+ public static warToJson(buffer: Buffer): JsonResult<Doodad[]> {
101
101
  const result = [];
102
- this._outBufferToJSON = new W3Buffer(buffer);
102
+ const outBufferToJSON = new W3Buffer(buffer);
103
103
 
104
- const fileId = this._outBufferToJSON.readChars(4); // W3do for doodad file
105
- const fileVersion = this._outBufferToJSON.readInt(); // File version = 8
106
- const subVersion = this._outBufferToJSON.readInt(); // 0B 00 00 00
107
- const numDoodads = this._outBufferToJSON.readInt(); // # of doodads
104
+ const fileId = outBufferToJSON.readChars(4); // W3do for doodad file
105
+ const fileVersion = outBufferToJSON.readInt(); // File version = 8
106
+ const subVersion = outBufferToJSON.readInt(); // 0B 00 00 00
107
+ const numDoodads = outBufferToJSON.readInt(); // # of doodads
108
108
 
109
109
  for (let i = 0; i < numDoodads; i++) {
110
110
  const doodad: Doodad = {
@@ -113,59 +113,61 @@ export class DoodadsTranslator {
113
113
  position: [0, 0, 0],
114
114
  angle: -1,
115
115
  scale: [0, 0, 0],
116
+ skinId: '',
116
117
  flags: { visible: flag.visible, solid: flag.solid },
117
118
  life: -1,
118
119
  id: -1
119
120
  };
120
121
 
121
- doodad.type = this._outBufferToJSON.readChars(4);
122
- doodad.variation = this._outBufferToJSON.readInt();
123
- doodad.position = [this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat()]; // X Y Z coords
122
+ doodad.type = outBufferToJSON.readChars(4);
123
+ doodad.variation = outBufferToJSON.readInt();
124
+ doodad.position = [outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat()]; // X Y Z coords
124
125
 
125
126
  // Angle
126
127
  // Doodads format is unique because it uses radians for angles, as opposed
127
128
  // to angles in any other file which use degrees. Hence conversion is needed.
128
129
  // war3map: Expects angle in RADIANS
129
130
  // JSON: Spec defines angle in DEGREES
130
- doodad.angle = rad2Deg(this._outBufferToJSON.readFloat());
131
+ doodad.angle = rad2Deg(outBufferToJSON.readFloat());
131
132
 
132
- doodad.scale = [this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat()]; // X Y Z scaling
133
+ doodad.scale = [outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat()]; // X Y Z scaling
134
+ doodad.skinId = outBufferToJSON.readChars(4);
133
135
 
134
- const flags: flag = this._outBufferToJSON.readByte();
136
+ const flags: flag = outBufferToJSON.readByte();
135
137
  doodad.flags = {
136
138
  visible: flags === 1 || flags === 2,
137
139
  solid: flags === 2
138
140
  };
139
141
 
140
- doodad.life = this._outBufferToJSON.readByte(); // as a %
142
+ doodad.life = outBufferToJSON.readByte(); // as a %
141
143
 
142
144
  // UNSUPPORTED: random item set drops when doodad is destroyed/killed
143
145
  // This section just consumes the bytes from the file
144
- const randomItemSetPtr = this._outBufferToJSON.readInt(); // points to an item set defined in the map (rather than custom one defined below)
145
- const numberOfItemSets = this._outBufferToJSON.readInt(); // this should be 0 if randomItemSetPtr is >= 0
146
+ const randomItemSetPtr = outBufferToJSON.readInt(); // points to an item set defined in the map (rather than custom one defined below)
147
+ const numberOfItemSets = outBufferToJSON.readInt(); // this should be 0 if randomItemSetPtr is >= 0
146
148
 
147
149
  for (let j = 0; j < numberOfItemSets; j++) {
148
150
  // Read the item set
149
- const numberOfItems = this._outBufferToJSON.readInt();
151
+ const numberOfItems = outBufferToJSON.readInt();
150
152
  for (let k = 0; k < numberOfItems; k++) {
151
- this._outBufferToJSON.readChars(4); // Item ID
152
- this._outBufferToJSON.readInt(); // % chance to drop
153
+ outBufferToJSON.readChars(4); // Item ID
154
+ outBufferToJSON.readInt(); // % chance to drop
153
155
  }
154
156
  }
155
157
 
156
- doodad.id = this._outBufferToJSON.readInt();
158
+ doodad.id = outBufferToJSON.readInt();
157
159
 
158
160
  result.push(doodad);
159
161
  }
160
162
 
161
163
  // UNSUPPORTED: Special doodads
162
- this._outBufferToJSON.readInt(); // special doodad format version set to '0'
163
- const numSpecialDoodads = this._outBufferToJSON.readInt();
164
+ outBufferToJSON.readInt(); // special doodad format version set to '0'
165
+ const numSpecialDoodads = outBufferToJSON.readInt();
164
166
  for (let i = 0; i < numSpecialDoodads; i++) {
165
- this._outBufferToJSON.readChars(4); // doodad ID
166
- this._outBufferToJSON.readInt();
167
- this._outBufferToJSON.readInt();
168
- this._outBufferToJSON.readInt();
167
+ outBufferToJSON.readChars(4); // doodad ID
168
+ outBufferToJSON.readInt();
169
+ outBufferToJSON.readInt();
170
+ outBufferToJSON.readInt();
169
171
  }
170
172
 
171
173
  return {
@@ -1,9 +1,10 @@
1
1
  import { HexBuffer } from '../HexBuffer';
2
2
  import { W3Buffer } from '../W3Buffer';
3
+ import { WarResult, JsonResult } from '../CommonInterfaces'
3
4
 
4
5
  enum ImportType {
5
- Standard,
6
- Custom
6
+ Standard = 'standard',
7
+ Custom = 'custom'
7
8
  }
8
9
 
9
10
  interface Import {
@@ -13,60 +14,57 @@ interface Import {
13
14
 
14
15
  export class ImportsTranslator {
15
16
 
16
- private _outBufferToWar: HexBuffer;
17
- private _outBufferToJSON: W3Buffer;
18
-
19
- constructor() { }
20
-
21
- public jsonToWar(imports: Import[]) {
22
- this._outBufferToWar = new HexBuffer();
17
+ public static jsonToWar(imports: Import[]): WarResult {
18
+ const outBufferToWar = new HexBuffer();
23
19
 
24
20
  /*
25
21
  * Header
26
22
  */
27
- this._outBufferToWar.addInt(1); // file version
28
- this._outBufferToWar.addInt(imports.length); // number of imports
23
+ outBufferToWar.addInt(1); // file version
24
+ outBufferToWar.addInt(imports.length); // number of imports
29
25
 
30
26
  /*
31
27
  * Body
32
28
  */
33
29
  imports.forEach((importedFile) => {
34
- this._outBufferToWar.addByte(
35
- importedFile.type === ImportType.Custom ? 13 : 8
30
+ outBufferToWar.addByte(
31
+ importedFile.type === ImportType.Custom ? 13 : 5
36
32
  );
37
33
 
38
- // Temporary (disabled): always start the file path with war3mapImported\ until other file support is added
39
- // if (!importedFile.path.startsWith('war3mapImported\\') && importedFile.type === 'custom') {
40
- // importedFile.path = 'war3mapImported\\' + importedFile.path;
41
- // }
34
+ // Temporary: always start the file path with war3mapImported\ until other file support is added
35
+ if (!importedFile.path.startsWith('war3mapImported\\') && importedFile.type === ImportType.Custom) {
36
+ importedFile.path = 'war3mapImported\\' + importedFile.path;
37
+ }
42
38
 
43
- this._outBufferToWar.addString(importedFile.path, true);
39
+ outBufferToWar.addString(importedFile.path);
44
40
  });
45
41
 
46
42
  return {
47
43
  errors: [],
48
- buffer: this._outBufferToWar.getBuffer()
44
+ buffer: outBufferToWar.getBuffer()
49
45
  };
50
46
  }
51
47
 
52
- public warToJson(buffer: Buffer) {
48
+ public static warToJson(buffer: Buffer): JsonResult<Import[]> {
53
49
  const result = [];
54
- this._outBufferToJSON = new W3Buffer(buffer);
50
+ const outBufferToJSON = new W3Buffer(buffer);
55
51
 
56
- const fileVersion = this._outBufferToJSON.readInt(); // File version
57
- const numImports = this._outBufferToJSON.readInt(); // # of imports
52
+ const fileVersion = outBufferToJSON.readInt(); // File version
53
+ const numImports = outBufferToJSON.readInt(); // # of imports
58
54
 
59
55
  for (let i = 0; i < numImports; i++) {
60
- const typeValue = this._outBufferToJSON.readByte();
61
-
62
- // Standard: 0, 5, 8*
63
- // Custom: 10, 13*
64
- // * = World Editor uses this value
65
- const importType = [0, 5, 8].indexOf(typeValue) !== -1 ? ImportType.Standard : ImportType.Custom;
56
+ const typeValue = outBufferToJSON.readByte();
57
+ const typeEnum = {
58
+ 0: 'standard',
59
+ 5: 'standard',
60
+ 8: 'standard', // * preferred
61
+ 10: 'custom',
62
+ 13: 'custom' // * preferred
63
+ };
66
64
 
67
65
  const importedFile = {
68
- type: importType,
69
- path: this._outBufferToJSON.readString() // e.g. "war3mapImported\mysound.wav"
66
+ type: typeEnum[typeValue], // 5 or 8= standard path, 10 or 13: custom path
67
+ path: outBufferToJSON.readString() // e.g. "war3mapImported\mysound.wav"
70
68
  };
71
69
 
72
70
  result.push(importedFile);