-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hasty writeToMod implementation EEE XXX
what's the deal with modFile.tops[top_grup_sig].getActiveRecords() vs typeBlock.records ?? What should we prefer?
- Loading branch information
Showing
1 changed file
with
38 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,25 @@ def readFromMod(self, modInfo): | |
def _read_record(self, record, id_data): | ||
raise AbstractError | ||
|
||
_changed_type = dict | ||
def writeToMod(self,modInfo): | ||
"""Hasty writeToMod implementation - export id_stored_data to specified | ||
mod.""" | ||
modFile = self._load_plugin(modInfo) | ||
changed = self._changed_type() | ||
for type_ in self._parser_sigs: | ||
id_name = self.id_stored_data.get(type_, None) | ||
typeBlock = modFile.tops.get(type_,None) | ||
if not id_name or not typeBlock: continue | ||
for record in typeBlock.records: # FIXME getActiveRecords???? | ||
self._write_record(record, id_name, changed) | ||
changed = self._additional_processing(changed, modFile) | ||
if changed: modFile.safeSave() | ||
return changed | ||
|
||
def _additional_processing(self, changed, modFile): | ||
return changed | ||
|
||
# TODO(inf) Once refactoring is done, we could easily take in Progress objects | ||
# for more accurate progress bars when importing/exporting | ||
class _AParser(_HandleAliases): | ||
|
@@ -627,24 +646,14 @@ def __init__(self, aliases_=None, questionableEidsSet=None, | |
def _read_record(self, record, id_data): | ||
if record.eid: id_data[record.fid] = record.eid | ||
|
||
def writeToMod(self,modInfo): | ||
"""Exports eids to specified mod.""" | ||
modFile = self._load_plugin(modInfo) | ||
changed = [] | ||
for type_ in self._parser_sigs: | ||
id_eid = self.id_stored_data.get(type_, None) | ||
typeBlock = modFile.tops.get(type_, None) | ||
if not id_eid or not typeBlock: continue | ||
for record in typeBlock.records: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Infernio
via email
Member
|
||
self._write_record(record, id_eid, changed) | ||
def _additional_processing(self, changed, modFile): | ||
#--Update scripts | ||
old_new = dict(self.old_new) | ||
old_new.update({oldEid.lower(): newEid for oldEid, newEid in changed}) | ||
changed.extend(self.changeScripts(modFile,old_new)) | ||
#--Done | ||
if changed: modFile.safeSave() | ||
return changed | ||
|
||
_changed_type = list | ||
def _write_record(self, record, id_eid, changed): | ||
newEid = id_eid.get(record.fid) | ||
oldEid = record.eid | ||
|
@@ -865,19 +874,6 @@ def _read_record(self, record, id_data): | |
if record.eid and full: # never used from patcher | ||
id_data[record.fid] = {u'eid': record.eid, u'full': full} | ||
|
||
def writeToMod(self,modInfo): | ||
"""Exports id_stored_data to specified mod.""" | ||
modFile = self._load_plugin(modInfo) | ||
changed = {} | ||
for type_ in self._parser_sigs: | ||
id_name = self.id_stored_data.get(type_, None) | ||
typeBlock = modFile.tops.get(type_,None) | ||
if not id_name or not typeBlock: continue | ||
for record in typeBlock.records: | ||
self._write_record(record, id_name, changed) | ||
if changed: modFile.safeSave() | ||
return changed | ||
|
||
def _write_record(self, record, id_name, changed): | ||
longid = record.fid | ||
full = record.full | ||
|
@@ -931,29 +927,24 @@ def _read_record(self, record, id_data): | |
id_data[record.fid].update( | ||
izip(atts, (getattr(record, a) for a in atts))) | ||
|
||
def writeToMod(self,modInfo): | ||
_changed_type = Counter #--changed[modName] = numChanged | ||
def _write_record(self, record, id_levels, changed): | ||
"""Writes stats to specified mod.""" | ||
modFile = self._load_plugin(modInfo) | ||
changed = Counter() #--changed[modName] = numChanged | ||
for top_grup_sig, fid_attr_value in self.id_stored_data.iteritems(): | ||
for record in modFile.tops[top_grup_sig].getActiveRecords(): | ||
longid = record.fid | ||
itemStats = fid_attr_value.get(longid,None) | ||
if not itemStats: continue | ||
change = False | ||
for stat_key, n_stat in itemStats.iteritems(): | ||
if change: | ||
setattr(record, stat_key, n_stat) | ||
continue | ||
o_stat = getattr(record, stat_key) | ||
change = o_stat != n_stat | ||
if change: | ||
setattr(record, stat_key, n_stat) | ||
if change: | ||
record.setChanged() | ||
changed[longid[0]] += 1 | ||
if changed: modFile.safeSave() | ||
return changed | ||
longid = record.fid | ||
itemStats = id_levels.get(longid,None) | ||
if not itemStats: return | ||
change = False | ||
for stat_key, n_stat in itemStats.iteritems(): | ||
if change: | ||
setattr(record, stat_key, n_stat) | ||
continue | ||
o_stat = getattr(record, stat_key) | ||
change = o_stat != n_stat | ||
if change: | ||
setattr(record, stat_key, n_stat) | ||
if change: | ||
record.setChanged() | ||
changed[longid[0]] += 1 | ||
|
||
def _parse_line(self, csv_fields): | ||
"""Reads stats from specified text file.""" | ||
|
@Infernio note this vs
modFile.tops[top_grup_sig].getActiveRecords()
- so what is the correct thing to do in base?