-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for (most) 1.8 maps #7631
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package games.strategy.engine.data.gameparser; | ||
|
||
import games.strategy.triplea.Constants; | ||
import lombok.experimental.UtilityClass; | ||
|
||
/** | ||
* This converts property names and values that were used in older map XMLs and updates those values | ||
* to their newer versions. This is useful to allow the game code to only use the newer names and | ||
* values while still being able to load older maps. | ||
*/ | ||
@UtilityClass | ||
class LegacyPropertyMapper { | ||
|
||
static String mapLegacyOptionName(final String optionName) { | ||
if (optionName.equalsIgnoreCase("isParatroop")) { | ||
return "isAirTransportable"; | ||
DanVanAtta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else if (optionName.equalsIgnoreCase("isInfantry") | ||
|| optionName.equalsIgnoreCase("isMechanized")) { | ||
return "isLandTransportable"; | ||
} else if (optionName.equalsIgnoreCase("occupiedTerrOf")) { | ||
return Constants.ORIGINAL_OWNER; | ||
} else if (optionName.equalsIgnoreCase("isImpassible")) { | ||
return "isImpassable"; | ||
} else if (optionName.equalsIgnoreCase("turns")) { | ||
return "rounds"; | ||
} | ||
return optionName; | ||
DanVanAtta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public String mapLegacyOptionValue(final String optionName, final String optionValue) { | ||
if (optionName.equalsIgnoreCase("victoryCity")) { | ||
if (optionValue.equalsIgnoreCase("true")) { | ||
return "1"; | ||
} else if (optionValue.equalsIgnoreCase("false")) { | ||
return "0"; | ||
} else { | ||
return optionValue; | ||
} | ||
} | ||
return optionValue; | ||
} | ||
|
||
public String mapPropertyName(final String propertyName) { | ||
if (propertyName.equalsIgnoreCase("Battleships repair at end of round") | ||
|| propertyName.equalsIgnoreCase("Units repair at end of round")) { | ||
return Constants.TWO_HIT_BATTLESHIPS_REPAIR_END_OF_TURN; | ||
} else if (propertyName.equalsIgnoreCase("Battleships repair at beginning of round") | ||
|| propertyName.equalsIgnoreCase("Units repair at beginning of round")) { | ||
return Constants.TWO_HIT_BATTLESHIPS_REPAIR_BEGINNING_OF_TURN; | ||
} | ||
|
||
return propertyName; | ||
} | ||
|
||
static boolean ignoreOptionName(final String name) { | ||
return name.equalsIgnoreCase("takeUnitControl") || name.equalsIgnoreCase("giveUnitControl"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,8 +175,7 @@ public Optional<IAttachment> newAttachment( | |
final GameData gameData) { | ||
checkNotNull(typeName); | ||
|
||
final String normalizedTypeName = | ||
typeName.replaceAll("^games\\.strategy\\.triplea\\.attachments\\.", ""); | ||
final String normalizedTypeName = typeName.replaceAll("^.*\\.", ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this change is working as intended. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to test and fix that if needed. Having an 'or' regex is not really ideal, but we could do it. IMO the java-class designation ideally would be completely removed, but we'll need to support it going forward. Perhaps we could do just straight up hardcoded mappings. We still have reflection going on to create classes by name, an explicit mapping with explicit construction code is I think where I'd like to go (and then couple that with updating the XML so that java classes are inferred on the backend and no longer needed in the XML). |
||
final @Nullable AttachmentFactory attachmentFactory = | ||
attachmentFactoriesByTypeName.get(normalizedTypeName); | ||
if (attachmentFactory != null) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -908,11 +908,13 @@ private void resetPlayers() { | |
players = new ArrayList<>(); | ||
} | ||
|
||
private void setPlayerAttachmentName(final String name) throws GameParseException { | ||
if (name == null) { | ||
playerAttachmentName = null; | ||
private void setPlayerAttachmentName(final String playerAttachmentName) | ||
throws GameParseException { | ||
if (playerAttachmentName == null) { | ||
this.playerAttachmentName = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy found an issue: Assigning an Object to null is a code smell. Consider refactoring. |
||
return; | ||
} | ||
final String name = playerAttachmentName.replaceAll("ttatch", "ttach"); | ||
final String[] s = splitOnColon(name); | ||
if (s.length != 2) { | ||
throw new GameParseException( | ||
|
@@ -961,7 +963,7 @@ private void setPlayerAttachmentName(final String name) throws GameParseExceptio | |
&& !s[0].startsWith(Constants.USERACTION_ATTACHMENT_PREFIX)) { | ||
throw new GameParseException("attachment incorrectly named:" + s[0] + thisErrorMsg()); | ||
} | ||
playerAttachmentName = Tuple.of(s[1], s[0]); | ||
this.playerAttachmentName = Tuple.of(s[1], s[0]); | ||
} | ||
|
||
private void setPlayerAttachmentName(final Tuple<String, String> value) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,8 +500,10 @@ public Color getPlayerColor(final String playerName) { | |
|
||
/** returns the color for impassable territories. */ | ||
public Color impassableColor() { | ||
// just use getPlayerColor, since it parses the properties | ||
return getPlayerColor(Constants.PLAYER_NAME_IMPASSABLE); | ||
return Optional.ofNullable( | ||
getColorProperty(PROPERTY_COLOR_PREFIX + Constants.PLAYER_NAME_IMPASSABLE)) | ||
.or(() -> Optional.ofNullable(getColorProperty(PROPERTY_COLOR_PREFIX + "Impassible"))) | ||
.orElseGet(defaultColors::nextColor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Off-Topic: I don't think we have a nice error message for "too few default colors" yet, so that might be something to consider here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, just saw #7637 |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean we all know why this exists, but it would be nice documenting it here in the code nevertheless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same on other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in: #7661