Skip to content

Commit f3abdb5

Browse files
MacSplodySharlikran
authored andcommitted
Fix Regions Comparison
1 parent 4774134 commit f3abdb5

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

Mopy/bash/patcher/patchers/importers.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,8 @@ def scanModFile(self, modFile, progress): # scanModFile0
409409
def buildPatch(self,log,progress): # buildPatch0
410410
"""Adds merged lists to patchfile."""
411411

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-
423-
def handlePatchCellBlock(patchCellBlock):
412+
def has_been_modified(patch_cell_block):
413+
# @formatter:off
424414
"""
425415
This function checks if an attribute or flag in CellData has
426416
a value which is different to the corresponding value in the
@@ -431,40 +421,48 @@ def handlePatchCellBlock(patchCellBlock):
431421
to the bash patch, and the cell is flagged as modified.
432422
Modified cell Blocks are kept, the other are discarded.
433423
"""
434-
modified=False
435-
for attr, value in cellData[patchCellBlock.cell.fid].viewitems():
436-
if attr == 'regions':
437-
if regions_differ(patchCellBlock.cell.__getattribute__(attr), value):
438-
patchCellBlock.cell.__setattr__(attr, value)
424+
# @formatter:on
425+
src_values = cellData[patch_cell_block.cell.fid].viewitems()
426+
src_flags = cellData[
427+
patch_cell_block.cell.fid + ('flags',)].viewitems()
428+
modified = False
429+
430+
for attribute, src_value in src_values:
431+
patch_value = patch_cell_block.cell.__getattribute__(attribute)
432+
if attribute == 'regions':
433+
if set(src_value).difference(set(patch_value)):
434+
patch_cell_block.cell.__setattr__(attribute, src_value)
435+
modified = True
436+
else:
437+
if patch_value != src_value:
438+
patch_cell_block.cell.__setattr__(attribute, src_value)
439439
modified = True
440-
elif patchCellBlock.cell.__getattribute__(attr) != value:
441-
patchCellBlock.cell.__setattr__(attr, value)
440+
for flag, src_value in src_flags:
441+
patch_value = patch_cell_block.cell.flags.__getattr__(flag)
442+
if patch_value != src_value:
443+
patch_cell_block.cell.flags.__setattr__(flag, src_value)
442444
modified = True
443-
for flag, value in cellData[patchCellBlock.cell.fid + ('flags',)].viewitems():
444-
if patchCellBlock.cell.flags.__getattr__(flag) != value:
445-
patchCellBlock.cell.flags.__setattr__(flag, value)
446-
modified=True
447445
if modified:
448-
patchCellBlock.cell.setChanged()
449-
keep(patchCellBlock.cell.fid)
446+
patch_cell_block.cell.setChanged()
447+
keep(patch_cell_block.cell.fid)
450448
return modified
451449

452450
if not self.isActive: return
453451
keep = self.patchFile.getKeeper()
454452
cellData, count = self.cellData, collections.defaultdict(int)
455453
for cellBlock in self.patchFile.CELL.cellBlocks:
456-
if cellBlock.cell.fid in cellData and handlePatchCellBlock(cellBlock):
454+
if cellBlock.cell.fid in cellData and has_been_modified(cellBlock):
457455
count[cellBlock.cell.fid[0]] += 1
458456
for worldBlock in self.patchFile.WRLD.worldBlocks:
459457
keepWorld = False
460458
for cellBlock in worldBlock.cellBlocks:
461459
if cellBlock.cell.fid in cellData:
462-
if handlePatchCellBlock(cellBlock):
460+
if has_been_modified(cellBlock):
463461
count[cellBlock.cell.fid[0]] += 1
464462
keepWorld = True
465463
if worldBlock.worldCellBlock:
466464
if worldBlock.worldCellBlock.cell.fid in cellData:
467-
if handlePatchCellBlock(worldBlock.worldCellBlock):
465+
if has_been_modified(worldBlock.worldCellBlock):
468466
count[worldBlock.worldCellBlock.cell.fid[0]] += 1
469467
keepWorld = True
470468
# if worldBlock.world.fid in cellData['Maps']:
@@ -479,7 +477,8 @@ def handlePatchCellBlock(patchCellBlock):
479477
self.cellData.clear()
480478
self._patchLog(log, count)
481479

482-
def _plog(self,log,count): # type 1 but for logMsg % sum(count.values())...
480+
# type 1 but for logMsg % sum(count.values())...
481+
def _plog(self,log,count):
483482
log(self.__class__.logMsg)
484483
for srcMod in load_order.get_ordered(count.keys()):
485484
log(u'* %s: %d' % (srcMod.s,count[srcMod]))

0 commit comments

Comments
 (0)