madden-franchise 3.0.2 → 3.0.3
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/FranchiseFileTable.js +23 -6
- package/package.json +1 -1
- package/strategies/common/table/FranchiseTableStrategy.js +24 -0
- package/strategies/franchise/m19/M19TableStrategy.js +1 -0
- package/strategies/franchise/m20/M20TableStrategy.js +1 -0
- package/strategies/franchise-common/m19/M19FTCTableStrategy.js +1 -0
- package/strategies/franchise-common/m20/M20FTCTableStrategy.js +1 -0
package/FranchiseFileTable.js
CHANGED
|
@@ -428,12 +428,20 @@ class FranchiseFileTable extends EventEmitter {
|
|
|
428
428
|
const changedRecordWasEmpty = emptyRecordReference !== null && emptyRecordReference !== undefined;
|
|
429
429
|
|
|
430
430
|
if (changedRecordWasEmpty) {
|
|
431
|
-
//
|
|
432
|
-
//
|
|
431
|
+
// 1/5/23: Assume all changes to a field make the record not empty. Leaving comments
|
|
432
|
+
// below if this needs to be reverted in the future.
|
|
433
433
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
|
|
435
|
+
// Check if the record's first four bytes still have a reference to the 0th table.
|
|
436
|
+
// If so, then the record is still considered empty.
|
|
437
|
+
|
|
438
|
+
// We need to check the buffer because the first field is not always a reference.
|
|
439
|
+
// const referenceData = utilService.getReferenceDataFromBuffer(object.data.slice(0, 4));
|
|
440
|
+
// if (referenceData.tableId !== 0 || referenceData.rowNumber > this.header.recordCapacity) {
|
|
441
|
+
|
|
442
|
+
// if the record contains any string values, point the string values to
|
|
443
|
+
// their correct offsets
|
|
444
|
+
this.strategy.recalculateStringOffsets(this, object);
|
|
437
445
|
|
|
438
446
|
// Delete the empty record entry because it is no longer empty
|
|
439
447
|
this.emptyRecords.delete(object.index);
|
|
@@ -491,7 +499,16 @@ class FranchiseFileTable extends EventEmitter {
|
|
|
491
499
|
}
|
|
492
500
|
else if (object instanceof FranchiseFileTable2Field) {
|
|
493
501
|
object.isChanged = true;
|
|
494
|
-
|
|
502
|
+
|
|
503
|
+
// When a table2 field changes, we need to check if the record is empty. If so, we need to mark it as not empty.
|
|
504
|
+
if (object.fieldReference) {
|
|
505
|
+
this.onEvent('change', object.fieldReference._parent);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
// Only emit change here if the field reference is empty.
|
|
509
|
+
// the onEvent call will emit a change in the above condition.
|
|
510
|
+
this.emit('change');
|
|
511
|
+
}
|
|
495
512
|
}
|
|
496
513
|
};
|
|
497
514
|
};
|
package/package.json
CHANGED
|
@@ -33,4 +33,28 @@ FranchiseTableStrategy.getMandatoryOffsets = (offsets) => {
|
|
|
33
33
|
return [];
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
FranchiseTableStrategy.recalculateStringOffsets = (table, record) => {
|
|
37
|
+
// First, calculate length allocated per record in table2
|
|
38
|
+
const byteLengthPerRecord = table.offsetTable.filter((offsetEntry) => {
|
|
39
|
+
return offsetEntry.type === 'string';
|
|
40
|
+
}).reduce((accum, cur) => {
|
|
41
|
+
return accum + cur.maxLength;
|
|
42
|
+
}, 0);
|
|
43
|
+
|
|
44
|
+
// Then, go through each string field sorted by offset index, and assign offsets to the table2 fields
|
|
45
|
+
let runningOffset = 0;
|
|
46
|
+
|
|
47
|
+
record.fieldsArray.filter((field) => {
|
|
48
|
+
return field.offset.type === 'string';
|
|
49
|
+
}).sort((a, b) => {
|
|
50
|
+
return a.offset.index - b.offset.index;
|
|
51
|
+
}).forEach((field) => {
|
|
52
|
+
if (field.secondTableField) {
|
|
53
|
+
field.secondTableField.offset = (record.index * byteLengthPerRecord) + runningOffset;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
runningOffset += field.offset.maxLength;
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
36
60
|
module.exports = FranchiseTableStrategy;
|
|
@@ -8,5 +8,6 @@ M19TableStrategy.parseHeaderAttributesFromSchema = M19TableHeaderStrategy.parseH
|
|
|
8
8
|
|
|
9
9
|
M19TableStrategy.getTable2BinaryData = FranchiseTableStrategy.getTable2BinaryData;
|
|
10
10
|
M19TableStrategy.getMandatoryOffsets = FranchiseTableStrategy.getMandatoryOffsets;
|
|
11
|
+
M19TableStrategy.recalculateStringOffsets = FranchiseTableStrategy.recalculateStringOffsets;
|
|
11
12
|
|
|
12
13
|
module.exports = M19TableStrategy;
|
|
@@ -8,5 +8,6 @@ M20TableStrategy.parseHeaderAttributesFromSchema = M20TableHeaderStrategy.parseH
|
|
|
8
8
|
|
|
9
9
|
M20TableStrategy.getTable2BinaryData = FranchiseTableStrategy.getTable2BinaryData;
|
|
10
10
|
M20TableStrategy.getMandatoryOffsets = FranchiseTableStrategy.getMandatoryOffsets;
|
|
11
|
+
M20TableStrategy.recalculateStringOffsets = FranchiseTableStrategy.recalculateStringOffsets;
|
|
11
12
|
|
|
12
13
|
module.exports = M20TableStrategy;
|
|
@@ -8,5 +8,6 @@ M19FTCTableStrategy.parseHeaderAttributesFromSchema = M19TableHeaderStrategy.par
|
|
|
8
8
|
|
|
9
9
|
M19FTCTableStrategy.getTable2BinaryData = FTCTableStrategy.getTable2BinaryData;
|
|
10
10
|
M19FTCTableStrategy.getMandatoryOffsets = FTCTableStrategy.getMandatoryOffsets;
|
|
11
|
+
M19FTCTableStrategy.recalculateStringOffsets = () => {};
|
|
11
12
|
|
|
12
13
|
module.exports = M19FTCTableStrategy;
|
|
@@ -8,5 +8,6 @@ M20FTCTableStrategy.parseHeaderAttributesFromSchema = M20TableHeaderStrategy.par
|
|
|
8
8
|
|
|
9
9
|
M20FTCTableStrategy.getTable2BinaryData = FTCTableStrategy.getTable2BinaryData;
|
|
10
10
|
M20FTCTableStrategy.getMandatoryOffsets = FTCTableStrategy.getMandatoryOffsets;
|
|
11
|
+
M20FTCTableStrategy.recalculateStringOffsets = () => {};
|
|
11
12
|
|
|
12
13
|
module.exports = M20FTCTableStrategy;
|