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,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: number;
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
- private _outBufferToWar: HexBuffer;
43
- private _outBufferToJSON: W3Buffer;
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
- this._outBufferToWar.addString('W3do');
54
- this._outBufferToWar.addInt(8);
55
- this._outBufferToWar.addInt(11);
56
- this._outBufferToWar.addInt(unitsJson.length); // number of units
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
- this._outBufferToWar.addString(unit.type); // type
63
- this._outBufferToWar.addInt(unit.variation || 0); // variation
64
- this._outBufferToWar.addFloat(unit.position[0]); // position x
65
- this._outBufferToWar.addFloat(unit.position[1]); // position y
66
- this._outBufferToWar.addFloat(unit.position[2]); // position z
67
- this._outBufferToWar.addFloat(unit.rotation || 0); // rotation angle
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
- this._outBufferToWar.addFloat(unit.scale[0] || 1); // scale x
71
- this._outBufferToWar.addFloat(unit.scale[1] || 1); // scale y
72
- this._outBufferToWar.addFloat(unit.scale[2] || 1); // scale z
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
- this._outBufferToWar.addByte(0); // UNSUPPORTED: flags
71
+ outBufferToWar.addByte(0); // UNSUPPORTED: flags
76
72
 
77
- this._outBufferToWar.addInt(unit.player); // player #
78
- this._outBufferToWar.addByte(0); // (byte unknown - 0)
79
- this._outBufferToWar.addByte(0); // (byte unknown - 0)
80
- this._outBufferToWar.addInt(unit.hitpoints); // hitpoints
81
- this._outBufferToWar.addInt(unit.mana || 0); // mana
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
- this._outBufferToWar.addInt(-1);
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
- this._outBufferToWar.addInt(0); // dropped item sets
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
- this._outBufferToWar.addInt(unit.type === 'ngol' ? unit.gold : 0);
93
+ outBufferToWar.addInt(unit.gold);
94
+ // outBufferToWar.addInt(unit.type === 'ngol' ? unit.gold : 0);
96
95
 
97
- this._outBufferToWar.addFloat(unit.targetAcquisition || 0); // target acquisition
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
- this._outBufferToWar.addInt(unit.hero.level || 1); // hero lvl
103
- this._outBufferToWar.addInt(unit.hero.str || 1); // hero str
104
- this._outBufferToWar.addInt(unit.hero.agi || 1); // hero agi
105
- this._outBufferToWar.addInt(unit.hero.int || 1); // hero int
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
- this._outBufferToWar.addInt(unit.inventory.length); // # items in inventory
108
+ outBufferToWar.addInt(unit.inventory.length); // # items in inventory
110
109
  unit.inventory.forEach((item) => {
111
- this._outBufferToWar.addInt(item.slot - 1); // zero-index item slot
112
- this._outBufferToWar.addString(item.type);
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
- this._outBufferToWar.addInt(unit.abilities.length); // # modified abilities
116
+ outBufferToWar.addInt(unit.abilities.length); // # modified abilities
118
117
  unit.abilities.forEach((ability) => {
119
- this._outBufferToWar.addString(ability.ability); // ability string
120
- this._outBufferToWar.addInt(+ability.active); // 0 = not active, 1 = active
121
- this._outBufferToWar.addInt(ability.level);
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
- this._outBufferToWar.addInt(0);
125
- this._outBufferToWar.addInt(1);
123
+ outBufferToWar.addInt(0);
124
+ outBufferToWar.addInt(1);
126
125
 
127
- this._outBufferToWar.addInt(unit.color || unit.player); // custom color, defaults to owning player
128
- this._outBufferToWar.addInt(0); // outBuffer.addInt(unit.waygate); // UNSUPPORTED - waygate
129
- this._outBufferToWar.addInt(unit.id); // id
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: this._outBufferToWar.getBuffer()
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
- this._outBufferToJSON = new W3Buffer(buffer);
139
+ const outBufferToJSON = new W3Buffer(buffer);
141
140
 
142
- const fileId = this._outBufferToJSON.readChars(4), // W3do for doodad file
143
- fileVersion = this._outBufferToJSON.readInt(), // File version = 7
144
- subVersion = this._outBufferToJSON.readInt(), // 0B 00 00 00
145
- numUnits = this._outBufferToJSON.readInt(); // # of units
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 = this._outBufferToJSON.readChars(4); // (iDNR = random item, uDNR = random unit)
167
- unit.variation = this._outBufferToJSON.readInt();
168
- unit.position = [this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat()]; // X Y Z coords
169
- unit.rotation = this._outBufferToJSON.readFloat();
170
- unit.scale = [this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat(), this._outBufferToJSON.readFloat()]; // X Y Z scaling
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 = this._outBufferToJSON.readInt(); // (player1 = 0, 16=neutral passive); note: wc3 patch now has 24 max players
176
+ unit.player = outBufferToJSON.readInt(); // (player1 = 0, 16=neutral passive); note: wc3 patch now has 24 max players
176
177
 
177
- this._outBufferToJSON.readByte(); // unknown
178
- this._outBufferToJSON.readByte(); // unknown
178
+ outBufferToJSON.readByte(); // unknown
179
+ outBufferToJSON.readByte(); // unknown
179
180
 
180
- unit.hitpoints = this._outBufferToJSON.readInt(); // -1 = use default
181
- unit.mana = this._outBufferToJSON.readInt(); // -1 = use default, 0 = unit doesn't have 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 = this._outBufferToJSON.readInt(),
184
- numDroppedItemSets = this._outBufferToJSON.readInt();
184
+ const droppedItemSetPtr = outBufferToJSON.readInt(),
185
+ numDroppedItemSets = outBufferToJSON.readInt();
185
186
  for (let j = 0; j < numDroppedItemSets; j++) {
186
- const numDroppableItems = this._outBufferToJSON.readInt();
187
+ const numDroppableItems = outBufferToJSON.readInt();
187
188
  for (let k = 0; k < numDroppableItems; k++) {
188
- this._outBufferToJSON.readChars(4); // Item ID
189
- this._outBufferToJSON.readInt(); // % chance to drop
189
+ outBufferToJSON.readChars(4); // Item ID
190
+ outBufferToJSON.readInt(); // % chance to drop
190
191
  }
191
192
  }
192
193
 
193
- unit.gold = this._outBufferToJSON.readInt();
194
- unit.targetAcquisition = this._outBufferToJSON.readFloat(); // (-1 = normal, -2 = camp)
194
+ unit.gold = outBufferToJSON.readInt();
195
+ unit.targetAcquisition = outBufferToJSON.readFloat(); // (-1 = normal, -2 = camp)
195
196
 
196
197
  unit.hero = {
197
- level: this._outBufferToJSON.readInt(), // non-hero units = 1
198
- str: this._outBufferToJSON.readInt(),
199
- agi: this._outBufferToJSON.readInt(),
200
- int: this._outBufferToJSON.readInt()
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 = this._outBufferToJSON.readInt();
204
+ const numItemsInventory = outBufferToJSON.readInt();
204
205
  for (let j = 0; j < numItemsInventory; j++) {
205
206
  unit.inventory.push({
206
- slot: this._outBufferToJSON.readInt() + 1, // the int is 0-based, but json format wants 1-6
207
- type: this._outBufferToJSON.readChars(4) // Item ID
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 = this._outBufferToJSON.readInt();
212
+ const numModifiedAbil = outBufferToJSON.readInt();
212
213
  for (let j = 0; j < numModifiedAbil; j++) {
213
214
  unit.abilities.push({
214
- ability: this._outBufferToJSON.readChars(4), // Ability ID
215
- active: !!this._outBufferToJSON.readInt(), // autocast active? 0=no, 1=active
216
- level: this._outBufferToJSON.readInt()
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 = this._outBufferToJSON.readInt(); // random unit/item flag "r" (for uDNR units and iDNR items)
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
- this._outBufferToJSON.readByte();
227
- this._outBufferToJSON.readByte();
228
- this._outBufferToJSON.readByte();
229
- this._outBufferToJSON.readByte();
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
- this._outBufferToJSON.readInt();
236
- this._outBufferToJSON.readInt();
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 = this._outBufferToJSON.readInt();
242
+ const numDiffAvailUnits = outBufferToJSON.readInt();
242
243
  for (let k = 0; k < numDiffAvailUnits; k++) {
243
- this._outBufferToJSON.readChars(4); // Unit ID
244
- this._outBufferToJSON.readInt(); // % chance
244
+ outBufferToJSON.readChars(4); // Unit ID
245
+ outBufferToJSON.readInt(); // % chance
245
246
  }
246
247
  }
247
248
 
248
- unit.color = this._outBufferToJSON.readInt();
249
- this._outBufferToJSON.readInt(); // UNSUPPORTED: waygate (-1 = deactivated, else its the creation number of the target rect as in war3map.w3r)
250
- unit.id = this._outBufferToJSON.readInt();
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
  }
@@ -1,4 +1,3 @@
1
-
2
1
  export * from './CamerasTranslator';
3
2
  export * from './DoodadsTranslator';
4
3
  export * from './ImportsTranslator';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wc3maptranslator",
3
- "version": "3.0.3",
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": ">=8.0.0"
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
- "rufreakde"
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": "^4.1.0"
49
+ "round-to": "^5.0.0"
43
50
  },
44
51
  "devDependencies": {
45
52
  "@istanbuljs/nyc-config-typescript": "^1.0.1",
46
- "@types/fs-extra": "^8.1.0",
47
- "@types/mocha": "^7.0.1",
48
- "@types/node": "^12.12.28",
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.9",
57
+ "coveralls": "^3.1.0",
51
58
  "diff-buf": "^1.0.1",
52
- "fs-extra": "^8.1.0",
53
- "ieee754": "^1.1.13",
59
+ "fs-extra": "^9.1.0",
60
+ "ieee754": "^1.2.1",
54
61
  "istanbul": "^0.4.5",
55
- "mocha": "^7.0.1",
56
- "nyc": "^15.0.0",
57
- "source-map-support": "^0.5.16",
58
- "ts-node": "^8.6.2",
59
- "tslint": "^6.0.0",
60
- "typescript": "^3.8.2"
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
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "recursive": true,
3
+ "require": ["ts-node/register", "source-map-support/register"]
4
+ }
@@ -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, false);
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);