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.
- package/.codeclimate.yml +0 -1
- package/.eslintignore +0 -1
- package/.github/workflows/codeql-analysis.yml +54 -0
- package/.nycrc +1 -2
- package/.travis.yml +1 -2
- package/CHANGELOG.md +78 -0
- package/LICENSE.md +23 -0
- package/README.md +68 -75
- package/index.js +11 -15
- package/index.ts +12 -30
- package/lib/CommonInterfaces.ts +22 -0
- package/lib/HexBuffer.ts +11 -14
- package/lib/W3Buffer.ts +7 -3
- package/lib/translators/CamerasTranslator.ts +36 -41
- package/lib/translators/DoodadsTranslator.ts +57 -55
- package/lib/translators/ImportsTranslator.ts +29 -31
- package/lib/translators/InfoTranslator.ts +252 -204
- package/lib/translators/{object/ObjectsTranslator.ts → ObjectsTranslator.ts} +84 -82
- package/lib/translators/RegionsTranslator.ts +40 -58
- package/lib/translators/SoundsTranslator.ts +112 -96
- package/lib/translators/StringsTranslator.ts +23 -49
- package/lib/translators/TerrainTranslator.ts +166 -97
- package/lib/translators/UnitsTranslator.ts +98 -97
- package/lib/translators/index.ts +0 -1
- package/package.json +23 -16
- package/test/.mocharc.json +4 -0
- package/test/HexBufferTest.ts +11 -15
- package/test/TranslatorReversion.ts +104 -115
- package/test/W3BufferTest.ts +19 -13
- package/test/data/cameras.json +16 -0
- package/test/data/doodads.json +2730 -0
- package/test/data/imports.json +386 -0
- package/test/data/info.json +250 -0
- package/test/data/obj-abilities.json +4892 -0
- package/test/data/obj-buffs.json +38 -0
- package/test/data/obj-destructables.json +31 -0
- package/test/data/obj-doodads.json +38 -0
- package/test/data/obj-items.json +31 -0
- package/test/data/obj-units.json +40 -0
- package/test/data/obj-upgrades.json +38 -0
- package/test/data/regions.json +206 -0
- package/test/data/sounds.json +50 -0
- package/test/data/strings.json +115 -0
- package/test/data/terrain.json +1 -0
- package/test/data/units.json +452 -0
- package/test/data/war3map.doo +0 -0
- package/test/data/war3map.imp +0 -0
- package/test/data/war3map.j +3442 -0
- package/test/data/war3map.shd +0 -0
- package/test/data/war3map.w3a +0 -0
- package/test/data/war3map.w3b +0 -0
- package/test/data/war3map.w3c +0 -0
- package/test/data/war3map.w3d +0 -0
- package/test/data/war3map.w3e +0 -0
- package/test/data/war3map.w3h +0 -0
- package/test/data/war3map.w3i +0 -0
- package/test/data/war3map.w3q +0 -0
- package/test/data/war3map.w3r +0 -0
- package/test/data/war3map.w3s +0 -0
- package/test/data/war3map.w3t +0 -0
- package/test/data/war3map.w3u +0 -0
- package/test/data/war3map.wts +631 -0
- package/test/data/war3mapUnits.doo +0 -0
- package/examples/index.js +0 -123
- package/examples/index.ts +0 -134
- package/examples/json/cameras.json +0 -16
- package/examples/json/doodads.json +0 -28499
- package/examples/json/imports.json +0 -10
- package/examples/json/info.json +0 -111
- package/examples/json/object-abilities.json +0 -31
- package/examples/json/object-buffs.json +0 -24
- package/examples/json/object-destructables.json +0 -31
- package/examples/json/object-doodads.json +0 -24
- package/examples/json/object-items.json +0 -45
- package/examples/json/object-units.json +0 -45
- package/examples/json/object-upgrades.json +0 -31
- package/examples/json/regions.json +0 -36
- package/examples/json/sounds.json +0 -46
- package/examples/json/strings.json +0 -83
- package/examples/json/terrain.json +0 -46633
- package/examples/json/units.json +0 -332
- package/examples/package.json +0 -17
- package/examples/tsconfig.json +0 -27
- package/examples/war/war3map.doo +0 -0
- package/examples/war/war3map.imp +0 -0
- package/examples/war/war3map.w3a +0 -0
- package/examples/war/war3map.w3b +0 -0
- package/examples/war/war3map.w3c +0 -0
- package/examples/war/war3map.w3d +0 -0
- package/examples/war/war3map.w3e +0 -0
- package/examples/war/war3map.w3h +0 -0
- package/examples/war/war3map.w3i +0 -0
- package/examples/war/war3map.w3q +0 -0
- package/examples/war/war3map.w3r +0 -0
- package/examples/war/war3map.w3s +0 -0
- package/examples/war/war3map.w3t +0 -0
- package/examples/war/war3map.w3u +0 -0
- package/examples/war/war3map.wts +0 -99
- package/lib/translators/index.js +0 -16
- 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:
|
|
8
|
-
aoa:
|
|
8
|
+
rotation: angle;
|
|
9
|
+
aoa: angle; // angle of attack
|
|
9
10
|
distance: number;
|
|
10
11
|
roll: number;
|
|
11
|
-
fov:
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
this._outBufferToWar.addNullTerminator();
|
|
49
|
+
outBufferToWar.addString(camera.name);
|
|
55
50
|
});
|
|
56
51
|
|
|
57
52
|
return {
|
|
58
53
|
errors: [],
|
|
59
|
-
buffer:
|
|
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
|
-
|
|
60
|
+
const outBufferToJSON = new W3Buffer(buffer);
|
|
66
61
|
|
|
67
|
-
const fileVersion =
|
|
68
|
-
numCameras =
|
|
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 =
|
|
87
|
-
camera.target.y =
|
|
88
|
-
camera.offsetZ =
|
|
89
|
-
camera.rotation =
|
|
90
|
-
camera.aoa =
|
|
91
|
-
camera.distance =
|
|
92
|
-
camera.roll =
|
|
93
|
-
camera.fov =
|
|
94
|
-
camera.farClipping =
|
|
95
|
-
|
|
96
|
-
camera.name =
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
80
|
+
outBufferToWar.addByte(treeFlag);
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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:
|
|
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
|
-
|
|
102
|
+
const outBufferToJSON = new W3Buffer(buffer);
|
|
103
103
|
|
|
104
|
-
const fileId =
|
|
105
|
-
const fileVersion =
|
|
106
|
-
const subVersion =
|
|
107
|
-
const numDoodads =
|
|
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 =
|
|
122
|
-
doodad.variation =
|
|
123
|
-
doodad.position = [
|
|
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(
|
|
131
|
+
doodad.angle = rad2Deg(outBufferToJSON.readFloat());
|
|
131
132
|
|
|
132
|
-
doodad.scale = [
|
|
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 =
|
|
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 =
|
|
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 =
|
|
145
|
-
const numberOfItemSets =
|
|
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 =
|
|
151
|
+
const numberOfItems = outBufferToJSON.readInt();
|
|
150
152
|
for (let k = 0; k < numberOfItems; k++) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
outBufferToJSON.readChars(4); // Item ID
|
|
154
|
+
outBufferToJSON.readInt(); // % chance to drop
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
doodad.id =
|
|
158
|
+
doodad.id = outBufferToJSON.readInt();
|
|
157
159
|
|
|
158
160
|
result.push(doodad);
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
// UNSUPPORTED: Special doodads
|
|
162
|
-
|
|
163
|
-
const numSpecialDoodads =
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
35
|
-
importedFile.type === ImportType.Custom ? 13 :
|
|
30
|
+
outBufferToWar.addByte(
|
|
31
|
+
importedFile.type === ImportType.Custom ? 13 : 5
|
|
36
32
|
);
|
|
37
33
|
|
|
38
|
-
// Temporary
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
39
|
+
outBufferToWar.addString(importedFile.path);
|
|
44
40
|
});
|
|
45
41
|
|
|
46
42
|
return {
|
|
47
43
|
errors: [],
|
|
48
|
-
buffer:
|
|
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
|
-
|
|
50
|
+
const outBufferToJSON = new W3Buffer(buffer);
|
|
55
51
|
|
|
56
|
-
const fileVersion =
|
|
57
|
-
const numImports =
|
|
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 =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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:
|
|
69
|
-
path:
|
|
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);
|