Skip to content

Commit 7268c14

Browse files
MacSplodySharlikran
authored andcommitted
Separate Persistent Cell Data from Interior and Exterior Cell Data
To prevent duplication of persistent cells in patch file.
1 parent 13dd372 commit 7268c14

1 file changed

Lines changed: 80 additions & 33 deletions

File tree

Mopy/bash/patcher/patchers/importers.py

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class CellImporter(_ACellImporter, ImportPatcher):
265265
def initPatchFile(self, patchFile):
266266
super(CellImporter, self).initPatchFile(patchFile)
267267
self.cellData = defaultdict(dict)
268+
self.persistentData = defaultdict(dict)
268269
# TODO: docs: recAttrs vs tag_attrs - extra in PBash:
269270
# 'unused1','unused2','unused3'
270271
self.recAttrs = bush.game.cellRecAttrs # dict[unicode, tuple[str]]
@@ -282,6 +283,7 @@ def initData(self,progress):
282283
"""Get cells from source files."""
283284
if not self.isActive: return
284285
cellData = self.cellData
286+
persistentData = self.persistentData
285287
# cellData['Maps'] = {}
286288
def importCellBlockData(cellBlock):
287289
"""
@@ -292,12 +294,20 @@ def importCellBlockData(cellBlock):
292294
"""
293295
if not cellBlock.cell.flags1.ignored:
294296
fid = cellBlock.cell.fid
295-
for attr in attrs:
296-
tempCellData[fid][attr] = (cellBlock.cell.__getattribute__(
297-
attr))
298-
for flg_ in flgs_:
299-
tempCellData[fid + ('flags',)][
300-
flg_] = (cellBlock.cell.flags.__getattr__(flg_))
297+
if cellBlock.cell.flags1.persistent:
298+
for attr in attrs:
299+
tempPersistentData[fid][attr] = (
300+
cellBlock.cell.__getattribute__(attr))
301+
for flg_ in flgs_:
302+
tempPersistentData[fid + ('flags',)][flg_] = (
303+
cellBlock.cell.flags.__getattr__(flg_))
304+
else:
305+
for attr in attrs:
306+
tempCellData[fid][attr] = (
307+
cellBlock.cell.__getattribute__(attr))
308+
for flg_ in flgs_:
309+
tempCellData[fid + ('flags',)][flg_] = (
310+
cellBlock.cell.flags.__getattr__(flg_))
301311

302312
def checkMasterCellBlockData(cellBlock):
303313
"""
@@ -309,16 +319,28 @@ def checkMasterCellBlockData(cellBlock):
309319
"""
310320
if not cellBlock.cell.flags1.ignored:
311321
fid = cellBlock.cell.fid
312-
if fid not in tempCellData: return
313-
for attr in attrs:
314-
master_attr = cellBlock.cell.__getattribute__(attr)
315-
if tempCellData[fid][attr] != master_attr:
316-
cellData[fid][attr] = tempCellData[fid][attr]
317-
for flg_ in flgs_:
318-
master_flag = cellBlock.cell.flags.__getattr__(flg_)
319-
if tempCellData[fid + ('flags',)][flg_] != master_flag:
320-
cellData[fid + ('flags',)][flg_] = \
321-
(tempCellData[fid + ('flags',)][flg_])
322+
if fid in tempPersistentData:
323+
for attr in attrs:
324+
master_attr = cellBlock.cell.__getattribute__(attr)
325+
if tempPersistentData[fid][attr] != master_attr:
326+
persistentData[fid][attr] = (
327+
tempPersistentData[fid][attr])
328+
for flg_ in flgs_:
329+
master_flag = cellBlock.cell.flags.__getattr__(flg_)
330+
if tempPersistentData[fid + ('flags',)][
331+
flg_] != master_flag:
332+
persistentData[fid + ('flags',)][flg_] = (
333+
tempPersistentData[fid + ('flags',)][flg_])
334+
if fid in tempCellData:
335+
for attr in attrs:
336+
master_attr = cellBlock.cell.__getattribute__(attr)
337+
if tempCellData[fid][attr] != master_attr:
338+
cellData[fid][attr] = tempCellData[fid][attr]
339+
for flg_ in flgs_:
340+
master_flag = cellBlock.cell.flags.__getattr__(flg_)
341+
if tempCellData[fid + ('flags',)][flg_] != master_flag:
342+
cellData[fid + ('flags',)][flg_] = (
343+
tempCellData[fid + ('flags',)][flg_])
322344

323345
loadFactory = LoadFactory(False,MreRecord.type_class['CELL'],
324346
MreRecord.type_class['WRLD'])
@@ -332,6 +354,7 @@ def checkMasterCellBlockData(cellBlock):
332354
# values from the value in any of srcMod's masters.
333355
tempCellData = defaultdict(dict)
334356
tempCellData['Maps'] = {} # unused !
357+
tempPersistentData = defaultdict(dict)
335358
srcInfo = bosh.modInfos[srcMod]
336359
srcFile = ModFile(srcInfo,loadFactory)
337360
srcFile.load(True)
@@ -382,6 +405,7 @@ def checkMasterCellBlockData(cellBlock):
382405
# if worldBlock.world.mapPath != tempCellData['Maps'][worldBlock.world.fid]:
383406
# cellData['Maps'][worldBlock.world.fid] = tempCellData['Maps'][worldBlock.world.fid]
384407
tempCellData = {}
408+
tempPersistentData = {}
385409
progress.plus()
386410

387411
def scanModFile(self, modFile, progress): # scanModFile0
@@ -390,6 +414,7 @@ def scanModFile(self, modFile, progress): # scanModFile0
390414
'CELL' not in modFile.tops and 'WRLD' not in modFile.tops):
391415
return
392416
cellData = self.cellData
417+
persistentData = self.persistentData
393418
patchCells = self.patchFile.CELL
394419
patchWorlds = self.patchFile.WRLD
395420
modFile.convertToLongFids(('CELL','WRLD'))
@@ -405,6 +430,10 @@ def scanModFile(self, modFile, progress): # scanModFile0
405430
worldBlock.worldCellBlock)
406431
patchWorlds.id_worldBlocks[
407432
worldBlock.world.fid].setCell(cellBlock.cell)
433+
if worldBlock.worldCellBlock is not None:
434+
if worldBlock.worldCellBlock.cell.fid in persistentData:
435+
patchWorlds.setWorld(worldBlock.world,
436+
worldBlock.worldCellBlock)
408437
# if worldBlock.world.fid in cellData['Maps']:
409438
# patchWorlds.setWorld(worldBlock.world)
410439

@@ -421,29 +450,47 @@ def handlePatchCellBlock(patchCellBlock):
421450
to the bash patch, and the cell is flagged as modified.
422451
Modified cell Blocks are kept, the other are discarded.
423452
"""
424-
modified=False
425-
for attr, value in cellData[patchCellBlock.cell.fid].viewitems():
426-
if attr == 'regions':
427-
if set(value).difference(set(patchCellBlock.cell.__getattribute__(attr))):
428-
patchCellBlock.cell.__setattr__(attr, value)
453+
modified = False
454+
fid = patchCellBlock.cell.fid
455+
if fid in persistentData:
456+
for attr, value in persistentData[fid].iteritems():
457+
if attr == 'regions':
458+
if set(value).difference(set(
459+
patchCellBlock.cell.__getattribute__(attr))):
460+
patchCellBlock.cell.__setattr__(attr, value)
461+
modified = True
462+
else:
463+
if patchCellBlock.cell.__getattribute__(attr) != value:
464+
patchCellBlock.cell.__setattr__(attr, value)
465+
modified = True
466+
for flag, value in persistentData[fid + ('flags',)].iteritems():
467+
if patchCellBlock.cell.flags.__getattr__(flag) != value:
468+
patchCellBlock.cell.flags.__setattr__(flag, value)
469+
modified = True
470+
elif fid in cellData:
471+
for attr, value in cellData[fid].iteritems():
472+
if attr == 'regions':
473+
if set(value).difference(set(
474+
patchCellBlock.cell.__getattribute__(attr))):
475+
patchCellBlock.cell.__setattr__(attr, value)
476+
modified = True
477+
else:
478+
if patchCellBlock.cell.__getattribute__(attr) != value:
479+
patchCellBlock.cell.__setattr__(attr, value)
480+
modified = True
481+
for flag, value in cellData[fid + ('flags',)].iteritems():
482+
if patchCellBlock.cell.flags.__getattr__(flag) != value:
483+
patchCellBlock.cell.flags.__setattr__(flag, value)
429484
modified = True
430-
else:
431-
if patchCellBlock.cell.__getattribute__(attr) != value:
432-
patchCellBlock.cell.__setattr__(attr, value)
433-
modified=True
434-
for flag, value in cellData[
435-
patchCellBlock.cell.fid + ('flags',)].viewitems():
436-
if patchCellBlock.cell.flags.__getattr__(flag) != value:
437-
patchCellBlock.cell.flags.__setattr__(flag, value)
438-
modified=True
439485
if modified:
440486
patchCellBlock.cell.setChanged()
441-
keep(patchCellBlock.cell.fid)
487+
keep(fid)
442488
return modified
443489

444490
if not self.isActive: return
445491
keep = self.patchFile.getKeeper()
446-
cellData, count = self.cellData, Counter()
492+
cellData, persistentData, count = (
493+
self.cellData, self.persistentData, Counter())
447494
for cellBlock in self.patchFile.CELL.cellBlocks:
448495
if cellBlock.cell.fid in cellData and handlePatchCellBlock(cellBlock):
449496
count[cellBlock.cell.fid[0]] += 1
@@ -455,7 +502,7 @@ def handlePatchCellBlock(patchCellBlock):
455502
count[cellBlock.cell.fid[0]] += 1
456503
keepWorld = True
457504
if worldBlock.worldCellBlock:
458-
if worldBlock.worldCellBlock.cell.fid in cellData:
505+
if worldBlock.worldCellBlock.cell.fid in persistentData:
459506
if handlePatchCellBlock(worldBlock.worldCellBlock):
460507
count[worldBlock.worldCellBlock.cell.fid[0]] += 1
461508
keepWorld = True

0 commit comments

Comments
 (0)