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,5 +1,6 @@
|
|
|
1
|
-
import { HexBuffer } from '
|
|
2
|
-
import { W3Buffer } from '
|
|
1
|
+
import { HexBuffer } from '../HexBuffer';
|
|
2
|
+
import { W3Buffer } from '../W3Buffer';
|
|
3
|
+
import { WarResult, JsonResult } from '../CommonInterfaces'
|
|
3
4
|
|
|
4
5
|
enum TableType {
|
|
5
6
|
original = 'original',
|
|
@@ -13,6 +14,26 @@ enum ModificationType {
|
|
|
13
14
|
string = 'string'
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
enum FileTypeExtension { // (*) - uses the two optional ints after variable type
|
|
18
|
+
units = 'w3u',
|
|
19
|
+
items = 'w3t',
|
|
20
|
+
destructables = 'w3b',
|
|
21
|
+
doodads = 'w3d', // (*)
|
|
22
|
+
abilities = 'w3a', // (*)
|
|
23
|
+
buffs = 'w3h',
|
|
24
|
+
upgrades = 'w3q' // (*)
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
enum ObjectType {
|
|
28
|
+
Units = 'units',
|
|
29
|
+
Items = 'items',
|
|
30
|
+
Destructables = 'destructables',
|
|
31
|
+
Doodads = 'doodads',
|
|
32
|
+
Abilities = 'abilities',
|
|
33
|
+
Buffs = 'buffs',
|
|
34
|
+
Upgrades = 'upgrades'
|
|
35
|
+
};
|
|
36
|
+
|
|
16
37
|
interface Modification {
|
|
17
38
|
id: string;
|
|
18
39
|
type: ModificationType; // 'int' | 'real' | 'unreal' | 'string',
|
|
@@ -26,54 +47,36 @@ interface Modification {
|
|
|
26
47
|
variation?: number;
|
|
27
48
|
}
|
|
28
49
|
|
|
29
|
-
|
|
50
|
+
interface ObjectModificationTable {
|
|
51
|
+
original: object,
|
|
52
|
+
custom: object
|
|
53
|
+
}
|
|
30
54
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
export abstract class ObjectsTranslator {
|
|
56
|
+
|
|
57
|
+
// Expose the ObjectType enum as part of this abstract class
|
|
58
|
+
// The enum could be "export"ed , but it wouldn't be accessible
|
|
59
|
+
// via `ObjectsTranslator.ObjectType`, which is preferable.
|
|
60
|
+
public static readonly ObjectType = ObjectType;
|
|
61
|
+
|
|
62
|
+
private static varTypes = {
|
|
63
|
+
int: 0,
|
|
64
|
+
real: 1,
|
|
65
|
+
unreal: 2,
|
|
66
|
+
string: 3,
|
|
67
|
+
0: 'int',
|
|
68
|
+
1: 'real',
|
|
69
|
+
2: 'unreal',
|
|
70
|
+
3: 'string'
|
|
39
71
|
};
|
|
40
72
|
|
|
41
|
-
public
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
private _outBufferToWar: HexBuffer;
|
|
45
|
-
private _outBufferToJSON: W3Buffer;
|
|
46
|
-
|
|
47
|
-
constructor() {
|
|
48
|
-
this.varTypes = {
|
|
49
|
-
int: 0,
|
|
50
|
-
real: 1,
|
|
51
|
-
unreal: 2,
|
|
52
|
-
string: 3,
|
|
53
|
-
0: 'int',
|
|
54
|
-
1: 'real',
|
|
55
|
-
2: 'unreal',
|
|
56
|
-
3: 'string'
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
this.fileTypeExt = { // (*) - uses the two optional ints after variable type
|
|
60
|
-
units: 'w3u',
|
|
61
|
-
items: 'w3t',
|
|
62
|
-
destructables: 'w3b',
|
|
63
|
-
doodads: 'w3d', // (*)
|
|
64
|
-
abilities: 'w3a', // (*)
|
|
65
|
-
buffs: 'w3h',
|
|
66
|
-
upgrades: 'w3q' // (*)
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public jsonToWar(type: string, json) {
|
|
71
|
-
this._outBufferToWar = new HexBuffer();
|
|
73
|
+
public static jsonToWar(type: string, json): WarResult {
|
|
74
|
+
const outBufferToWar = new HexBuffer();
|
|
72
75
|
|
|
73
76
|
/*
|
|
74
77
|
* Header
|
|
75
78
|
*/
|
|
76
|
-
|
|
79
|
+
outBufferToWar.addInt(2); // file version
|
|
77
80
|
|
|
78
81
|
const generateTableFromJson = (tableType: TableType, tableData) => { // create "original" or "custom" table
|
|
79
82
|
Object.keys(tableData).forEach((defKey) => {
|
|
@@ -81,22 +84,22 @@ export class ObjectsTranslator {
|
|
|
81
84
|
|
|
82
85
|
// Original and new object ids
|
|
83
86
|
if (tableType === TableType.original) {
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
outBufferToWar.addChars(defKey);
|
|
88
|
+
outBufferToWar.addByte(0); outBufferToWar.addByte(0); outBufferToWar.addByte(0); outBufferToWar.addByte(0); // no new Id is assigned
|
|
86
89
|
} else {
|
|
87
90
|
// e.g. "h000:hfoo"
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
outBufferToWar.addChars(defKey.substring(5, 9)); // original id
|
|
92
|
+
outBufferToWar.addChars(defKey.substring(0, 4)); // custom id
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
// Number of modifications made to this object
|
|
93
|
-
|
|
96
|
+
outBufferToWar.addInt(obj.length);
|
|
94
97
|
|
|
95
98
|
obj.forEach((mod: Modification) => {
|
|
96
99
|
let modType;
|
|
97
100
|
|
|
98
101
|
// Modification id (e.g. unam = name; reference MetaData lookups)
|
|
99
|
-
|
|
102
|
+
outBufferToWar.addChars(mod.id);
|
|
100
103
|
|
|
101
104
|
// Determine what type of field the mod is (int, real, unreal, string)
|
|
102
105
|
if (mod.type) { // if a type is specified, use it
|
|
@@ -111,43 +114,42 @@ export class ObjectsTranslator {
|
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
|
|
117
|
+
outBufferToWar.addInt(modType);
|
|
115
118
|
|
|
116
119
|
// Addl integers
|
|
117
120
|
// Required for: doodads, abilities, upgrades
|
|
118
|
-
if (type ===
|
|
121
|
+
if (type === ObjectType.Doodads || type === ObjectType.Abilities || type === ObjectType.Upgrades) {
|
|
119
122
|
|
|
120
123
|
// Level or variation
|
|
121
124
|
// We need to check if hasOwnProperty because these could be explititly
|
|
122
125
|
// set to 0, but JavaScript's truthiness evaluates to false to it was defaulting
|
|
123
|
-
|
|
126
|
+
outBufferToWar.addInt(mod.level || mod.variation || 0); // defaults to 0
|
|
124
127
|
|
|
125
|
-
|
|
128
|
+
outBufferToWar.addInt(mod.column || 0); // E.g DataA1 is 1 because of col A; refer to the xyzData.slk files for Data fields
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
// Write mod value
|
|
129
132
|
if (modType === this.varTypes.int) {
|
|
130
|
-
|
|
133
|
+
outBufferToWar.addInt(mod.value);
|
|
131
134
|
} else if (modType === this.varTypes.real || modType === this.varTypes.unreal) {
|
|
132
135
|
// Follow-up: check if unreal values are same hex format as real
|
|
133
|
-
|
|
136
|
+
outBufferToWar.addFloat(mod.value);
|
|
134
137
|
} else if (modType === this.varTypes.string) {
|
|
135
138
|
// Note that World Editor normally creates a TRIGSTR_000 for these string
|
|
136
139
|
// values - WC3MapTranslator just writes the string directly to file
|
|
137
|
-
|
|
138
|
-
this._outBufferToWar.addNullTerminator();
|
|
140
|
+
outBufferToWar.addString(mod.value);
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
// End of struct
|
|
142
144
|
if (tableType === TableType.original) {
|
|
143
145
|
// Original objects are ended with their base id (e.g. hfoo)
|
|
144
|
-
|
|
146
|
+
outBufferToWar.addChars(defKey);
|
|
145
147
|
} else {
|
|
146
148
|
// Custom objects are ended with 0000 bytes
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
outBufferToWar.addByte(0);
|
|
150
|
+
outBufferToWar.addByte(0);
|
|
151
|
+
outBufferToWar.addByte(0);
|
|
152
|
+
outBufferToWar.addByte(0);
|
|
151
153
|
}
|
|
152
154
|
});
|
|
153
155
|
});
|
|
@@ -156,36 +158,36 @@ export class ObjectsTranslator {
|
|
|
156
158
|
/*
|
|
157
159
|
* Original table
|
|
158
160
|
*/
|
|
159
|
-
|
|
161
|
+
outBufferToWar.addInt(Object.keys(json.original).length);
|
|
160
162
|
generateTableFromJson(TableType.original, json.original);
|
|
161
163
|
|
|
162
164
|
/*
|
|
163
165
|
* Custom table
|
|
164
166
|
*/
|
|
165
|
-
|
|
167
|
+
outBufferToWar.addInt(Object.keys(json.custom).length); // # entry modifications
|
|
166
168
|
generateTableFromJson(TableType.custom, json.custom);
|
|
167
169
|
|
|
168
170
|
return {
|
|
169
171
|
errors: [],
|
|
170
|
-
buffer:
|
|
172
|
+
buffer: outBufferToWar.getBuffer()
|
|
171
173
|
};
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
public warToJson(type: string, buffer: Buffer) {
|
|
176
|
+
public static warToJson(type: string, buffer: Buffer): JsonResult<ObjectModificationTable> {
|
|
175
177
|
const result = { original: {}, custom: {} };
|
|
176
|
-
|
|
178
|
+
const outBufferToJSON = new W3Buffer(buffer);
|
|
177
179
|
|
|
178
|
-
const fileVersion =
|
|
180
|
+
const fileVersion = outBufferToJSON.readInt();
|
|
179
181
|
|
|
180
182
|
const readModificationTable = (isOriginalTable: boolean) => {
|
|
181
|
-
const numTableModifications =
|
|
183
|
+
const numTableModifications = outBufferToJSON.readInt();
|
|
182
184
|
|
|
183
185
|
for (let i = 0; i < numTableModifications; i++) {
|
|
184
186
|
const objectDefinition = []; // object definition will store one or more modification objects
|
|
185
187
|
|
|
186
|
-
const originalId =
|
|
187
|
-
customId =
|
|
188
|
-
modificationCount =
|
|
188
|
+
const originalId = outBufferToJSON.readChars(4),
|
|
189
|
+
customId = outBufferToJSON.readChars(4),
|
|
190
|
+
modificationCount = outBufferToJSON.readInt();
|
|
189
191
|
|
|
190
192
|
for (let j = 0; j < modificationCount; j++) {
|
|
191
193
|
const modification: Modification = {
|
|
@@ -196,26 +198,26 @@ export class ObjectsTranslator {
|
|
|
196
198
|
value: {}
|
|
197
199
|
};
|
|
198
200
|
|
|
199
|
-
modification.id =
|
|
200
|
-
modification.type = this.varTypes[
|
|
201
|
+
modification.id = outBufferToJSON.readChars(4);
|
|
202
|
+
modification.type = this.varTypes[outBufferToJSON.readInt()]; // 'int' | 'real' | 'unreal' | 'string',
|
|
201
203
|
|
|
202
|
-
if (type ===
|
|
203
|
-
modification.level =
|
|
204
|
-
modification.column =
|
|
204
|
+
if (type === ObjectType.Doodads || type === ObjectType.Abilities || type === ObjectType.Upgrades) {
|
|
205
|
+
modification.level = outBufferToJSON.readInt();
|
|
206
|
+
modification.column = outBufferToJSON.readInt();
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
if (modification.type === 'int') {
|
|
208
|
-
modification.value =
|
|
210
|
+
modification.value = outBufferToJSON.readInt();
|
|
209
211
|
} else if (modification.type === 'real' || modification.type === 'unreal') {
|
|
210
|
-
modification.value =
|
|
212
|
+
modification.value = outBufferToJSON.readFloat();
|
|
211
213
|
} else { // modification.type === 'string'
|
|
212
|
-
modification.value =
|
|
214
|
+
modification.value = outBufferToJSON.readString();
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
if (isOriginalTable) {
|
|
216
|
-
|
|
218
|
+
outBufferToJSON.readInt(); // should be 0 for original objects
|
|
217
219
|
} else {
|
|
218
|
-
|
|
220
|
+
outBufferToJSON.readChars(4); // should be object ID for custom objects
|
|
219
221
|
}
|
|
220
222
|
|
|
221
223
|
objectDefinition.push(modification);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HexBuffer } from '../HexBuffer';
|
|
2
2
|
import { W3Buffer } from '../W3Buffer';
|
|
3
|
+
import { WarResult, JsonResult } from '../CommonInterfaces'
|
|
3
4
|
|
|
4
5
|
interface Region {
|
|
5
6
|
position: Rect;
|
|
@@ -17,21 +18,16 @@ interface Rect {
|
|
|
17
18
|
top: number;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export class RegionsTranslator {
|
|
21
|
+
export abstract class RegionsTranslator {
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
constructor() { }
|
|
26
|
-
|
|
27
|
-
public jsonToWar(regionsJson: Region[]) {
|
|
28
|
-
this._outBufferToWar = new HexBuffer();
|
|
23
|
+
public static jsonToWar(regionsJson: Region[]): WarResult {
|
|
24
|
+
const outBufferToWar = new HexBuffer();
|
|
29
25
|
|
|
30
26
|
/*
|
|
31
27
|
* Header
|
|
32
28
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
outBufferToWar.addInt(5); // file version
|
|
30
|
+
outBufferToWar.addInt(regionsJson.length); // number of regions
|
|
35
31
|
|
|
36
32
|
/*
|
|
37
33
|
* Body
|
|
@@ -39,59 +35,51 @@ export class RegionsTranslator {
|
|
|
39
35
|
regionsJson.forEach((region) => {
|
|
40
36
|
// Position
|
|
41
37
|
// Note that the .w3x guide has these coords wrong - the guide swaps bottom and right, but this is incorrect; bottom should be written before right
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
outBufferToWar.addFloat(region.position.left);
|
|
39
|
+
outBufferToWar.addFloat(region.position.bottom);
|
|
40
|
+
outBufferToWar.addFloat(region.position.right);
|
|
41
|
+
outBufferToWar.addFloat(region.position.top);
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this._outBufferToWar.addNullTerminator();
|
|
50
|
-
|
|
51
|
-
// Region id
|
|
52
|
-
this._outBufferToWar.addInt(region.id);
|
|
43
|
+
outBufferToWar.addString(region.name);
|
|
44
|
+
outBufferToWar.addInt(region.id);
|
|
53
45
|
|
|
54
46
|
// Weather effect name - lookup necessary: char[4]
|
|
55
47
|
if (region.weatherEffect) {
|
|
56
|
-
|
|
48
|
+
outBufferToWar.addChars(region.weatherEffect); // Weather effect is optional - defaults to 0000 for "none"
|
|
57
49
|
} else {
|
|
58
|
-
//
|
|
59
|
-
|
|
50
|
+
// We can't put a string "0000", because ASCII 0's differ from 0x0 bytes
|
|
51
|
+
outBufferToWar.addByte(0);
|
|
52
|
+
outBufferToWar.addByte(0);
|
|
53
|
+
outBufferToWar.addByte(0);
|
|
54
|
+
outBufferToWar.addByte(0);
|
|
60
55
|
}
|
|
61
56
|
|
|
62
57
|
// Ambient sound - refer to names defined in .w3s file
|
|
63
|
-
|
|
64
|
-
this._outBufferToWar.addNullTerminator();
|
|
58
|
+
outBufferToWar.addString(region.ambientSound || ''); // May be empty string
|
|
65
59
|
|
|
66
60
|
// Color of region used by editor
|
|
67
61
|
// Careful! The order in .w3r is BB GG RR, whereas the JSON spec order is [RR, GG, BB]
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this._outBufferToWar.addByte(0); // red
|
|
72
|
-
} else {
|
|
73
|
-
this._outBufferToWar.addByte(region.color[2]); // blue
|
|
74
|
-
this._outBufferToWar.addByte(region.color[1]); // green
|
|
75
|
-
this._outBufferToWar.addByte(region.color[0]); // red
|
|
76
|
-
}
|
|
62
|
+
outBufferToWar.addByte(region.color[2]); // blue
|
|
63
|
+
outBufferToWar.addByte(region.color[1]); // green
|
|
64
|
+
outBufferToWar.addByte(region.color[0]); // red
|
|
77
65
|
|
|
78
66
|
// End of structure - for some reason the .w3r needs this here;
|
|
79
67
|
// Value is set to 0xff based on observing the .w3r file, but not sure if it could be something else
|
|
80
|
-
|
|
68
|
+
outBufferToWar.addByte(0xff);
|
|
81
69
|
});
|
|
82
70
|
|
|
83
71
|
return {
|
|
84
72
|
errors: [],
|
|
85
|
-
buffer:
|
|
73
|
+
buffer: outBufferToWar.getBuffer()
|
|
86
74
|
};
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
public warToJson(buffer: Buffer) {
|
|
77
|
+
public static warToJson(buffer: Buffer): JsonResult<Region[]> {
|
|
90
78
|
const result = [];
|
|
91
|
-
|
|
79
|
+
const outBufferToJSON = new W3Buffer(buffer);
|
|
92
80
|
|
|
93
|
-
const fileVersion =
|
|
94
|
-
numRegions =
|
|
81
|
+
const fileVersion = outBufferToJSON.readInt(), // File version
|
|
82
|
+
numRegions = outBufferToJSON.readInt(); // # of regions
|
|
95
83
|
|
|
96
84
|
for (let i = 0; i < numRegions; i++) {
|
|
97
85
|
const region: Region = {
|
|
@@ -108,27 +96,21 @@ export class RegionsTranslator {
|
|
|
108
96
|
}
|
|
109
97
|
};
|
|
110
98
|
|
|
111
|
-
region.position.left =
|
|
112
|
-
region.position.bottom =
|
|
113
|
-
region.position.right =
|
|
114
|
-
region.position.top =
|
|
115
|
-
region.name =
|
|
116
|
-
region.id =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// war3map uses "0000" as literal characters to indicate no weather effect, but
|
|
120
|
-
// for the JSON format we use an empty string for this purpose, hence the check
|
|
121
|
-
region.weatherEffect = this._outBufferToJSON.readChars(4);
|
|
122
|
-
if (region.weatherEffect === '0000') region.weatherEffect = '';
|
|
123
|
-
|
|
124
|
-
region.ambientSound = this._outBufferToJSON.readString();
|
|
99
|
+
region.position.left = outBufferToJSON.readFloat();
|
|
100
|
+
region.position.bottom = outBufferToJSON.readFloat();
|
|
101
|
+
region.position.right = outBufferToJSON.readFloat();
|
|
102
|
+
region.position.top = outBufferToJSON.readFloat();
|
|
103
|
+
region.name = outBufferToJSON.readString();
|
|
104
|
+
region.id = outBufferToJSON.readInt();
|
|
105
|
+
region.weatherEffect = outBufferToJSON.readChars(4);
|
|
106
|
+
region.ambientSound = outBufferToJSON.readString();
|
|
125
107
|
region.color = [
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
108
|
+
outBufferToJSON.readByte(), // red
|
|
109
|
+
outBufferToJSON.readByte(), // green
|
|
110
|
+
outBufferToJSON.readByte() // blue
|
|
129
111
|
];
|
|
130
112
|
region.color.reverse(); // json wants it in RGB, but .w3r file stores it as BB GG RR
|
|
131
|
-
|
|
113
|
+
outBufferToJSON.readByte(); // end of region structure
|
|
132
114
|
|
|
133
115
|
result.push(region);
|
|
134
116
|
}
|