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,11 +1,12 @@
|
|
|
1
1
|
import { HexBuffer } from '../HexBuffer';
|
|
2
2
|
import { W3Buffer } from '../W3Buffer';
|
|
3
|
+
import { WarResult, JsonResult, angle } from '../CommonInterfaces'
|
|
3
4
|
|
|
4
5
|
interface Unit {
|
|
5
6
|
type: string;
|
|
6
7
|
variation: number;
|
|
7
8
|
position: number[];
|
|
8
|
-
rotation:
|
|
9
|
+
rotation: angle;
|
|
9
10
|
scale: number[];
|
|
10
11
|
hero: Hero;
|
|
11
12
|
inventory: Inventory[];
|
|
@@ -37,112 +38,110 @@ interface Abilities {
|
|
|
37
38
|
level: number;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export class UnitsTranslator {
|
|
41
|
+
export abstract class UnitsTranslator {
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
constructor() { }
|
|
46
|
-
|
|
47
|
-
public jsonToWar(unitsJson: Unit[]) {
|
|
48
|
-
this._outBufferToWar = new HexBuffer();
|
|
43
|
+
public static jsonToWar(unitsJson: Unit[]): WarResult {
|
|
44
|
+
const outBufferToWar = new HexBuffer();
|
|
49
45
|
|
|
50
46
|
/*
|
|
51
47
|
* Header
|
|
52
48
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
outBufferToWar.addChars('W3do');
|
|
50
|
+
outBufferToWar.addInt(8);
|
|
51
|
+
outBufferToWar.addInt(11);
|
|
52
|
+
outBufferToWar.addInt(unitsJson.length); // number of units
|
|
57
53
|
|
|
58
54
|
/*
|
|
59
55
|
* Body
|
|
60
56
|
*/
|
|
61
57
|
unitsJson.forEach((unit) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
outBufferToWar.addChars(unit.type); // type
|
|
59
|
+
outBufferToWar.addInt(unit.variation || 0); // variation
|
|
60
|
+
outBufferToWar.addFloat(unit.position[0]); // position x
|
|
61
|
+
outBufferToWar.addFloat(unit.position[1]); // position y
|
|
62
|
+
outBufferToWar.addFloat(unit.position[2]); // position z
|
|
63
|
+
outBufferToWar.addFloat(unit.rotation || 0); // rotation angle
|
|
68
64
|
|
|
69
65
|
if (!unit.scale) unit.scale = [1, 1, 1];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
outBufferToWar.addFloat(unit.scale[0] || 1); // scale x
|
|
67
|
+
outBufferToWar.addFloat(unit.scale[1] || 1); // scale y
|
|
68
|
+
outBufferToWar.addFloat(unit.scale[2] || 1); // scale z
|
|
73
69
|
|
|
74
70
|
// Unit flags
|
|
75
|
-
|
|
71
|
+
outBufferToWar.addByte(0); // UNSUPPORTED: flags
|
|
76
72
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
outBufferToWar.addInt(0); // unknown
|
|
74
|
+
|
|
75
|
+
outBufferToWar.addInt(unit.player); // player #
|
|
76
|
+
outBufferToWar.addByte(0); // (byte unknown - 0)
|
|
77
|
+
outBufferToWar.addByte(0); // (byte unknown - 0)
|
|
78
|
+
outBufferToWar.addInt(unit.hitpoints); // hitpoints
|
|
79
|
+
outBufferToWar.addInt(unit.mana || 0); // mana
|
|
82
80
|
|
|
83
81
|
// if(unit.droppedItemSets.length === 0) { // needs to be -1 if no item sets
|
|
84
|
-
|
|
82
|
+
outBufferToWar.addInt(-1);
|
|
85
83
|
// }
|
|
86
84
|
// else {
|
|
87
85
|
// outBuffer.addInt(unit.droppedItemSets.length); // # item sets
|
|
88
86
|
// }
|
|
89
87
|
// UNSUPPORTED: dropped items
|
|
90
|
-
|
|
88
|
+
outBufferToWar.addInt(0); // dropped item sets
|
|
91
89
|
|
|
92
90
|
// Gold amount
|
|
93
91
|
// Required if unit is a gold mine
|
|
94
92
|
// Optional (set to zero) if unit is not a gold mine
|
|
95
|
-
|
|
93
|
+
outBufferToWar.addInt(unit.gold);
|
|
94
|
+
// outBufferToWar.addInt(unit.type === 'ngol' ? unit.gold : 0);
|
|
96
95
|
|
|
97
|
-
|
|
96
|
+
outBufferToWar.addFloat(unit.targetAcquisition || 0); // target acquisition
|
|
98
97
|
|
|
99
98
|
// Unit hero attributes
|
|
100
99
|
// Can be left unspecified, but values can never be below 1
|
|
101
100
|
if (!unit.hero) unit.hero = { level: 1, str: 1, agi: 1, int: 1 };
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
outBufferToWar.addInt(unit.hero.level);
|
|
102
|
+
outBufferToWar.addInt(unit.hero.str);
|
|
103
|
+
outBufferToWar.addInt(unit.hero.agi);
|
|
104
|
+
outBufferToWar.addInt(unit.hero.int);
|
|
106
105
|
|
|
107
106
|
// Inventory - - -
|
|
108
107
|
if (!unit.inventory) unit.inventory = [];
|
|
109
|
-
|
|
108
|
+
outBufferToWar.addInt(unit.inventory.length); // # items in inventory
|
|
110
109
|
unit.inventory.forEach((item) => {
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
outBufferToWar.addInt(item.slot - 1); // zero-index item slot
|
|
111
|
+
outBufferToWar.addChars(item.type);
|
|
113
112
|
});
|
|
114
113
|
|
|
115
114
|
// Modified abilities - - -
|
|
116
115
|
if (!unit.abilities) unit.abilities = [];
|
|
117
|
-
|
|
116
|
+
outBufferToWar.addInt(unit.abilities.length); // # modified abilities
|
|
118
117
|
unit.abilities.forEach((ability) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
outBufferToWar.addChars(ability.ability); // ability string
|
|
119
|
+
outBufferToWar.addInt(+ability.active); // 0 = not active, 1 = active
|
|
120
|
+
outBufferToWar.addInt(ability.level);
|
|
122
121
|
});
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
outBufferToWar.addInt(0);
|
|
124
|
+
outBufferToWar.addInt(1);
|
|
126
125
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
outBufferToWar.addInt(unit.color || unit.player); // custom color, defaults to owning player
|
|
127
|
+
outBufferToWar.addInt(0); // outBuffer.addInt(unit.waygate); // UNSUPPORTED - waygate
|
|
128
|
+
outBufferToWar.addInt(unit.id); // id
|
|
130
129
|
});
|
|
131
130
|
|
|
132
131
|
return {
|
|
133
132
|
errors: [],
|
|
134
|
-
buffer:
|
|
133
|
+
buffer: outBufferToWar.getBuffer()
|
|
135
134
|
};
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
public warToJson(buffer: Buffer) {
|
|
137
|
+
public static warToJson(buffer: Buffer): JsonResult<Unit[]> {
|
|
139
138
|
const result = [];
|
|
140
|
-
|
|
139
|
+
const outBufferToJSON = new W3Buffer(buffer);
|
|
141
140
|
|
|
142
|
-
const fileId =
|
|
143
|
-
fileVersion =
|
|
144
|
-
subVersion =
|
|
145
|
-
numUnits =
|
|
141
|
+
const fileId = outBufferToJSON.readChars(4), // W3do for doodad file
|
|
142
|
+
fileVersion = outBufferToJSON.readInt(), // File version = 7
|
|
143
|
+
subVersion = outBufferToJSON.readInt(), // 0B 00 00 00
|
|
144
|
+
numUnits = outBufferToJSON.readInt(); // # of units
|
|
146
145
|
|
|
147
146
|
for (let i = 0; i < numUnits; i++) {
|
|
148
147
|
const unit: Unit = {
|
|
@@ -163,91 +162,93 @@ export class UnitsTranslator {
|
|
|
163
162
|
id: -1
|
|
164
163
|
};
|
|
165
164
|
|
|
166
|
-
unit.type =
|
|
167
|
-
unit.variation =
|
|
168
|
-
unit.position = [
|
|
169
|
-
unit.rotation =
|
|
170
|
-
unit.scale = [
|
|
165
|
+
unit.type = outBufferToJSON.readChars(4); // (iDNR = random item, uDNR = random unit)
|
|
166
|
+
unit.variation = outBufferToJSON.readInt();
|
|
167
|
+
unit.position = [outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat()]; // X Y Z coords
|
|
168
|
+
unit.rotation = outBufferToJSON.readFloat();
|
|
169
|
+
unit.scale = [outBufferToJSON.readFloat(), outBufferToJSON.readFloat(), outBufferToJSON.readFloat()]; // X Y Z scaling
|
|
171
170
|
|
|
172
|
-
const flags = this._outBufferToJSON.readByte();
|
|
173
171
|
// UNSUPPORTED: flags
|
|
172
|
+
const flags = outBufferToJSON.readByte();
|
|
173
|
+
|
|
174
|
+
outBufferToJSON.readInt(); // Unknown
|
|
174
175
|
|
|
175
|
-
unit.player =
|
|
176
|
+
unit.player = outBufferToJSON.readInt(); // (player1 = 0, 16=neutral passive); note: wc3 patch now has 24 max players
|
|
176
177
|
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
outBufferToJSON.readByte(); // unknown
|
|
179
|
+
outBufferToJSON.readByte(); // unknown
|
|
179
180
|
|
|
180
|
-
unit.hitpoints =
|
|
181
|
-
unit.mana =
|
|
181
|
+
unit.hitpoints = outBufferToJSON.readInt(); // -1 = use default
|
|
182
|
+
unit.mana = outBufferToJSON.readInt(); // -1 = use default, 0 = unit doesn't have mana
|
|
182
183
|
|
|
183
|
-
const droppedItemSetPtr =
|
|
184
|
-
numDroppedItemSets =
|
|
184
|
+
const droppedItemSetPtr = outBufferToJSON.readInt(),
|
|
185
|
+
numDroppedItemSets = outBufferToJSON.readInt();
|
|
185
186
|
for (let j = 0; j < numDroppedItemSets; j++) {
|
|
186
|
-
const numDroppableItems =
|
|
187
|
+
const numDroppableItems = outBufferToJSON.readInt();
|
|
187
188
|
for (let k = 0; k < numDroppableItems; k++) {
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
outBufferToJSON.readChars(4); // Item ID
|
|
190
|
+
outBufferToJSON.readInt(); // % chance to drop
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
|
|
193
|
-
unit.gold =
|
|
194
|
-
unit.targetAcquisition =
|
|
194
|
+
unit.gold = outBufferToJSON.readInt();
|
|
195
|
+
unit.targetAcquisition = outBufferToJSON.readFloat(); // (-1 = normal, -2 = camp)
|
|
195
196
|
|
|
196
197
|
unit.hero = {
|
|
197
|
-
level:
|
|
198
|
-
str:
|
|
199
|
-
agi:
|
|
200
|
-
int:
|
|
198
|
+
level: outBufferToJSON.readInt(), // non-hero units = 1
|
|
199
|
+
str: outBufferToJSON.readInt(),
|
|
200
|
+
agi: outBufferToJSON.readInt(),
|
|
201
|
+
int: outBufferToJSON.readInt()
|
|
201
202
|
};
|
|
202
203
|
|
|
203
|
-
const numItemsInventory =
|
|
204
|
+
const numItemsInventory = outBufferToJSON.readInt();
|
|
204
205
|
for (let j = 0; j < numItemsInventory; j++) {
|
|
205
206
|
unit.inventory.push({
|
|
206
|
-
slot:
|
|
207
|
-
type:
|
|
207
|
+
slot: outBufferToJSON.readInt() + 1, // the int is 0-based, but json format wants 1-6
|
|
208
|
+
type: outBufferToJSON.readChars(4) // Item ID
|
|
208
209
|
});
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
const numModifiedAbil =
|
|
212
|
+
const numModifiedAbil = outBufferToJSON.readInt();
|
|
212
213
|
for (let j = 0; j < numModifiedAbil; j++) {
|
|
213
214
|
unit.abilities.push({
|
|
214
|
-
ability:
|
|
215
|
-
active: !!
|
|
216
|
-
level:
|
|
215
|
+
ability: outBufferToJSON.readChars(4), // Ability ID
|
|
216
|
+
active: !!outBufferToJSON.readInt(), // autocast active? 0=no, 1=active
|
|
217
|
+
level: outBufferToJSON.readInt()
|
|
217
218
|
});
|
|
218
219
|
}
|
|
219
220
|
|
|
220
|
-
const randFlag =
|
|
221
|
+
const randFlag = outBufferToJSON.readInt(); // random unit/item flag "r" (for uDNR units and iDNR items)
|
|
221
222
|
if (randFlag === 0) {
|
|
222
223
|
// 0 = Any neutral passive building/item, in this case we have
|
|
223
224
|
// byte[3]: level of the random unit/item,-1 = any (this is actually interpreted as a 24-bit number)
|
|
224
225
|
// byte: item class of the random item, 0 = any, 1 = permanent ... (this is 0 for units)
|
|
225
226
|
// r is also 0 for non random units/items so we have these 4 bytes anyway (even if the id wasnt uDNR or iDNR)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
outBufferToJSON.readByte();
|
|
228
|
+
outBufferToJSON.readByte();
|
|
229
|
+
outBufferToJSON.readByte();
|
|
230
|
+
outBufferToJSON.readByte();
|
|
230
231
|
} else if (randFlag === 1) {
|
|
231
232
|
// 1 = random unit from random group (defined in the w3i), in this case we have
|
|
232
233
|
// int: unit group number (which group from the global table)
|
|
233
234
|
// int: position number (which column of this group)
|
|
234
235
|
// the column should of course have the item flag set (in the w3i) if this is a random item
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
outBufferToJSON.readInt();
|
|
237
|
+
outBufferToJSON.readInt();
|
|
237
238
|
} else if (randFlag === 2) {
|
|
238
239
|
// 2 = random unit from custom table, in this case we have
|
|
239
240
|
// int: number "n" of different available units
|
|
240
241
|
// then we have n times a random unit structure
|
|
241
|
-
const numDiffAvailUnits =
|
|
242
|
+
const numDiffAvailUnits = outBufferToJSON.readInt();
|
|
242
243
|
for (let k = 0; k < numDiffAvailUnits; k++) {
|
|
243
|
-
|
|
244
|
-
|
|
244
|
+
outBufferToJSON.readChars(4); // Unit ID
|
|
245
|
+
outBufferToJSON.readInt(); // % chance
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
248
|
|
|
248
|
-
unit.color =
|
|
249
|
-
|
|
250
|
-
unit.id =
|
|
249
|
+
unit.color = outBufferToJSON.readInt();
|
|
250
|
+
outBufferToJSON.readInt(); // UNSUPPORTED: waygate (-1 = deactivated, else its the creation number of the target rect as in war3map.w3r)
|
|
251
|
+
unit.id = outBufferToJSON.readInt();
|
|
251
252
|
|
|
252
253
|
result.push(unit);
|
|
253
254
|
}
|
package/lib/translators/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wc3maptranslator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Module to translate between `war3map` and `json` formats for WarCraft III .w3x maps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wc3",
|
|
@@ -17,12 +17,15 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "tsc --build",
|
|
19
19
|
"lint": "tslint --project .",
|
|
20
|
+
"postinstall": "npm run build",
|
|
20
21
|
"test": "npm run build && mocha",
|
|
21
22
|
"test-nyc": "npm run build && nyc mocha",
|
|
22
23
|
"test-travis": "npm run build && ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --include-all-sources true --root ./lib -- -R spec ./test/*.js"
|
|
23
24
|
},
|
|
24
25
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
26
|
+
"node": ">=14",
|
|
27
|
+
"npm": ">=7",
|
|
28
|
+
"tsc": ">3"
|
|
26
29
|
},
|
|
27
30
|
"repository": {
|
|
28
31
|
"type": "git",
|
|
@@ -30,7 +33,11 @@
|
|
|
30
33
|
},
|
|
31
34
|
"author": "ChiefOfGxBxL",
|
|
32
35
|
"contributors": [
|
|
33
|
-
"
|
|
36
|
+
"ChiefOfGxBxL",
|
|
37
|
+
"dulingzhi",
|
|
38
|
+
"rufreakde",
|
|
39
|
+
"ttay24",
|
|
40
|
+
"yatyricky"
|
|
34
41
|
],
|
|
35
42
|
"license": "MIT",
|
|
36
43
|
"bugs": {
|
|
@@ -39,24 +46,24 @@
|
|
|
39
46
|
"homepage": "https://github.com/ChiefOfGxBxL/WC3MapTranslator#readme",
|
|
40
47
|
"dependencies": {
|
|
41
48
|
"intn": "^1.0.0",
|
|
42
|
-
"round-to": "^
|
|
49
|
+
"round-to": "^5.0.0"
|
|
43
50
|
},
|
|
44
51
|
"devDependencies": {
|
|
45
52
|
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
46
|
-
"@types/fs-extra": "^
|
|
47
|
-
"@types/mocha": "^
|
|
48
|
-
"@types/node": "^
|
|
53
|
+
"@types/fs-extra": "^9.0.7",
|
|
54
|
+
"@types/mocha": "^8.2.1",
|
|
55
|
+
"@types/node": "^14.14.31",
|
|
49
56
|
"@types/round-to": "^4.0.0",
|
|
50
|
-
"coveralls": "^3.0
|
|
57
|
+
"coveralls": "^3.1.0",
|
|
51
58
|
"diff-buf": "^1.0.1",
|
|
52
|
-
"fs-extra": "^
|
|
53
|
-
"ieee754": "^1.1
|
|
59
|
+
"fs-extra": "^9.1.0",
|
|
60
|
+
"ieee754": "^1.2.1",
|
|
54
61
|
"istanbul": "^0.4.5",
|
|
55
|
-
"mocha": "^
|
|
56
|
-
"nyc": "^15.
|
|
57
|
-
"source-map-support": "^0.5.
|
|
58
|
-
"ts-node": "^
|
|
59
|
-
"tslint": "^6.
|
|
60
|
-
"typescript": "^
|
|
62
|
+
"mocha": "^8.3.0",
|
|
63
|
+
"nyc": "^15.1.0",
|
|
64
|
+
"source-map-support": "^0.5.19",
|
|
65
|
+
"ts-node": "^9.1.1",
|
|
66
|
+
"tslint": "^6.1.3",
|
|
67
|
+
"typescript": "^4.2.2"
|
|
61
68
|
}
|
|
62
69
|
}
|
package/test/HexBufferTest.ts
CHANGED
|
@@ -97,19 +97,13 @@ describe('HexBuffer', () => {
|
|
|
97
97
|
// tslint:disable-next-line: forin
|
|
98
98
|
for (const word of testWords) {
|
|
99
99
|
const bufLength = Buffer.from(word).length;
|
|
100
|
-
hexBuffer.addString(word
|
|
101
|
-
totalLength += bufLength;
|
|
100
|
+
hexBuffer.addString(word);
|
|
101
|
+
totalLength += bufLength + 1; // adding one accounts for the null terminator at the end of the string
|
|
102
102
|
const bufferLength = hexBuffer.getBuffer().length;
|
|
103
103
|
assert.equal(bufferLength, totalLength);
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
it('should addString null-terminated', () => {
|
|
108
|
-
hexBuffer.addString('hello world', true);
|
|
109
|
-
assert.equal(hexBuffer.getBuffer().length, 12); // now it has a null-terminator at the end
|
|
110
|
-
assert.equal(hexBuffer.getBuffer()[11], 0); // last character should be the null terminator
|
|
111
|
-
});
|
|
112
|
-
|
|
113
107
|
it('should addNewLine', () => {
|
|
114
108
|
hexBuffer.addNewLine();
|
|
115
109
|
assert.equal(hexBuffer.getBuffer().length, 2);
|
|
@@ -123,6 +117,15 @@ describe('HexBuffer', () => {
|
|
|
123
117
|
assert.equal(hexBuffer.getBuffer()[0], 65); // charcode for the ASCII letter "A"
|
|
124
118
|
});
|
|
125
119
|
|
|
120
|
+
it('should addChars', () => {
|
|
121
|
+
hexBuffer.addChars('ABCD');
|
|
122
|
+
assert.equal(hexBuffer.getBuffer().length, 4);
|
|
123
|
+
assert.equal(hexBuffer.getBuffer()[0], 65); // charcode for the ASCII letter "A"
|
|
124
|
+
assert.equal(hexBuffer.getBuffer()[1], 66); // charcode for the ASCII letter "B"
|
|
125
|
+
assert.equal(hexBuffer.getBuffer()[2], 67); // charcode for the ASCII letter "C"
|
|
126
|
+
assert.equal(hexBuffer.getBuffer()[3], 68); // charcode for the ASCII letter "D"
|
|
127
|
+
});
|
|
128
|
+
|
|
126
129
|
it('should addInt', () => {
|
|
127
130
|
hexBuffer.addInt(0);
|
|
128
131
|
assert.equal(hexBuffer.getBuffer().length, 4); // integer is 4 bytes in length
|
|
@@ -153,13 +156,6 @@ describe('HexBuffer', () => {
|
|
|
153
156
|
assert.equal(hexBuffer.getBuffer()[0], 15);
|
|
154
157
|
});
|
|
155
158
|
|
|
156
|
-
it('should addBytes', () => {
|
|
157
|
-
hexBuffer.addBytes([1, 2, 3]);
|
|
158
|
-
assert.equal(hexBuffer.getBuffer()[0], 1);
|
|
159
|
-
assert.equal(hexBuffer.getBuffer()[1], 2);
|
|
160
|
-
assert.equal(hexBuffer.getBuffer()[2], 3);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
159
|
it('should addNullTerminator', () => {
|
|
164
160
|
hexBuffer.addNullTerminator();
|
|
165
161
|
assert.equal(hexBuffer.getBuffer().length, 1);
|