Skip to content

Commit 7a08257

Browse files
committed
Separate Persistent Cell Data from Interior and Exterior Cell Data
To prevent duplication of persistent cells in patch file.
1 parent 2e4f6bb commit 7a08257

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
@@ -261,6 +261,7 @@ class CellImporter(_ACellImporter, ImportPatcher):
261261
def initPatchFile(self, patchFile):
262262
super(CellImporter, self).initPatchFile(patchFile)
263263
self.cellData = defaultdict(dict)
264+
self.persistentData = defaultdict(dict)
264265
# TODO: docs: recAttrs vs tag_attrs - extra in PBash:
265266
# 'unused1','unused2','unused3'
266267
self.recAttrs = bush.game.cellRecAttrs # dict[unicode, tuple[str]]
@@ -278,6 +279,7 @@ def initData(self,progress):
278279
"""Get cells from source files."""
279280
if not self.isActive: return
280281
cellData = self.cellData
282+
persistentData = self.persistentData
281283
# cellData['Maps'] = {}
282284
def importCellBlockData(cellBlock):
283285
"""
@@ -288,12 +290,20 @@ def importCellBlockData(cellBlock):
288290
"""
289291
if not cellBlock.cell.flags1.ignored:
290292
fid = cellBlock.cell.fid
291-
for attr in attrs:
292-
tempCellData[fid][attr] = (cellBlock.cell.__getattribute__(
293-
attr))
294-
for flg_ in flgs_:
295-
tempCellData[fid + ('flags',)][
296-
flg_] = (cellBlock.cell.flags.__getattr__(flg_))
293+
if cellBlock.cell.flags1.persistent:
294+
for attr in attrs:
295+
tempPersistentData[fid][attr] = (
296+
cellBlock.cell.__getattribute__(attr))
297+
for flg_ in flgs_:
298+
tempPersistentData[fid + ('flags',)][flg_] = (
299+
cellBlock.cell.flags.__getattr__(flg_))
300+
else:
301+
for attr in attrs:
302+
tempCellData[fid][attr] = (
303+
cellBlock.cell.__getattribute__(attr))
304+
for flg_ in flgs_:
305+
tempCellData[fid + ('flags',)][flg_] = (
306+
cellBlock.cell.flags.__getattr__(flg_))
297307

298308
def checkMasterCellBlockData(cellBlock):
299309
"""
@@ -305,16 +315,28 @@ def checkMasterCellBlockData(cellBlock):
305315
"""
306316
if not cellBlock.cell.flags1.ignored:
307317
fid = cellBlock.cell.fid
308-
if fid not in tempCellData: return
309-
for attr in attrs:
310-
master_attr = cellBlock.cell.__getattribute__(attr)
311-
if tempCellData[fid][attr] != master_attr:
312-
cellData[fid][attr] = tempCellData[fid][attr]
313-
for flg_ in flgs_:
314-
master_flag = cellBlock.cell.flags.__getattr__(flg_)
315-
if tempCellData[fid + ('flags',)][flg_] != master_flag:
316-
cellData[fid + ('flags',)][flg_] = \
317-
(tempCellData[fid + ('flags',)][flg_])
318+
if fid in tempPersistentData:
319+
for attr in attrs:
320+
master_attr = cellBlock.cell.__getattribute__(attr)
321+
if tempPersistentData[fid][attr] != master_attr:
322+
persistentData[fid][attr] = (
323+
tempPersistentData[fid][attr])
324+
for flg_ in flgs_:
325+
master_flag = cellBlock.cell.flags.__getattr__(flg_)
326+
if tempPersistentData[fid + ('flags',)][
327+
flg_] != master_flag:
328+
persistentData[fid + ('flags',)][flg_] = (
329+
tempPersistentData[fid + ('flags',)][flg_])
330+
if fid in tempCellData:
331+
for attr in attrs:
332+
master_attr = cellBlock.cell.__getattribute__(attr)
333+
if tempCellData[fid][attr] != master_attr:
334+
cellData[fid][attr] = tempCellData[fid][attr]
335+
for flg_ in flgs_:
336+
master_flag = cellBlock.cell.flags.__getattr__(flg_)
337+
if tempCellData[fid + ('flags',)][flg_] != master_flag:
338+
cellData[fid + ('flags',)][flg_] = (
339+
tempCellData[fid + ('flags',)][flg_])
318340

319341
loadFactory = LoadFactory(False,MreRecord.type_class['CELL'],
320342
MreRecord.type_class['WRLD'])
@@ -328,6 +350,7 @@ def checkMasterCellBlockData(cellBlock):
328350
# values from the value in any of srcMod's masters.
329351
tempCellData = defaultdict(dict)
330352
tempCellData['Maps'] = {} # unused !
353+
tempPersistentData = defaultdict(dict)
331354
srcInfo = bosh.modInfos[srcMod]
332355
srcFile = ModFile(srcInfo,loadFactory)
333356
srcFile.load(True)
@@ -378,6 +401,7 @@ def checkMasterCellBlockData(cellBlock):
378401
# if worldBlock.world.mapPath != tempCellData['Maps'][worldBlock.world.fid]:
379402
# cellData['Maps'][worldBlock.world.fid] = tempCellData['Maps'][worldBlock.world.fid]
380403
tempCellData = {}
404+
tempPersistentData = {}
381405
progress.plus()
382406

383407
def scanModFile(self, modFile, progress): # scanModFile0
@@ -386,6 +410,7 @@ def scanModFile(self, modFile, progress): # scanModFile0
386410
'CELL' not in modFile.tops and 'WRLD' not in modFile.tops):
387411
return
388412
cellData = self.cellData
413+
persistentData = self.persistentData
389414
patchCells = self.patchFile.CELL
390415
patchWorlds = self.patchFile.WRLD
391416
modFile.convertToLongFids(('CELL','WRLD'))
@@ -401,6 +426,10 @@ def scanModFile(self, modFile, progress): # scanModFile0
401426
worldBlock.worldCellBlock)
402427
patchWorlds.id_worldBlocks[
403428
worldBlock.world.fid].setCell(cellBlock.cell)
429+
if worldBlock.worldCellBlock is not None:
430+
if worldBlock.worldCellBlock.cell.fid in persistentData:
431+
patchWorlds.setWorld(worldBlock.world,
432+
worldBlock.worldCellBlock)
404433
# if worldBlock.world.fid in cellData['Maps']:
405434
# patchWorlds.setWorld(worldBlock.world)
406435

@@ -417,29 +446,47 @@ def handlePatchCellBlock(patchCellBlock):
417446
to the bash patch, and the cell is flagged as modified.
418447
Modified cell Blocks are kept, the other are discarded.
419448
"""
420-
modified=False
421-
for attr, value in cellData[patchCellBlock.cell.fid].viewitems():
422-
if attr == 'regions':
423-
if set(value).difference(set(patchCellBlock.cell.__getattribute__(attr))):
424-
patchCellBlock.cell.__setattr__(attr, value)
449+
modified = False
450+
fid = patchCellBlock.cell.fid
451+
if fid in persistentData:
452+
for attr, value in persistentData[fid].iteritems():
453+
if attr == 'regions':
454+
if set(value).difference(set(
455+
patchCellBlock.cell.__getattribute__(attr))):
456+
patchCellBlock.cell.__setattr__(attr, value)
457+
modified = True
458+
else:
459+
if patchCellBlock.cell.__getattribute__(attr) != value:
460+
patchCellBlock.cell.__setattr__(attr, value)
461+
modified = True
462+
for flag, value in persistentData[fid + ('flags',)].iteritems():
463+
if patchCellBlock.cell.flags.__getattr__(flag) != value:
464+
patchCellBlock.cell.flags.__setattr__(flag, value)
465+
modified = True
466+
elif fid in cellData:
467+
for attr, value in cellData[fid].iteritems():
468+
if attr == 'regions':
469+
if set(value).difference(set(
470+
patchCellBlock.cell.__getattribute__(attr))):
471+
patchCellBlock.cell.__setattr__(attr, value)
472+
modified = True
473+
else:
474+
if patchCellBlock.cell.__getattribute__(attr) != value:
475+
patchCellBlock.cell.__setattr__(attr, value)
476+
modified = True
477+
for flag, value in cellData[fid + ('flags',)].iteritems():
478+
if patchCellBlock.cell.flags.__getattr__(flag) != value:
479+
patchCellBlock.cell.flags.__setattr__(flag, value)
425480
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',)].viewitems():
432-
if patchCellBlock.cell.flags.__getattr__(flag) != value:
433-
patchCellBlock.cell.flags.__setattr__(flag, value)
434-
modified=True
435481
if modified:
436482
patchCellBlock.cell.setChanged()
437-
keep(patchCellBlock.cell.fid)
483+
keep(fid)
438484
return modified
439485

440486
if not self.isActive: return
441487
keep = self.patchFile.getKeeper()
442-
cellData, count = self.cellData, Counter()
488+
cellData, persistentData, count = (
489+
self.cellData, self.persistentData, Counter())
443490
for cellBlock in self.patchFile.CELL.cellBlocks:
444491
if cellBlock.cell.fid in cellData and handlePatchCellBlock(cellBlock):
445492
count[cellBlock.cell.fid[0]] += 1
@@ -451,7 +498,7 @@ def handlePatchCellBlock(patchCellBlock):
451498
count[cellBlock.cell.fid[0]] += 1
452499
keepWorld = True
453500
if worldBlock.worldCellBlock:
454-
if worldBlock.worldCellBlock.cell.fid in cellData:
501+
if worldBlock.worldCellBlock.cell.fid in persistentData:
455502
if handlePatchCellBlock(worldBlock.worldCellBlock):
456503
count[worldBlock.worldCellBlock.cell.fid[0]] += 1
457504
keepWorld = True

0 commit comments

Comments
 (0)