use of util.fig.Bag in project solution-finder by knewjade.
the class FigUtilEntryPoint method createPng.
private FigWriter createPng(MinoFactory minoFactory, ColorConverter colorConverter, FrameType frameType, List<TetfuPage> usingTetfuPages) throws FinderException {
// 日付から新しいディレクトリ名を生成
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
String dateDirName = format.format(date);
// 出力先の親ディレクトリを取得
File originOutputFile = new File(settings.getOutputFilePath());
File parentDirectory = originOutputFile.getParentFile();
// 出力先ディレクトリを作成
String baseName = getCanonicalPath(parentDirectory) + File.separatorChar + dateDirName;
File outputDirectoryFile = new File(baseName);
for (int suffix = 0; outputDirectoryFile.exists(); suffix++) {
outputDirectoryFile = new File(baseName + "_" + suffix);
}
// ファイル名の取得
String outputFileName = getRemoveExtensionFromPath(originOutputFile.getName());
if (outputFileName.isEmpty())
outputFileName = "fig";
// 出力先ディレクトリがない場合は作成
if (!outputDirectoryFile.exists()) {
boolean mkdirsSuccess = outputDirectoryFile.mkdirs();
if (!mkdirsSuccess) {
throw new FinderInitializeException("Failed to make output directory: OutputFilePath=" + originOutputFile.getName());
}
}
output(" .... Output to " + getCanonicalPath(outputDirectoryFile));
Quiz quiz = parseQuiz();
// generatorの準備
boolean usingHold = settings.isUsingHold();
FigGenerator figGenerator = createFigGenerator(frameType, usingHold, minoFactory, colorConverter);
// Bagの作成
List<TetfuPage> tetfuPages = settings.getTetfuPages();
int startPageIndex = settings.getStartPageIndex();
int endPage = settings.getEndPage();
Bag bag = createBag(colorConverter, startPageIndex, tetfuPages, quiz, usingTetfuPages);
// もし開始ページ以降にQuizが含まれるときは無視することを警告
if (tetfuPages.subList(startPageIndex + 1, endPage).stream().map(TetfuPage::getComment).anyMatch(s -> s.startsWith("#Q="))) {
output("#### WARNING: Contains Quiz in tetfu after start page. ignored");
}
String path = String.format("%s" + File.separatorChar + "%s", getCanonicalPath(outputDirectoryFile), outputFileName);
int nextBoxCount = settings.getNextBoxCount();
return new PngWriter(minoFactory, colorConverter, figGenerator, bag, nextBoxCount, path, startPageIndex);
}
use of util.fig.Bag in project solution-finder by knewjade.
the class FigUtilEntryPoint method createBag.
private Bag createBag(ColorConverter colorConverter, int startPageIndex, List<TetfuPage> tetfuPages, Quiz quiz, List<TetfuPage> usingTetfuPages) {
String comment = quiz.comment;
if (settings.isUsingHold() && comment != null) {
int holdIndex = comment.indexOf('[') + 1;
char holdChar = comment.charAt(holdIndex);
Piece hold = null;
if (holdChar != ']')
hold = Piece.valueOf(String.valueOf(holdChar).toUpperCase());
int currentIndex = comment.indexOf('(') + 1;
int currentChar = comment.charAt(currentIndex);
String next = comment.substring(comment.indexOf(')') + 1, comment.length());
List<Piece> pieces = IntStream.concat(IntStream.of(currentChar), next.chars()).mapToObj(value -> (char) value).map(String::valueOf).map(String::toUpperCase).map(Piece::valueOf).collect(Collectors.toList());
Bag bag = new Bag(pieces, hold);
for (int index = quiz.index; index < startPageIndex; index++) {
ColorType colorType = tetfuPages.get(index).getColorType();
bag.use(colorConverter.parseToBlock(colorType));
}
return bag;
} else {
List<Piece> collect = usingTetfuPages.stream().map(TetfuPage::getColorType).filter(ColorType::isMinoBlock).map(colorConverter::parseToBlock).collect(Collectors.toList());
return new Bag(collect, null);
}
}
use of util.fig.Bag in project solution-finder by knewjade.
the class FigUtilEntryPoint method createGif.
private FigWriter createGif(MinoFactory minoFactory, ColorConverter colorConverter, FrameType frameType, File originalOutputFile, List<TetfuPage> usingTetfuPages) throws FinderException {
String outputFilePath = getRemoveExtensionFromPath(getCanonicalPath(originalOutputFile));
if (outputFilePath.isEmpty())
outputFilePath = "fig";
outputFilePath += ".gif";
File outputFile = new File(outputFilePath);
if (outputFile.isDirectory())
throw new FinderInitializeException("Cannot specify directory as output file path: Output=" + settings.getOutputFilePath());
if (outputFile.exists() && !outputFile.canWrite())
throw new FinderInitializeException("Cannot write output file: Output=" + settings.getOutputFilePath());
output(" .... Output to " + getCanonicalPath(outputFile));
Quiz quiz = parseQuiz();
// generatorの準備
boolean usingHold = settings.isUsingHold();
FigGenerator figGenerator = createFigGenerator(frameType, usingHold, minoFactory, colorConverter);
// Bagの作成
List<TetfuPage> tetfuPages = settings.getTetfuPages();
int startPageIndex = settings.getStartPageIndex();
int endPage = settings.getEndPage();
Bag bag = createBag(colorConverter, startPageIndex, tetfuPages, quiz, usingTetfuPages);
// もし開始ページ以降にQuizが含まれるときは無視することを警告
if (tetfuPages.subList(startPageIndex + 1, endPage).stream().map(TetfuPage::getComment).anyMatch(s -> s.startsWith("#Q="))) {
output("#### WARNING: Contains Quiz in tetfu after start page. ignored");
}
int nextBoxCount = settings.getNextBoxCount();
int delay = settings.getDelay();
boolean isInfiniteLoop = settings.getInfiniteLoop();
return new GifWriter(minoFactory, colorConverter, figGenerator, bag, nextBoxCount, delay, outputFile, isInfiniteLoop);
}
Aggregations