Search in sources :

Example 11 with TetfuPage

use of common.tetfu.TetfuPage in project solution-finder by knewjade.

the class GifWriter method write.

@Override
public void write(List<TetfuPage> tetfuPages) throws IOException {
    boolean isLoop = isInfiniteLoop;
    try (ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(outputFile)) {
        // imageWriterの準備
        ImageWriter imageWriter = getGifImageWriter();
        imageWriter.setOutput(imageOutputStream);
        imageWriter.prepareWriteSequence(null);
        for (TetfuPage tetfuPage : tetfuPages) {
            // リセット
            figGenerator.reset();
            // 現在のミノを取得
            ColorType colorType = tetfuPage.getColorType();
            Rotate rotate = tetfuPage.getRotate();
            Mino mino = ColorType.isMinoBlock(colorType) ? minoFactory.create(colorConverter.parseToBlock(colorType), rotate) : null;
            int x = tetfuPage.getX();
            int y = tetfuPage.getY();
            // フィールドの更新
            ColoredField field = tetfuPage.getField();
            figGenerator.updateField(field, mino, x, y);
            // ミノを置くかチェック
            if (ColorType.isMinoBlock(colorType)) {
                // 現在のミノの更新
                figGenerator.updateMino(colorType, rotate, x, y);
                // bagの更新
                Piece piece = colorConverter.parseToBlock(colorType);
                bag.use(piece);
            }
            // ネクストの更新
            figGenerator.updateNext(bag.getNext(nextBoxCount));
            // ホールドの更新
            figGenerator.updateHold(bag.getHold());
            // 画像の生成
            BufferedImage image = figGenerator.fix();
            // メタデータの作成
            IIOMetadata metadata = createMetadata(imageWriter, image, delay, isLoop);
            IIOImage iioImage = new IIOImage(image, null, metadata);
            imageWriter.writeToSequence(iioImage, null);
            // 無限ループの設定は最大1度までで十分
            isLoop = false;
        }
        // imageWriterの終了処理
        imageWriter.endWriteSequence();
    }
}
Also used : TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) BufferedImage(java.awt.image.BufferedImage) IIOMetadata(javax.imageio.metadata.IIOMetadata) Piece(core.mino.Piece) ColorType(common.tetfu.common.ColorType) Mino(core.mino.Mino) ImageOutputStream(javax.imageio.stream.ImageOutputStream)

Example 12 with TetfuPage

use of common.tetfu.TetfuPage in project solution-finder by knewjade.

the class PathSettingParser method loadTetfu.

private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PathSettings settings) throws FinderParseException {
    // テト譜面のエンコード
    List<TetfuPage> decoded = encodeTetfu(data);
    // 指定されたページを抽出
    int page = wrapper.getIntegerOption("page").orElse(1);
    TetfuPage tetfuPage = extractTetfuPage(decoded, page);
    // コメントの抽出
    // 先頭が数字ではない(--clear-line -p *p7のようになる)場合でも、parserはエラーにならない
    // データ取得時にOptional.emptyがかえるだけ
    String comment = "--clear-line " + tetfuPage.getComment();
    List<String> splitComment = Arrays.stream(comment.split(" ")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    // コマンド引数を配列に変換
    String[] commentArgs = new String[splitComment.size()];
    splitComment.toArray(commentArgs);
    // オプションとして読み込む
    try {
        CommandLine commandLineTetfu = parseToCommandLine(options, parser, commentArgs);
        CommandLineWrapper newWrapper = new NormalCommandLineWrapper(commandLineTetfu);
        // 削除ラインが読み取れればOK
        newWrapper.getIntegerOption("clear-line");
        wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
    } catch (FinderParseException ignore) {
    }
    // 固定ピースの指定があるか
    Optional<Boolean> reservedOption = wrapper.getBoolOption("reserved");
    reservedOption.ifPresent(settings::setReserved);
    // 最大削除ラインの設定
    Optional<Integer> maxClearLineOption = wrapper.getIntegerOption("clear-line");
    maxClearLineOption.ifPresent(settings::setMaxClearLine);
    // フィールドを設定
    ColoredField coloredField = tetfuPage.getField();
    if (tetfuPage.isPutMino()) {
        ColorType colorType = tetfuPage.getColorType();
        Rotate rotate = tetfuPage.getRotate();
        int x = tetfuPage.getX();
        int y = tetfuPage.getY();
        ColorConverter colorConverter = new ColorConverter();
        Mino mino = new Mino(colorConverter.parseToBlock(colorType), rotate);
        coloredField.putMino(mino, x, y);
    }
    if (settings.isReserved())
        settings.setFieldWithReserved(coloredField, settings.getMaxClearLine());
    else
        settings.setField(coloredField, settings.getMaxClearLine());
    return wrapper;
}
Also used : TetfuPage(common.tetfu.TetfuPage) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Files(java.nio.file.Files) org.apache.commons.cli(org.apache.commons.cli) IOException(java.io.IOException) Tetfu(common.tetfu.Tetfu) FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) List(java.util.List) ColoredFieldFactory(common.tetfu.field.ColoredFieldFactory) MinoFactory(core.mino.MinoFactory) Charset(java.nio.charset.Charset) Paths(java.nio.file.Paths) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) Optional(java.util.Optional) CommandLineWrapper(entry.CommandLineWrapper) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) FinderParseException(exceptions.FinderParseException) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) CommandLineWrapper(entry.CommandLineWrapper) ColorType(common.tetfu.common.ColorType) ColorConverter(common.tetfu.common.ColorConverter) Mino(core.mino.Mino) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper)

Example 13 with TetfuPage

use of common.tetfu.TetfuPage in project solution-finder by knewjade.

the class PercentSettingParser method loadTetfu.

private CommandLineWrapper loadTetfu(String data, CommandLineParser parser, Options options, CommandLineWrapper wrapper, PercentSettings settings) throws FinderParseException {
    // テト譜面のエンコード
    List<TetfuPage> decoded = encodeTetfu(data);
    // 指定されたページを抽出
    int page = wrapper.getIntegerOption("page").orElse(1);
    TetfuPage tetfuPage = extractTetfuPage(decoded, page);
    // コメントの抽出
    // 先頭が数字ではない(--clear-line -p *p7のようになる)場合でも、parserはエラーにならない
    // データ取得時にOptional.emptyがかえるだけ
    String comment = "--clear-line " + tetfuPage.getComment();
    List<String> splitComment = Arrays.stream(comment.split(" ")).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toList());
    // コマンド引数を配列に変換
    String[] commentArgs = new String[splitComment.size()];
    splitComment.toArray(commentArgs);
    // オプションとして読み込む
    try {
        CommandLine commandLineTetfu = parseToCommandLine(options, parser, commentArgs);
        CommandLineWrapper newWrapper = new NormalCommandLineWrapper(commandLineTetfu);
        // 削除ラインが読み取れればOK
        newWrapper.getIntegerOption("clear-line");
        wrapper = new PriorityCommandLineWrapper(Arrays.asList(wrapper, newWrapper));
    } catch (FinderParseException ignore) {
    }
    // 最大削除ラインの設定
    Optional<Integer> maxClearLineOption = wrapper.getIntegerOption("clear-line");
    maxClearLineOption.ifPresent(settings::setMaxClearLine);
    // フィールドを設定
    ColoredField coloredField = tetfuPage.getField();
    if (tetfuPage.isPutMino()) {
        ColorType colorType = tetfuPage.getColorType();
        Rotate rotate = tetfuPage.getRotate();
        int x = tetfuPage.getX();
        int y = tetfuPage.getY();
        ColorConverter colorConverter = new ColorConverter();
        Mino mino = new Mino(colorConverter.parseToBlock(colorType), rotate);
        coloredField.putMino(mino, x, y);
    }
    settings.setField(coloredField, settings.getMaxClearLine());
    return wrapper;
}
Also used : TetfuPage(common.tetfu.TetfuPage) Arrays(java.util.Arrays) ColorType(common.tetfu.common.ColorType) org.apache.commons.cli(org.apache.commons.cli) Tetfu(common.tetfu.Tetfu) FinderParseException(exceptions.FinderParseException) MinoFactory(core.mino.MinoFactory) Charset(java.nio.charset.Charset) FieldFactory(core.field.FieldFactory) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Files(java.nio.file.Files) IOException(java.io.IOException) ColorConverter(common.tetfu.common.ColorConverter) Rotate(core.srs.Rotate) Collectors(java.util.stream.Collectors) List(java.util.List) Field(core.field.Field) Paths(java.nio.file.Paths) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) Optional(java.util.Optional) CommandLineWrapper(entry.CommandLineWrapper) ColoredField(common.tetfu.field.ColoredField) Mino(core.mino.Mino) TetfuPage(common.tetfu.TetfuPage) ColoredField(common.tetfu.field.ColoredField) Rotate(core.srs.Rotate) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) FinderParseException(exceptions.FinderParseException) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper) CommandLineWrapper(entry.CommandLineWrapper) ColorType(common.tetfu.common.ColorType) ColorConverter(common.tetfu.common.ColorConverter) Mino(core.mino.Mino) PriorityCommandLineWrapper(entry.PriorityCommandLineWrapper)

Example 14 with TetfuPage

use of common.tetfu.TetfuPage in project solution-finder by knewjade.

the class DevRandomEntryPoint method getTetfu.

private ColoredField getTetfu(MinoFactory minoFactory, ColorConverter converter) throws FinderParseException {
    if (!code.isEmpty()) {
        Tetfu tetfu = new Tetfu(minoFactory, converter);
        String removeDomainData = Tetfu.removeDomainData(code);
        String data = Tetfu.removePrefixData(removeDomainData);
        List<TetfuPage> decode = tetfu.decode(data);
        TetfuPage lastPage = decode.get(decode.size() - 1);
        return lastPage.getField();
    }
    return new ArrayColoredField(Tetfu.TETFU_MAX_HEIGHT);
}
Also used : TetfuPage(common.tetfu.TetfuPage) Tetfu(common.tetfu.Tetfu) ArrayColoredField(common.tetfu.field.ArrayColoredField)

Aggregations

TetfuPage (common.tetfu.TetfuPage)14 ColorType (common.tetfu.common.ColorType)7 ColoredField (common.tetfu.field.ColoredField)7 Mino (core.mino.Mino)7 Rotate (core.srs.Rotate)7 ColorConverter (common.tetfu.common.ColorConverter)6 MinoFactory (core.mino.MinoFactory)6 Tetfu (common.tetfu.Tetfu)5 FinderParseException (exceptions.FinderParseException)5 List (java.util.List)5 CommandLineWrapper (entry.CommandLineWrapper)4 EntryPoint (entry.EntryPoint)4 NormalCommandLineWrapper (entry.NormalCommandLineWrapper)4 PriorityCommandLineWrapper (entry.PriorityCommandLineWrapper)4 File (java.io.File)4 IOException (java.io.IOException)4 Charset (java.nio.charset.Charset)4 Files (java.nio.file.Files)4 Path (java.nio.file.Path)4 Paths (java.nio.file.Paths)4