Skip to content

Commit

Permalink
Add: Support XML tag aliases, support "attatchment" mispelling
Browse files Browse the repository at this point in the history
This initial round of updates allows for basic support of 1.8 maps,
they will load after this update.
  • Loading branch information
DanVanAtta committed Sep 12, 2020
1 parent ca7a4b4 commit cca0406
Show file tree
Hide file tree
Showing 14 changed files with 3,756 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ChangeAttachmentChange extends Change {
private final Object newValue;
private final Object oldValue;
private final String property;
private boolean clearFirst = false;
private final boolean clearFirst;

/**
* Initializes a new instance of the ChangeAttachmentChange class.
Expand All @@ -21,13 +21,13 @@ public class ChangeAttachmentChange extends Change {
*/
public ChangeAttachmentChange(
final IAttachment attachment, final Object newValue, final String property) {
checkNotNull(attachment, "null attachment; newValue: " + newValue + ", property: " + property);

attachedTo = attachment.getAttachedTo();
attachmentName = attachment.getName();
oldValue = attachment.getPropertyOrThrow(property).getValue();
this.newValue = newValue;
this.property = property;
this(
attachment.getAttachedTo(),
attachment.getName(),
newValue,
attachment.getPropertyOrThrow(property).getValue(),
property,
false);
}

/**
Expand All @@ -38,15 +38,14 @@ public ChangeAttachmentChange(
final IAttachment attachment,
final Object newValue,
final String property,
final boolean resetFirst) {
checkNotNull(attachment, "null attachment; newValue: " + newValue + ", property: " + property);

attachedTo = attachment.getAttachedTo();
clearFirst = resetFirst;
attachmentName = attachment.getName();
oldValue = attachment.getPropertyOrThrow(property).getValue();
this.newValue = newValue;
this.property = property;
final boolean clearFirst) {
this(
attachment.getAttachedTo(),
attachment.getName(),
newValue,
attachment.getPropertyOrThrow(property).getValue(),
property,
clearFirst);
}

/**
Expand All @@ -59,13 +58,13 @@ public ChangeAttachmentChange(
final Object newValue,
final Object oldValue,
final String property,
final boolean resetFirst) {
this.attachmentName = attachmentName;
final boolean clearFirst) {
this.attachmentName = attachmentName.replaceAll("ttatch", "ttach");
attachedTo = attachTo;
this.newValue = newValue;
this.oldValue = oldValue;
this.property = property;
clearFirst = resetFirst;
this.clearFirst = clearFirst;
}

public Attachable getAttachedTo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Map<String, IAttachment> getAttachments() {

@Override
public void addAttachment(final String key, final IAttachment value) {
attachments.put(key, value);
attachments.put(key.replaceAll("ttatchment", "ttachment"), value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public Optional<IAttachment> newAttachment(
checkNotNull(typeName);

final String normalizedTypeName =
typeName.replaceAll("^games\\.strategy\\.triplea\\.attachments\\.", "");
typeName.replaceAll("^.*\\.", "");
final @Nullable AttachmentFactory attachmentFactory =
attachmentFactoriesByTypeName.get(normalizedTypeName);
if (attachmentFactory != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,56 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.notNullValue;

import games.strategy.engine.data.GameData;
import java.net.URI;
import java.util.List;
import org.hamcrest.core.Is;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.triplea.util.Tuple;

final class GameParserTest {

@Test
@DisplayName("Verify backward compatibility can parse 1.8 maps")
void backwardCompatibilityCheck() throws Exception {
final URI mapUri =
GameParserTest.class.getClassLoader().getResource("v1_8_map__270BC.xml").toURI();

final GameData gameData = GameParser.parse(mapUri, new XmlGameElementMapper()).orElseThrow();

assertThat(gameData.getAttachmentOrderAndValues(), Is.is(notNullValue()));
assertThat(gameData.getAllianceTracker().getAlliances(), Is.is(notNullValue()));
assertThat(gameData.getBattleRecordsList(), Is.is(notNullValue()));
assertThat(gameData.getDelegates(), Is.is(notNullValue()));
assertThat(gameData.getDiceSides(), Is.is(notNullValue()));
assertThat(gameData.getGameLoader(), Is.is(notNullValue()));
assertThat(gameData.getGameName(), Is.is(notNullValue()));
assertThat(gameData.getGameVersion(), Is.is(notNullValue()));
assertThat(gameData.getHistory().getActivePlayer(), Is.is(notNullValue()));
assertThat(gameData.getHistory().getLastNode(), Is.is(notNullValue()));
assertThat(gameData.getMap().getTerritories(), Is.is(notNullValue()));
assertThat(gameData.getPlayerList().getPlayers(), Is.is(notNullValue()));
assertThat(
gameData.getProductionFrontierList().getProductionFrontierNames(), Is.is(notNullValue()));
assertThat(gameData.getProductionRuleList().getProductionRules(), Is.is(notNullValue()));
assertThat(gameData.getProperties(), Is.is(notNullValue()));
assertThat(gameData.getRelationshipTracker(), Is.is(notNullValue()));
assertThat(gameData.getRelationshipTypeList().getAllRelationshipTypes(), Is.is(notNullValue()));
assertThat(gameData.getRepairFrontierList().getRepairFrontierNames(), Is.is(notNullValue()));
assertThat(gameData.getResourceList().getResources(), Is.is(notNullValue()));
assertThat(gameData.getSaveGameFileName(), Is.is(notNullValue()));
assertThat(gameData.getSequence().getRound(), Is.is(notNullValue()));
assertThat(gameData.getSequence().getStep(), Is.is(notNullValue()));
assertThat(gameData.getTechnologyFrontier().getTechs(), Is.is(notNullValue()));
assertThat(gameData.getTerritoryEffectList(), Is.is(notNullValue()));
assertThat(gameData.getUnits().getUnits(), Is.is(notNullValue()));
assertThat(gameData.getUnitTypeList().getAllUnitTypes(), Is.is(notNullValue()));
}

@Nested
final class DecapitalizeTest {
@Test
Expand Down
Loading

0 comments on commit cca0406

Please sign in to comment.