use of common.tetfu.decorder.CommentDecoder in project solution-finder by knewjade.
the class Tetfu method decodeMain.
private List<TetfuPage> decodeMain(String str) {
LinkedList<Integer> values = str.replace("?", "").chars().boxed().map(c -> decodeData((char) c.intValue())).collect(Collectors.toCollection(LinkedList::new));
ArrayList<TetfuPage> pages = new ArrayList<>();
ColoredField prevField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
ColoredField currentField = ColoredFieldFactory.createField(TETFU_MAX_HEIGHT);
int[] blockUp = new int[FILED_WIDTH];
int repeatCount = -1;
while (!values.isEmpty()) {
if (repeatCount <= 0) {
int index = 0;
boolean isChange = false;
while (index < TETFU_FIELD_BLOCKS) {
int diffBlock = pollValues(values, 2);
int diff = diffBlock / TETFU_FIELD_BLOCKS;
int block = diffBlock % TETFU_FIELD_BLOCKS;
if (block != TETFU_FIELD_BLOCKS - 1)
isChange = true;
for (int b = 0; b < block + 1; b++) {
int x = index % 10;
int y = TETFU_FIELD_TOP - (index / 10) - 1;
if (0 <= y) {
int prevBlockNumber = prevField.getBlockNumber(x, y);
currentField.setBlockNumber(x, y, diff + prevBlockNumber - 8);
} else {
blockUp[x] += diff - 8;
}
index += 1;
}
}
if (!isChange)
repeatCount = pollValues(values, 1);
} else {
currentField = prevField;
repeatCount -= 1;
}
int action = pollValues(values, 3);
ActionDecoder actionDecoder = new ActionDecoder(action);
String escapedComment = "";
if (actionDecoder.isComment) {
List<Integer> commentValues = new ArrayList<>();
int commentLength = pollValues(values, 2);
for (int commentCounter = 0; commentCounter < (commentLength + 3) / 4; commentCounter++) {
int commentValue = pollValues(values, 5);
commentValues.add(commentValue);
}
CommentDecoder commentDecoder = new CommentDecoder(commentLength, commentValues);
escapedComment = commentDecoder.getEscapedComment();
}
TetfuPage tetfuPage = new DecodedTetfuPage(actionDecoder, escapedComment, currentField);
pages.add(tetfuPage);
ColorType colorType = actionDecoder.colorType;
if (actionDecoder.isLock) {
if (ColorType.isMinoBlock(colorType)) {
Rotate rotate = actionDecoder.rotate;
Coordinate coordinate = actionDecoder.coordinate;
Piece piece = converter.parseToBlock(colorType);
Mino mino = minoFactory.create(piece, rotate);
currentField.putMino(mino, coordinate.x, coordinate.y);
}
currentField.clearLine();
if (actionDecoder.isBlockUp) {
currentField.blockUp();
for (int x = 0; x < TETFU_FIELD_WIDTH; x++) currentField.setBlockNumber(x, 0, blockUp[x]);
}
if (actionDecoder.isMirror)
currentField.mirror();
}
prevField = currentField;
}
return pages;
}
Aggregations