madden-franchise 2.3.2 → 2.3.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.
@@ -165,56 +165,68 @@ class FranchiseFileTable extends EventEmitter {
165
165
  // If so, we need to consider the record as no longer empty
166
166
  // So we need to adjust the empty records
167
167
 
168
- // Ex: Empty record list looks like this: A -> B -> C
169
- // When B's value is changed, the records need updated to: A -> C
170
- const emptyRecordReference = that.emptyRecords.get(this.index);
171
- const changedRecordWasEmpty = emptyRecordReference !== null && emptyRecordReference !== undefined;
172
-
173
- if (changedRecordWasEmpty) {
174
-
175
- // Delete the empty record entry because it is no longer empty
176
- that.emptyRecords.delete(this.index);
177
-
178
- // Set the isEmpty back to false because it's no longer empty
179
- this.isEmpty = false;
180
-
181
- // Check if there is a previous empty record
182
- const previousEmptyReference = that.emptyRecords.get(emptyRecordReference.previous);
183
-
184
- if (previousEmptyReference) {
185
- // Set the previous empty record to point to the old reference's next node
186
- that.emptyRecords.set(emptyRecordReference.previous, {
187
- previous: that.emptyRecords.get(emptyRecordReference.previous).previous,
188
- next: emptyRecordReference.next
189
- });
190
-
191
- // change the table buffer and record buffer to reflect this change
192
- changeRecordBuffers(emptyRecordReference.previous, emptyRecordReference.next);
193
- }
194
-
195
- // If there is a next empty reference, update the previous value accordingly to now point
196
- // to the current record's previous index.
197
- const nextEmptyReference = that.emptyRecords.get(emptyRecordReference.next);
198
-
199
- if (nextEmptyReference) {
200
- that.emptyRecords.set(emptyRecordReference.next, {
201
- previous: emptyRecordReference.previous,
202
- next: that.emptyRecords.get(emptyRecordReference.next).next
203
- });
204
-
205
- if (!previousEmptyReference) {
206
- // If no previous empty record exists and a next record exists, we need to update the header to
207
- // point to this record as the next record to use.
208
- updateNextRecordToUseHeaderAndBuffer(emptyRecordReference.next);
168
+ // First, check if the record's length is greater than 4 bytes (32 bits)
169
+ // If less than 4 bytes, it can never become empty...probably. :)
170
+ if (that.header.record1Size >= 4) {
171
+
172
+ // Ex: Empty record list looks like this: A -> B -> C
173
+ // When B's value is changed, the records need updated to: A -> C
174
+ const emptyRecordReference = that.emptyRecords.get(this.index);
175
+ const changedRecordWasEmpty = emptyRecordReference !== null && emptyRecordReference !== undefined;
176
+
177
+ if (changedRecordWasEmpty) {
178
+ // Check if the record's first four bytes still have a reference to the 0th table.
179
+ // If so, then the record is still considered empty.
180
+
181
+ // We need to check the buffer because the first field is not always a reference.
182
+ const referenceData = utilService.getReferenceData(this._data.slice(0, 32));
183
+ if (referenceData.tableId !== 0) {
184
+
185
+ // Delete the empty record entry because it is no longer empty
186
+ that.emptyRecords.delete(this.index);
187
+
188
+ // Set the isEmpty back to false because it's no longer empty
189
+ this.isEmpty = false;
190
+
191
+ // Check if there is a previous empty record
192
+ const previousEmptyReference = that.emptyRecords.get(emptyRecordReference.previous);
193
+
194
+ if (previousEmptyReference) {
195
+ // Set the previous empty record to point to the old reference's next node
196
+ that.emptyRecords.set(emptyRecordReference.previous, {
197
+ previous: that.emptyRecords.get(emptyRecordReference.previous).previous,
198
+ next: emptyRecordReference.next
199
+ });
200
+
201
+ // change the table buffer and record buffer to reflect this change
202
+ changeRecordBuffers(emptyRecordReference.previous, emptyRecordReference.next);
203
+ }
204
+
205
+ // If there is a next empty reference, update the previous value accordingly to now point
206
+ // to the current record's previous index.
207
+ const nextEmptyReference = that.emptyRecords.get(emptyRecordReference.next);
208
+
209
+ if (nextEmptyReference) {
210
+ that.emptyRecords.set(emptyRecordReference.next, {
211
+ previous: emptyRecordReference.previous,
212
+ next: that.emptyRecords.get(emptyRecordReference.next).next
213
+ });
214
+
215
+ if (!previousEmptyReference) {
216
+ // If no previous empty record exists and a next record exists, we need to update the header to
217
+ // point to this record as the next record to use.
218
+ updateNextRecordToUseHeaderAndBuffer(emptyRecordReference.next);
219
+ }
220
+ }
221
+
222
+ // If there are no previous or next empty references
223
+ // Then there are no more empty references in the table
224
+ // Update the table header nextRecordToUse back to the table record capacity
225
+ if (!previousEmptyReference && !nextEmptyReference) {
226
+ updateNextRecordToUseHeaderAndBuffer(that.header.recordCapacity);
227
+ }
209
228
  }
210
229
  }
211
-
212
- // If there are no previous or next empty references
213
- // Then there are no more empty references in the table
214
- // Update the table header nextRecordToUse back to the table record capacity
215
- if (!previousEmptyReference && !nextEmptyReference) {
216
- updateNextRecordToUseHeaderAndBuffer(that.header.recordCapacity);
217
- }
218
230
  }
219
231
 
220
232
  that.emit('change');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "madden-franchise",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "description": "Tools to read a madden franchise file and get data from it",
5
5
  "main": "FranchiseFile.js",
6
6
  "scripts": {