cheats: improved card commands to support names like ED-E, Lonesome Eyebot (related to #12238)

This commit is contained in:
Oleg Agafonov 2024-05-09 11:43:37 +04:00
parent 551d5d8633
commit 36d54bc7a9
4 changed files with 42 additions and 25 deletions

View file

@ -90,9 +90,10 @@ public final class SystemUtil {
private static final Pattern patternGroup = Pattern.compile("\\[(.+)\\]"); // [test new card]
private static final Pattern patternCommand = Pattern.compile("([\\w]+):([\\S ]+?):([\\S ]+):([\\d]+)"); // battlefield:Human:Island:10
private static final Pattern patternCardInfo = Pattern.compile("(^[\\dA-Z]{2,7})@([\\S ]+)" // XLN-Island
.replace("7", String.valueOf(CardUtil.TESTS_SET_CODE_LOOKUP_LENGTH))
.replace("@", CardUtil.TESTS_SET_CODE_DELIMETER)
private static final Pattern patternCardInfo = Pattern.compile("(^[\\dA-Z]{MIN,MAX})DELIMETER([\\S ]+)" // XLN-Island
.replace("MIN", String.valueOf(CardUtil.TESTS_SET_CODE_MIN_LOOKUP_LENGTH))
.replace("MAX", String.valueOf(CardUtil.TESTS_SET_CODE_MAX_LOOKUP_LENGTH))
.replace("DELIMETER", CardUtil.TESTS_SET_CODE_DELIMETER)
);
// show ext info for special commands

View file

@ -19,36 +19,47 @@ public class AddCardApiTest extends CardTestPlayerBase {
List<String> info;
info = SystemUtil.parseSetAndCardNameCommand("");
Assert.assertEquals(2, info.size());
Assert.assertEquals("", info.get(0));
Assert.assertEquals("", info.get(1));
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "", info.get(0));
Assert.assertEquals(info.toString(), "", info.get(1));
info = SystemUtil.parseSetAndCardNameCommand("single name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("", info.get(0));
Assert.assertEquals("single name", info.get(1));
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "", info.get(0));
Assert.assertEquals(info.toString(), "single name", info.get(1));
info = SystemUtil.parseSetAndCardNameCommand("SET-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("SET", info.get(0));
Assert.assertEquals("name", info.get(1));
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "SET", info.get(0));
Assert.assertEquals(info.toString(), "name", info.get(1));
// only upper case set codes can be used
info = SystemUtil.parseSetAndCardNameCommand("non-set-code-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("", info.get(0));
Assert.assertEquals("non-set-code-name", info.get(1));
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "", info.get(0));
Assert.assertEquals(info.toString(), "non-set-code-name", info.get(1));
info = SystemUtil.parseSetAndCardNameCommand("SET-card-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("SET", info.get(0));
Assert.assertEquals("card-name", info.get(1));
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "SET", info.get(0));
Assert.assertEquals(info.toString(), "card-name", info.get(1));
// must find first symbols before delimeter, e.g. TOO
info = SystemUtil.parseSetAndCardNameCommand("TOO-LONG-SET-card-name");
Assert.assertEquals(2, info.size());
Assert.assertEquals("TOO", info.get(0));
Assert.assertEquals("LONG-SET-card-name", info.get(1));
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "TOO", info.get(0));
Assert.assertEquals(info.toString(), "LONG-SET-card-name", info.get(1));
// short cards names like ED-E, Lonesome Eyebot (set code must be x3 length)
info = SystemUtil.parseSetAndCardNameCommand("ED-E, Lonesome Eyebot");
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "", info.get(0));
Assert.assertEquals(info.toString(), "ED-E, Lonesome Eyebot", info.get(1));
//
info = SystemUtil.parseSetAndCardNameCommand("XLN-ED-E, Lonesome Eyebot");
Assert.assertEquals(info.toString(), 2, info.size());
Assert.assertEquals(info.toString(), "XLN", info.get(0));
Assert.assertEquals(info.toString(), "ED-E, Lonesome Eyebot", info.get(1));
}
@Test

View file

@ -1071,9 +1071,12 @@ public class VerifyCardDataTest {
}
// CHECK: set code must be compatible with tests commands format like "SET-card"
// how-to fix: increase lookup lenth
if (set.getCode().length() + 1 > CardUtil.TESTS_SET_CODE_LOOKUP_LENGTH) {
errorsList.add("Error: set code too big for test commads lookup: " + set.getCode() + ", lookup length: " + CardUtil.TESTS_SET_CODE_LOOKUP_LENGTH);
// how-to fix: change min/max lookup length
if (set.getCode().length() < CardUtil.TESTS_SET_CODE_MIN_LOOKUP_LENGTH
|| set.getCode().length() > CardUtil.TESTS_SET_CODE_MAX_LOOKUP_LENGTH) {
errorsList.add("Error: set code un-supported by test commands lookup: " + set.getCode()
+ ", min length: " + CardUtil.TESTS_SET_CODE_MIN_LOOKUP_LENGTH
+ ", max length: " + CardUtil.TESTS_SET_CODE_MAX_LOOKUP_LENGTH);
}
boolean containsDoubleSideCards = false;

View file

@ -78,7 +78,9 @@ public final class CardUtil {
"put", "return", "exile", "discard", "sacrifice", "remove", "tap", "reveal", "pay", "collect"
);
public static final int TESTS_SET_CODE_LOOKUP_LENGTH = 6; // search set code in commands like "set_code-card_name"
// search set code in commands like "set_code-card_name"
public static final int TESTS_SET_CODE_MIN_LOOKUP_LENGTH = 3;
public static final int TESTS_SET_CODE_MAX_LOOKUP_LENGTH = 6;
public static final String TESTS_SET_CODE_DELIMETER = "-"; // delimeter for cheats and tests command "set_code-card_name"
/**