Skip to content

Commit f69f6d4

Browse files
UtumnoInfernio
authored andcommitted
WIP - getRead/WriteClasses pruning:
Kept isActive check although this must be handled in patchFile Mopy/bash/game/oblivion/patcher/importers.py: Initially I did this here too @@ -39,2 +39,3 @@ class RoadImporter(ImportPatcher, _ARoadImporter): logMsg = u'\n=== ' + _(u'Worlds Patched') + _read_write_records = ('CELL', 'WRLD', 'ROAD',) ... but keep in mind there is a silly override in ImportPatcher def getReadClasses(self): """Returns load factory classes needed for reading.""" return tuple( x.classType for x in self.srcClasses) if self.isActive else () This needs some thought - we could bin this along with classestemp attribute, seems to just complicate stuff We also must make sure we import correctly @@ -86,3 +86,3 @@ def _overhaul_compat(self, mods, _skip_id): class ListsMerger(_AListsMerger, ListPatcher): - _read_write_records = bush.game.listTypes + _read_write_records = bush.game.listTypes # is it imported correctly ? We should add an assert_game_set() on all files that use bush.game to avoid nasty surprises Finally, all this needs better names - _read_record_signatures and some properties to replace getRead/WriteClasses (or rather override class variables)
1 parent 058534c commit f69f6d4

5 files changed

Lines changed: 23 additions & 81 deletions

File tree

Mopy/bash/game/oblivion/patcher/special.py

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ class _AAlchemicalCatalogs(SpecialPatcher):
6262
default_isEnabled = True
6363

6464
class AlchemicalCatalogs(_AAlchemicalCatalogs,Patcher):
65+
_read_write_records = ('INGR',)
6566

6667
#--Patch Phase ------------------------------------------------------------
6768
def initPatchFile(self, patchFile):
6869
super(AlchemicalCatalogs, self).initPatchFile(patchFile)
6970
self.isActive = (GPath(u'COBL Main.esm') in patchFile.loadSet)
7071
self.id_ingred = {}
7172

72-
def getReadClasses(self):
73-
"""Returns load factory classes needed for reading."""
74-
return ('INGR',) if self.isActive else ()
75-
7673
def getWriteClasses(self):
7774
"""Returns load factory classes needed for writing."""
7875
return ('BOOK',) if self.isActive else ()
@@ -375,6 +372,7 @@ def _pLog(self, log, count):
375372
log(u' * %s: %d' % (srcMod.s, count[srcMod]))
376373

377374
class CoblExhaustion(_ACoblExhaustion,ListPatcher):
375+
_read_write_records = ('SPEL',)
378376

379377
#--Patch Phase ------------------------------------------------------------
380378
def initPatchFile(self, patchFile):
@@ -411,14 +409,6 @@ def initData(self,progress):
411409
self.readFromText(getPatchesPath(srcFile))
412410
progress.plus()
413411

414-
def getReadClasses(self):
415-
"""Returns load factory classes needed for reading."""
416-
return ('SPEL',) if self.isActive else ()
417-
418-
def getWriteClasses(self):
419-
"""Returns load factory classes needed for writing."""
420-
return ('SPEL',) if self.isActive else ()
421-
422412
def scanModFile(self,modFile,progress):
423413
if not self.isActive: return
424414
mapper = modFile.getLongMapper()
@@ -558,6 +548,7 @@ def _pLog(self, log, changed):
558548
log(u'* %s: %d' % (mod.s, changed[mod]))
559549

560550
class MFactMarker(_AMFactMarker,ListPatcher):
551+
_read_write_records = ('FACT',)
561552

562553
#--Patch Phase ------------------------------------------------------------
563554
def initPatchFile(self, patchFile):
@@ -588,14 +579,6 @@ def initData(self,progress):
588579
if not rankName: rankName = _(u'Member')
589580
id_info[longid] = (morphName,rankName)
590581

591-
def getReadClasses(self):
592-
"""Returns load factory classes needed for reading."""
593-
return ('FACT',) if self.isActive else ()
594-
595-
def getWriteClasses(self):
596-
"""Returns load factory classes needed for writing."""
597-
return ('FACT',) if self.isActive else ()
598-
599582
def scanModFile(self, modFile, progress):
600583
"""Scan modFile."""
601584
if not self.isActive: return
@@ -775,6 +758,8 @@ class _ASEWorldEnforcer(SpecialPatcher):
775758
default_isEnabled = True
776759

777760
class SEWorldEnforcer(_ASEWorldEnforcer,Patcher):
761+
_read_write_records = ('QUST',)
762+
778763
#--Patch Phase ------------------------------------------------------------
779764
def initPatchFile(self, patchFile):
780765
super(SEWorldEnforcer, self).initPatchFile(patchFile)
@@ -792,14 +777,6 @@ def initPatchFile(self, patchFile):
792777
break
793778
self.isActive = bool(self.cyrodiilQuests)
794779

795-
def getReadClasses(self):
796-
"""Returns load factory classes needed for reading."""
797-
return ('QUST',) if self.isActive else ()
798-
799-
def getWriteClasses(self):
800-
"""Returns load factory classes needed for writing."""
801-
return ('QUST',) if self.isActive else ()
802-
803780
def scanModFile(self,modFile,progress):
804781
if not self.isActive: return
805782
if modFile.fileInfo.name == GPath(u'Oblivion.esm'): return

Mopy/bash/patcher/base.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,15 @@ def initPatchFile(self, patchFile):
7474
class Patcher(_Abstract_Patcher):
7575
"""Abstract base class for patcher elements performing a PBash patch - must
7676
be just before Abstract_Patcher in MRO.""" ##: "performing" ? how ?
77-
# would it make any sense to make getRead/WriteClasses() into classmethods
78-
# and just define an attribute in the classes - so getReadClasses(cls):
79-
# return cls.READ and have in subclasses just READ = 'AMMO' (say)
77+
_read_write_records = ()
8078

81-
#--Patch Phase ------------------------------------------------------------
8279
def getReadClasses(self):
8380
"""Returns load factory classes needed for reading."""
84-
return ()
81+
return self.__class__._read_write_records if self.isActive else ()
8582

8683
def getWriteClasses(self):
8784
"""Returns load factory classes needed for writing."""
88-
return ()
85+
return self.__class__._read_write_records if self.isActive else ()
8986

9087
def initData(self,progress):
9188
"""Compiles material, i.e. reads source text, esp's, etc. as

Mopy/bash/patcher/patchers/multitweak_clothes.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,13 @@ class _AClothesTweaker(AMultiTweaker):
236236
text = _(u"Tweak clothing weight and blocking.")
237237

238238
class ClothesTweaker(_AClothesTweaker,MultiTweaker):
239+
_read_write_records = ('CLOT',)
239240

240241
tweaks = sorted(itertools.chain(
241242
(ClothesTweak_Unblock(*x) for x in _AClothesTweaker._unblock),
242243
(ClothesTweak_MaxWeight(*x) for x in _AClothesTweaker._max_weight)),
243244
key=lambda a: a.label.lower())
244245

245-
#--Patch Phase ------------------------------------------------------------
246-
def getReadClasses(self):
247-
"""Returns load factory classes needed for reading."""
248-
return ('CLOT',) if self.isActive else ()
249-
250-
def getWriteClasses(self):
251-
"""Returns load factory classes needed for writing."""
252-
return ('CLOT',) if self.isActive else ()
253-
254246
def scanModFile(self,modFile,progress):
255247
if not self.isActive or 'CLOT' not in modFile.tops: return
256248
mapper = modFile.getLongMapper()

Mopy/bash/patcher/patchers/multitweak_settings.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,12 @@ class GmstTweaker(MultiTweaker, _AGmstTweaker):
205205
editOrder = 29
206206
class_tweaks = [(GlobalsTweak, bush.game.GlobalsTweaks),
207207
(GmstTweak, bush.game.GmstTweaks)]
208-
209-
#--Patch Phase ------------------------------------------------------------
210-
def getReadClasses(self):
211-
"""Returns load factory classes needed for writing."""
212-
return ('GMST','GLOB') if self.isActive else ()
213-
214-
def getWriteClasses(self):
215-
"""Returns load factory classes needed for writing."""
216-
return ('GMST','GLOB') if self.isActive else ()
208+
_read_write_records = ('GMST', 'GLOB')
217209

218210
def scanModFile(self,modFile,progress):
219211
if not self.isActive: return
220212
mapper = modFile.getLongMapper()
221-
for blockType in ['GMST','GLOB']:
213+
for blockType in self._read_write_records:
222214
if blockType not in modFile.tops: continue
223215
modBlock = getattr(modFile,blockType)
224216
patchBlock = getattr(self.patchFile,blockType)

Mopy/bash/patcher/patchers/special.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,21 @@ def _overhaul_compat(self, mods, _skip_id):
9393
self.OverhaulUOPSkips = set()
9494

9595
class ListsMerger(_AListsMerger, ListPatcher):
96+
_read_write_records = bush.game.listTypes # bush.game must be set!
9697

9798
#--Patch Phase ------------------------------------------------------------
9899
def initPatchFile(self, patchFile):
99100
super(ListsMerger, self).initPatchFile(patchFile)
100101
self.srcs_ordered = self.srcs
101102
self.srcs = set(self.srcs) & patchFile.loadSet
102-
self.listTypes = bush.game.listTypes
103-
self.type_list = dict([(type,{}) for type in self.listTypes])
103+
self.type_list = dict([(rec, {}) for rec in self._read_write_records])
104104
self.masterItems = {}
105105
self.mastersScanned = set()
106106
self.levelers = None #--Will initialize later
107107
self.empties = set()
108108
_skip_id = lambda x: (GPath(u'Oblivion.esm'), x)
109109
self._overhaul_compat(self.srcs, _skip_id)
110110

111-
def getReadClasses(self):
112-
"""Returns load factory classes needed for reading."""
113-
return self.listTypes
114-
115-
def getWriteClasses(self):
116-
"""Returns load factory classes needed for writing."""
117-
return self.listTypes
118-
119111
def scanModFile(self, modFile, progress):
120112
"""Add lists from modFile."""
121113
#--Level Masters (complete initialization)
@@ -127,10 +119,10 @@ def scanModFile(self, modFile, progress):
127119
self.delevMasters.update(bosh.modInfos[leveler].get_masters())
128120
#--Begin regular scan
129121
modName = modFile.fileInfo.name
130-
modFile.convertToLongFids(self.listTypes)
122+
modFile.convertToLongFids(self._read_write_records)
131123
#--PreScan for later Relevs/Delevs?
132124
if modName in self.delevMasters:
133-
for list_type in self.listTypes:
125+
for list_type in self._read_write_records:
134126
for levList in getattr(modFile,list_type).getActiveRecords():
135127
masterItems = self.masterItems.setdefault(levList.fid,{})
136128
masterItems[modName] = set(
@@ -141,7 +133,7 @@ def scanModFile(self, modFile, progress):
141133
isRelev = (u'Relev' in configChoice)
142134
isDelev = (u'Delev' in configChoice)
143135
#--Scan
144-
for list_type in self.listTypes:
136+
for list_type in self._read_write_records:
145137
levLists = self.type_list[list_type]
146138
newLevLists = getattr(modFile,list_type)
147139
for newLevList in newLevLists.getActiveRecords():
@@ -190,7 +182,7 @@ def buildPatch(self,log,progress):
190182
#--Save to patch file
191183
for label, type in ((_(u'Creature'), 'LVLC'), (_(u'Actor'), 'LVLN'),
192184
(_(u'Item'), 'LVLI'), (_(u'Spell'), 'LVSP')):
193-
if type not in self.listTypes: continue
185+
if type not in self._read_write_records: continue
194186
log.setHeader(u'=== '+_(u'Merged %s Lists') % label)
195187
patchBlock = getattr(self.patchFile,type)
196188
levLists = self.type_list[type]
@@ -210,7 +202,7 @@ def buildPatch(self,log,progress):
210202
if not self.remove_empty_sublists: return
211203
for label, type in ((_(u'Creature'), 'LVLC'), (_(u'Actor'), 'LVLN'),
212204
(_(u'Item'), 'LVLI'), (_(u'Spell'), 'LVSP')):
213-
if type not in self.listTypes: continue
205+
if type not in self._read_write_records: continue
214206
patchBlock = getattr(self.patchFile,type)
215207
levLists = self.type_list[type]
216208
#--Empty lists
@@ -465,27 +457,19 @@ class FidListsMerger(_AListsMerger,ListPatcher):
465457
tip = _(u"Merges changes to formid lists from all active mods.")
466458
autoKey = {u'Deflst'}
467459
iiMode = True
460+
_read_write_records = ('FLST',)
468461

469462
#--Patch Phase ------------------------------------------------------------
470463
def initPatchFile(self, patchFile):
471464
"""Prepare to handle specified patch mod. All functions are called
472465
after this."""
473466
super(FidListsMerger, self).initPatchFile(patchFile)
474467
self.srcMods = set(self.getConfigChecked()) & patchFile.loadSet
475-
self.listTypes = ('FLST',)
476-
self.type_list = dict([(type,{}) for type in self.listTypes])
468+
self.type_list = dict([(rec, {}) for rec in self._read_write_records])
477469
self.masterItems = {}
478470
self.mastersScanned = set()
479471
self.levelers = None #--Will initialize later
480472

481-
def getReadClasses(self):
482-
"""Returns load factory classes needed for reading."""
483-
return self.listTypes
484-
485-
def getWriteClasses(self):
486-
"""Returns load factory classes needed for writing."""
487-
return self.listTypes
488-
489473
def scanModFile(self, modFile, progress):
490474
"""Add lists from modFile."""
491475
#--Level Masters (complete initialization)
@@ -497,10 +481,10 @@ def scanModFile(self, modFile, progress):
497481
self.deflstMasters.update(bosh.modInfos[leveler].get_masters())
498482
#--Begin regular scan
499483
modName = modFile.fileInfo.name
500-
modFile.convertToLongFids(self.listTypes)
484+
modFile.convertToLongFids(self._read_write_records)
501485
#--PreScan for later Deflsts?
502486
if modName in self.deflstMasters:
503-
for list_type in self.listTypes:
487+
for list_type in self._read_write_records:
504488
for levList in getattr(modFile,list_type).getActiveRecords():
505489
masterItems = self.masterItems.setdefault(levList.fid,{})
506490
# masterItems[modName] = set([entry.listId for entry in levList.entries])
@@ -510,7 +494,7 @@ def scanModFile(self, modFile, progress):
510494
configChoice = self.configChoices.get(modName,tuple())
511495
isDeflst = (u'Deflst' in configChoice)
512496
#--Scan
513-
for list_type in self.listTypes:
497+
for list_type in self._read_write_records:
514498
levLists = self.type_list[list_type]
515499
newLevLists = getattr(modFile,list_type)
516500
for newLevList in newLevLists.getActiveRecords():

0 commit comments

Comments
 (0)