madden-franchise 3.2.1 → 3.2.2

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.
@@ -502,6 +502,7 @@ class FranchiseFileTable extends EventEmitter {
502
502
  // if the record contains any string values, point the string values to
503
503
  // their correct offsets
504
504
  this.strategy.recalculateStringOffsets(this, object);
505
+ this.strategy.recalculateBlobOffsets(this, object);
505
506
 
506
507
  // Delete the empty record entry because it is no longer empty
507
508
  this.emptyRecords.delete(object.index);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "madden-franchise",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "description": "Tools to read a madden franchise file and get data from it",
5
5
  "main": "FranchiseFile.js",
6
6
  "scripts": {
@@ -59,4 +59,28 @@ FranchiseTableStrategy.recalculateStringOffsets = (table, record) => {
59
59
  });
60
60
  };
61
61
 
62
+ FranchiseTableStrategy.recalculateBlobOffsets = (table, record) => {
63
+ // First, calculate length allocated per record in table2
64
+ const byteLengthPerRecord = table.offsetTable.filter((offsetEntry) => {
65
+ return offsetEntry.type === 'binaryblob';
66
+ }).reduce((accum, cur) => {
67
+ return accum + cur.maxLength;
68
+ }, 0);
69
+
70
+ // Then, go through each string field sorted by offset index, and assign offsets to the table2 fields
71
+ let runningOffset = 0;
72
+
73
+ record.fieldsArray.filter((field) => {
74
+ return field.offset.type === 'binaryblob';
75
+ }).sort((a, b) => {
76
+ return a.offset.index - b.offset.index;
77
+ }).forEach((field) => {
78
+ if (field.thirdTableField) {
79
+ field.thirdTableField.offset = (record.index * byteLengthPerRecord) + runningOffset;
80
+ }
81
+
82
+ runningOffset += field.offset.maxLength;
83
+ });
84
+ };
85
+
62
86
  module.exports = FranchiseTableStrategy;
@@ -10,5 +10,6 @@ M19TableStrategy.getTable2BinaryData = FranchiseTableStrategy.getTable2BinaryDat
10
10
  M19TableStrategy.getTable3BinaryData = FranchiseTableStrategy.getTable2BinaryData;
11
11
  M19TableStrategy.getMandatoryOffsets = FranchiseTableStrategy.getMandatoryOffsets;
12
12
  M19TableStrategy.recalculateStringOffsets = FranchiseTableStrategy.recalculateStringOffsets;
13
+ M19TableStrategy.recalculateBlobOffsets = FranchiseTableStrategy.recalculateBlobOffsets;
13
14
 
14
15
  module.exports = M19TableStrategy;
@@ -10,5 +10,6 @@ M20TableStrategy.getTable2BinaryData = FranchiseTableStrategy.getTable2BinaryDat
10
10
  M20TableStrategy.getTable3BinaryData = FranchiseTableStrategy.getTable2BinaryData;
11
11
  M20TableStrategy.getMandatoryOffsets = FranchiseTableStrategy.getMandatoryOffsets;
12
12
  M20TableStrategy.recalculateStringOffsets = FranchiseTableStrategy.recalculateStringOffsets;
13
+ M20TableStrategy.recalculateBlobOffsets = FranchiseTableStrategy.recalculateBlobOffsets;
13
14
 
14
15
  module.exports = M20TableStrategy;
@@ -11,5 +11,6 @@ M24TableStrategy.getTable2BinaryData = FranchiseTableStrategy.getTable2BinaryDat
11
11
  M24TableStrategy.getTable3BinaryData = FranchiseTableStrategy.getTable2BinaryData;
12
12
  M24TableStrategy.getMandatoryOffsets = FranchiseTableStrategy.getMandatoryOffsets;
13
13
  M24TableStrategy.recalculateStringOffsets = FranchiseTableStrategy.recalculateStringOffsets;
14
+ M24TableStrategy.recalculateBlobOffsets = FranchiseTableStrategy.recalculateBlobOffsets;
14
15
 
15
16
  module.exports = M24TableStrategy;