mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
images: tokens-database cleanup and better formatting (#14142)
* Begin by documenting the schema for tokens-database.txt * Remove first unnecessary Generate column in tokens-database.txt. Shift references to extracted params by one * Correct tokens-database.txt schema * Include info on nullable columns, and strictly expect 5 params with the last being non-optional for the Token Class Name * Extract non-nullable columns from tokens-database.txt and simplify validation on TokenClassName values being non-empty * Validate tokens-database.txt fields more robustly, and simplify parsing as a result of earlier validation being present * Remove deprecated Image Filename column from tokens-database.txt * Re-add guard if a line item isn't parsed as expected in TokenRepository * Audit and ensure all Tokens in token db point to existing Java classes
This commit is contained in:
parent
1903f56796
commit
15cd693acb
2 changed files with 2604 additions and 2599 deletions
|
|
@ -129,47 +129,46 @@ public enum TokenRepository {
|
|||
List<String> params = Arrays.stream(line.split("\\|", -1))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
if (params.size() < 5) {
|
||||
if (params.size() != 6) { // Schema specifies 4 columns. Split provides 2 extra values from trailing and leading |
|
||||
errorsList.add("Tokens database: wrong params count: " + line);
|
||||
continue;
|
||||
}
|
||||
if (!params.get(1).toLowerCase(Locale.ENGLISH).equals("generate")) {
|
||||
// TODO: remove "generate" from db
|
||||
errorsList.add("Tokens database: miss generate param: " + line);
|
||||
continue;
|
||||
}
|
||||
|
||||
String objectType = params.get(1);
|
||||
String tokenName = params.get(2);
|
||||
String tokenClassName = params.get(4); // token class name (uses for images search for render)
|
||||
|
||||
// image number (uses if one set contains multiple tokens with same name)
|
||||
int imageNumber = 0;
|
||||
if (!params.get(4).isEmpty()) {
|
||||
imageNumber = Integer.parseInt(params.get(4));
|
||||
if (!params.get(3).isEmpty()) {
|
||||
imageNumber = Integer.parseInt(params.get(3));
|
||||
}
|
||||
|
||||
// token class name (uses for images search for render)
|
||||
String tokenClassName = "";
|
||||
if (params.size() > 7 && !params.get(6).isEmpty()) {
|
||||
tokenClassName = params.get(6);
|
||||
if (objectType.isEmpty() || !objectType.matches("(?:DUNGEON|EMBLEM|PLANE|TOK):[A-Z0-9]{3,4}")) {
|
||||
errorsList.add("Tokens database: invalid object type declaration: " + line);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokenName.isEmpty()) {
|
||||
errorsList.add("Tokens database: missing token name: " + line);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tokenClassName.isEmpty()) {
|
||||
errorsList.add("Tokens database: miss class name: " + line);
|
||||
continue;
|
||||
}
|
||||
|
||||
// object type
|
||||
String objectType = params.get(2);
|
||||
String tokenName = params.get(3);
|
||||
String setCode = "";
|
||||
TokenType tokenType = null;
|
||||
String[] typeAndSet = objectType.split(":");
|
||||
|
||||
// type - token
|
||||
if (objectType.startsWith("TOK:")) {
|
||||
setCode = objectType.substring("TOK:".length());
|
||||
TokenType tokenType = null;
|
||||
String setCode = typeAndSet[1];
|
||||
|
||||
if (typeAndSet[0].equals("TOK")) {
|
||||
tokenType = TokenType.TOKEN;
|
||||
}
|
||||
|
||||
// type - emblem
|
||||
if (objectType.startsWith("EMBLEM:")) {
|
||||
setCode = objectType.substring("EMBLEM:".length());
|
||||
if (typeAndSet[0].equals("EMBLEM")) {
|
||||
tokenType = TokenType.EMBLEM;
|
||||
if (!tokenName.startsWith("Emblem ")) {
|
||||
errorsList.add("Tokens database: emblem's name must start with [Emblem ...] word: " + line);
|
||||
|
|
@ -181,9 +180,7 @@ public enum TokenRepository {
|
|||
}
|
||||
}
|
||||
|
||||
// type - plane
|
||||
if (objectType.startsWith("PLANE:")) {
|
||||
setCode = objectType.substring("PLANE:".length());
|
||||
if (typeAndSet[0].equals("PLANE")) {
|
||||
tokenType = TokenType.PLANE;
|
||||
if (!tokenName.startsWith("Plane - ")) {
|
||||
errorsList.add("Tokens database: plane's name must start with [Plane - ...] word: " + line);
|
||||
|
|
@ -195,9 +192,7 @@ public enum TokenRepository {
|
|||
}
|
||||
}
|
||||
|
||||
// type - dungeon
|
||||
if (objectType.startsWith("DUNGEON:")) {
|
||||
setCode = objectType.substring("DUNGEON:".length());
|
||||
if (typeAndSet[0].equals("DUNGEON")) {
|
||||
tokenType = TokenType.DUNGEON;
|
||||
if (!tokenClassName.endsWith("Dungeon")) {
|
||||
errorsList.add("Tokens database: dungeon's class name must ends with [...Dungeon] word: " + line);
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue