Skip to content

Commit

Permalink
Merge pull request #1654 from Windchild292/dev_Windchild_psrx
Browse files Browse the repository at this point in the history
Fixing load from psrx data for spouses
  • Loading branch information
Windchild292 authored Apr 10, 2020
2 parents 62d4091 + 19942a5 commit 6e53d45
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ public boolean recruitPerson(Person p, boolean prisoner, boolean dependent, bool
}
}

UUID id = UUID.randomUUID();
UUID id = (p.getId() == null) ? UUID.randomUUID() : p.getId();
p.setId(id);
personnel.put(id, p);

Expand Down
29 changes: 27 additions & 2 deletions MekHQ/src/mekhq/gui/CampaignGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ protected void loadPersonFile() {
MekHQ.getLogger().log(getClass(), METHOD_NAME, LogLevel.INFO, //$NON-NLS-1$
"Starting load of personnel file from XML..."); //$NON-NLS-1$
// Initialize variables.
Document xmlDoc = null;
Document xmlDoc;

// Open the file
try (InputStream is = new FileInputStream(personnelFile)) {
Expand All @@ -2040,7 +2040,8 @@ protected void loadPersonFile() {
// Parse using builder to get DOM representation of the XML file
xmlDoc = db.parse(is);
} catch (Exception ex) {
MekHQ.getLogger().error(getClass(), METHOD_NAME, ex); //$NON-NLS-1$
MekHQ.getLogger().error(getClass(), METHOD_NAME, "Cannot load person XML", ex);
return; // otherwise we NPE out in the next line
}

Element personnelEle = xmlDoc.getDocumentElement();
Expand Down Expand Up @@ -2091,6 +2092,30 @@ && getCampaign().getPerson(p.getId()).getFullName().equals(p.getFullName())) {
p.clearTechUnitIDs();
}
}

// Fix Spouse Id Information - This is required to fix spouse NPEs where one doesn't export
// both members of the couple
// TODO : make it so that exports will automatically include both spouses
for (Person p : getCampaign().getActivePersonnel()) {
if (p.hasSpouse() && !getCampaign().getPersonnel().contains(p.getSpouse())) {
// If this happens, we need to clear the spouse
if (p.getMaidenName() != null) {
p.setSurname(p.getMaidenName());
}

p.setSpouseId(null);
}

if (p.isPregnant()) {
String fatherIdString = p.getExtraData().get(Person.PREGNANCY_FATHER_DATA);
UUID fatherId = (fatherIdString != null) ? UUID.fromString(fatherIdString) : null;
if ((fatherId != null)
&& !getCampaign().getPersonnel().contains(getCampaign().getPerson(fatherId))) {
p.getExtraData().set(Person.PREGNANCY_FATHER_DATA, null);
}
}
}

MekHQ.getLogger().log(getClass(), METHOD_NAME, LogLevel.INFO, //$NON-NLS-1$
"Finished load of personnel file"); //$NON-NLS-1$
}
Expand Down

0 comments on commit 6e53d45

Please sign in to comment.