Skip to content

Commit

Permalink
Hasty writeToMod implementation EEE XXX
Browse files Browse the repository at this point in the history
what's the deal with modFile.tops[top_grup_sig].getActiveRecords() vs
typeBlock.records ?? What should we prefer?
  • Loading branch information
Utumno committed May 4, 2021
1 parent 4a7c223 commit 88097f4
Showing 1 changed file with 38 additions and 47 deletions.
85 changes: 38 additions & 47 deletions Mopy/bash/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.

Copy link
@Utumno

Utumno May 4, 2021

Author Member

@Infernio note this vs modFile.tops[top_grup_sig].getActiveRecords() - so what is the correct thing to do in base?

This comment has been minimized.

Copy link
@Infernio

Infernio via email May 4, 2021

Member

This comment has been minimized.

Copy link
@Utumno

Utumno May 5, 2021

Author Member

Done in c1ea75b for parsers LGTY?

This comment has been minimized.

Copy link
@Infernio

Infernio May 5, 2021

Member

Yup, LGTM.

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 88097f4

Please sign in to comment.