@@ -287,16 +287,17 @@ def importCellBlockData(cellBlock):
287287 Add attribute values from source mods to a temporary cache.
288288 These are used to filter for required records by formID and
289289 to update the attribute values taken from the master files
290- when creating cell_data .
290+ when creating cellData .
291291 """
292292 if not cellBlock .cell .flags1 .ignored :
293293 fid = cellBlock .cell .fid
294294 for attr in attrs :
295- tempCellData [fid ][attr ] = cellBlock . cell . __getattribute__ (
296- attr )
295+ tempCellData [fid ][attr ] = (
296+ cellBlock . cell . __getattribute__ ( attr ) )
297297 for flag in flags :
298- tempCellData [fid + ('flags' ,)][
299- flag ] = cellBlock .cell .flags .__getattr__ (flag )
298+ tempCellData [fid + ('flags' ,)][flag ] = (
299+ cellBlock .cell .flags .__getattr__ (flag ))
300+
300301 def checkMasterCellBlockData (cellBlock ):
301302 """
302303 Add attribute values from record(s) in master file(s).
@@ -315,10 +316,11 @@ def checkMasterCellBlockData(cellBlock):
315316 for flag in flags :
316317 master_flag = cellBlock .cell .flags .__getattr__ (flag )
317318 if tempCellData [fid + ('flags' ,)][flag ] != master_flag :
318- cellData [fid + ('flags' ,)][flag ] = \
319- tempCellData [fid + ('flags' ,)][flag ]
320- loadFactory = LoadFactory (False ,MreRecord .type_class ['CELL' ],
321- MreRecord .type_class ['WRLD' ])
319+ cellData [fid + ('flags' ,)][flag ] = (
320+ tempCellData [fid + ('flags' ,)][flag ])
321+
322+ loadFactory = LoadFactory (False , MreRecord .type_class ['CELL' ],
323+ MreRecord .type_class ['WRLD' ])
322324 progress .setFull (len (self .srcs ))
323325 cachedMasters = {}
324326 for srcMod in self .srcs :
@@ -406,6 +408,18 @@ def scanModFile(self, modFile, progress): # scanModFile0
406408
407409 def buildPatch (self ,log ,progress ): # buildPatch0
408410 """Adds merged lists to patchfile."""
411+
412+ def regions_differ (patch_value , value_ ):
413+ """
414+ Required for regions because comparing using `==` or `!=`
415+ results in false positives.
416+ """
417+ sorted_patch_value = sorted (patch_value )
418+ sorted_value = sorted (value_ )
419+ regions_compare = set (sorted_value ).difference (
420+ sorted_patch_value )
421+ return (bool (regions_compare ))
422+
409423 def handlePatchCellBlock (patchCellBlock ):
410424 """
411425 This function checks if an attribute or flag in CellData has
@@ -418,24 +432,23 @@ def handlePatchCellBlock(patchCellBlock):
418432 Modified cell Blocks are kept, the other are discarded.
419433 """
420434 modified = False
421- for attr ,value in cellData [patchCellBlock .cell .fid ].iteritems ():
435+ for attr , value in cellData [patchCellBlock .cell .fid ].viewitems ():
422436 if attr == 'regions' :
423- if set ( value ). difference ( set ( patchCellBlock .cell .__getattribute__ (attr )) ):
437+ if regions_differ ( patchCellBlock .cell .__getattribute__ (attr ), value ):
424438 patchCellBlock .cell .__setattr__ (attr , value )
425439 modified = True
426- else :
427- if patchCellBlock .cell .__getattribute__ (attr ) != value :
428- patchCellBlock .cell .__setattr__ (attr , value )
429- modified = True
430- for flag , value in cellData [
431- patchCellBlock .cell .fid + ('flags' ,)].iteritems ():
440+ elif patchCellBlock .cell .__getattribute__ (attr ) != value :
441+ patchCellBlock .cell .__setattr__ (attr , value )
442+ modified = True
443+ for flag , value in cellData [patchCellBlock .cell .fid + ('flags' ,)].viewitems ():
432444 if patchCellBlock .cell .flags .__getattr__ (flag ) != value :
433445 patchCellBlock .cell .flags .__setattr__ (flag , value )
434446 modified = True
435447 if modified :
436448 patchCellBlock .cell .setChanged ()
437449 keep (patchCellBlock .cell .fid )
438450 return modified
451+
439452 if not self .isActive : return
440453 keep = self .patchFile .getKeeper ()
441454 cellData , count = self .cellData , collections .defaultdict (int )
@@ -445,10 +458,10 @@ def handlePatchCellBlock(patchCellBlock):
445458 for worldBlock in self .patchFile .WRLD .worldBlocks :
446459 keepWorld = False
447460 for cellBlock in worldBlock .cellBlocks :
448- if cellBlock .cell .fid in cellData and handlePatchCellBlock (
449- cellBlock ):
450- count [cellBlock .cell .fid [0 ]] += 1
451- keepWorld = True
461+ if cellBlock .cell .fid in cellData :
462+ if handlePatchCellBlock ( cellBlock ):
463+ count [cellBlock .cell .fid [0 ]] += 1
464+ keepWorld = True
452465 if worldBlock .worldCellBlock :
453466 if worldBlock .worldCellBlock .cell .fid in cellData :
454467 if handlePatchCellBlock (worldBlock .worldCellBlock ):
0 commit comments