Skip to content

Commit

Permalink
Merge pull request #4915 from IllianiCBT/bayLoad
Browse files Browse the repository at this point in the history
Added <50.01 Compatibility BayType Handlers
  • Loading branch information
HammerGS authored Sep 26, 2024
2 parents 2913764 + d0082ab commit 618b588
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
26 changes: 19 additions & 7 deletions MekHQ/src/mekhq/campaign/parts/Cubicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
*/
package mekhq.campaign.parts;

import java.io.PrintWriter;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.common.BayType;
import megamek.common.Entity;
import megamek.common.ITechnology;
Expand All @@ -31,6 +26,11 @@
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
import mekhq.utilities.MHQXMLUtility;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.PrintWriter;
import java.util.Objects;

/**
* A transport bay cubicle for a Mek, ProtoMek, vehicle, fighter, or small
Expand Down Expand Up @@ -164,9 +164,21 @@ protected void loadFieldsFromXmlNode(Node wn) {
for (int x = 0; x < nl.getLength(); x++) {
Node wn2 = nl.item(x);
if (wn2.getNodeName().equalsIgnoreCase("bayType")) {
bayType = BayType.parse(wn2.getTextContent());
// <50.01 compatibility handler
String bayRawValue = wn2.getTextContent();

if (Objects.equals(bayRawValue, "MECH")) {
bayRawValue = "MEK";
}

if (Objects.equals(bayRawValue, "PROTOMECH")) {
bayRawValue = "PROTOMEK";
}

bayType = BayType.parse(bayRawValue);
if (null == bayType) {
logger.error("Could not parse bay type " + wn2.getTextContent());
logger.error(String.format("Could not parse bay type %s treating as BayType.Mek",
wn2.getTextContent()));
bayType = BayType.MEK;
}
name = bayType.getDisplayName() + " Cubicle";
Expand Down
26 changes: 19 additions & 7 deletions MekHQ/src/mekhq/campaign/parts/MissingCubicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
*/
package mekhq.campaign.parts;

import java.io.PrintWriter;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.common.BayType;
import megamek.common.Entity;
import megamek.common.ITechnology;
import megamek.common.annotations.Nullable;
import megamek.logging.MMLogger;
import mekhq.campaign.Campaign;
import mekhq.utilities.MHQXMLUtility;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.PrintWriter;
import java.util.Objects;

/**
* @author Neoancient
Expand Down Expand Up @@ -123,9 +123,21 @@ protected void loadFieldsFromXmlNode(Node wn) {
for (int x = 0; x < nl.getLength(); x++) {
Node wn2 = nl.item(x);
if (wn2.getNodeName().equalsIgnoreCase("bayType")) {
bayType = BayType.parse(wn2.getTextContent());
// <50.01 compatibility handler
String bayRawValue = wn2.getTextContent();

if (Objects.equals(bayRawValue, "MECH")) {
bayRawValue = "MEK";
}

if (Objects.equals(bayRawValue, "PROTOMECH")) {
bayRawValue = "PROTOMEK";
}

bayType = BayType.parse(bayRawValue);
if (null == bayType) {
logger.error("Could not parse bay type " + wn2.getTextContent());
logger.error(String.format("Could not parse bay type %s treating as BayType.Mek",
wn2.getTextContent()));
bayType = BayType.MEK;
}
name = bayType.getDisplayName() + " Cubicle";
Expand Down

0 comments on commit 618b588

Please sign in to comment.