use of util.fig.FrameType in project solution-finder by knewjade.
the class FigUtilSettings method adjust.
void adjust() {
// Quizがない場合はホールドは使えない
boolean isUsingQuiz = tetfuPages.subList(0, startPage).stream().map(TetfuPage::getComment).anyMatch(s -> s.startsWith("#Q="));
if (!isUsingQuiz)
setUsingHold(false);
// 高さの指定がないときは最も高い場所 + 1とする
if (this.height == -1) {
MinoFactory minoFactory = new MinoFactory();
ColorConverter colorConverter = new ColorConverter();
OptionalInt maxHeight = tetfuPages.subList(startPage - 1, endPage).stream().mapToInt(page -> {
ColoredField field = page.getField();
int fieldHeight = field.getUsingHeight();
ColorType colorType = page.getColorType();
if (ColorType.isMinoBlock(colorType)) {
Piece piece = colorConverter.parseToBlock(colorType);
Rotate rotate = page.getRotate();
Mino mino = minoFactory.create(piece, rotate);
int minoHeight = page.getY() + mino.getMaxY() + 1;
return fieldHeight < minoHeight ? minoHeight : fieldHeight;
} else {
return fieldHeight;
}
}).max();
this.height = maxHeight.orElse(0) + 1;
if (height <= 0)
this.height = 1;
else if (23 <= height)
this.height = 23;
}
// ホールドを使わない場合はRightに変更
if (!this.isUsingHold && frameType == FrameType.Basic) {
frameType = FrameType.Right;
}
// ネクストがない場合はチェックは必要がない
if (frameType == FrameType.NoFrame) {
return;
}
// フィールドの高さを計算し、その高さで置けるネクスト数を計算
int fieldHeight = 34 * this.height + 2;
int canPutCount = (fieldHeight - 5) / 52;
// ネクスト (& ホールド)で必要な個数を算出し、ネクストを置けるならチェック終了
int count = this.isUsingHold && frameType == FrameType.Right ? nextBoxCount + 1 : nextBoxCount;
if (count <= canPutCount)
return;
// ネクストを置けるようにフィールドの高さを調整
int needHeightPx = 52 * count + 5;
setHeight((int) Math.ceil((needHeightPx - 2) / 34.0));
}
use of util.fig.FrameType in project solution-finder by knewjade.
the class FigUtilEntryPoint method run.
@Override
public void run() throws FinderException {
output("# Setup");
output("Version = " + FinderConstant.VERSION);
MinoFactory minoFactory = new MinoFactory();
ColorConverter colorConverter = new ColorConverter();
FrameType frameType = settings.getFrameType();
File outputFile = new File(settings.getOutputFilePath());
output();
output("# Generate");
output(" -> Stopwatch start");
Stopwatch stopwatch = Stopwatch.createStartedStopwatch();
List<TetfuPage> usingTetfuPages = useTetfuPages();
FigFormat figFormat = settings.getFigFormat();
FigWriter figWriter = createFigWriter(minoFactory, colorConverter, frameType, outputFile, figFormat, usingTetfuPages);
generate(figWriter, usingTetfuPages);
stopwatch.stop();
output(" -> Stopwatch stop : " + stopwatch.toMessage(TimeUnit.MILLISECONDS));
}
use of util.fig.FrameType in project solution-finder by knewjade.
the class FigUtilSettingParser method parse.
public Optional<FigUtilSettings> parse() throws FinderParseException {
Options options = createOptions();
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parseToCommandLine(options, parser);
CommandLineWrapper wrapper = new NormalCommandLineWrapper(commandLine);
FigUtilSettings settings = new FigUtilSettings();
// help
if (wrapper.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("util fig [options]", options);
return Optional.empty();
}
// ホールドの設定
Optional<Boolean> isUsingHold = wrapper.getBoolOption("hold");
isUsingHold.ifPresent(settings::setUsingHold);
// ループの設定
Optional<Boolean> isInfiniteLoop = wrapper.getBoolOption("loop");
isInfiniteLoop.ifPresent(settings::setInfiniteLoop);
// アウトプットファイルの設定
Optional<String> outputPath = wrapper.getStringOption("output");
outputPath.ifPresent(settings::setOutputFilePath);
// ディレイタイムの設定
Optional<Integer> delay = wrapper.getIntegerOption("delay");
try {
delay.ifPresent(value -> {
if (value <= 0)
throw new RuntimeException("Delay should be positive: delay=" + value);
settings.setDelay(value);
});
} catch (RuntimeException e) {
throw new FinderParseException(e.getMessage());
}
// フレームの設定
Optional<String> frameTypeName = wrapper.getStringOption("frame");
try {
Optional<FrameType> frameType = frameTypeName.map(frame -> {
try {
return parseFrameType(frame);
} catch (UnsupportedDataTypeException e) {
throw new RuntimeException(e);
}
});
frameType.ifPresent(settings::setFrameType);
} catch (RuntimeException e) {
throw new FinderParseException("Unsupported frame: frame=" + frameTypeName.orElse("<empty>"));
}
// フォーマットの設定
Optional<String> formatName = wrapper.getStringOption("format");
try {
Optional<FigFormat> figFormat = formatName.map(format -> {
try {
return parseFigFormat(format);
} catch (UnsupportedDataTypeException e) {
throw new RuntimeException(e);
}
});
figFormat.ifPresent(settings::setFigFormat);
} catch (RuntimeException e) {
throw new FinderParseException("Unsupported format: format=" + formatName.orElse("<empty>"));
}
// 高さの設定
Optional<Integer> height = wrapper.getIntegerOption("line");
try {
height.ifPresent(value -> {
if (value == 0)
throw new RuntimeException("Line should be positive or -1: line=" + value);
settings.setHeight(value);
});
} catch (RuntimeException e) {
throw new FinderParseException(e.getMessage());
}
// テト譜の設定
if (wrapper.hasOption("tetfu")) {
// パラメータから
Optional<String> tetfuData = wrapper.getStringOption("tetfu");
if (!tetfuData.isPresent())
throw new FinderParseException("Should specify option value: --tetfu");
String encoded = Tetfu.removeDomainData(tetfuData.get());
wrapper = loadTetfu(encoded, wrapper, settings);
} else {
// フィールドファイルから
Optional<String> fieldPathOption = wrapper.getStringOption("field-path");
String fieldPath = fieldPathOption.orElse(DEFAULT_FIELD_TXT);
Path path = Paths.get(fieldPath);
Charset charset = Charset.forName(CHARSET_NAME);
try {
LinkedList<String> fieldLines = Files.lines(path, charset).map(str -> {
if (str.contains("#"))
return str.substring(0, str.indexOf('#'));
return str;
}).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toCollection(LinkedList::new));
if (fieldLines.isEmpty())
throw new FinderParseException("Should specify field-definition in field file");
String encoded = fieldLines.get(0);
String removeDomainData = Tetfu.removeDomainData(encoded);
wrapper = loadTetfu(removeDomainData, wrapper, settings);
} catch (IOException e) {
throw new FinderParseException("Cannot open field file", e);
}
}
// ネクストの設定
Optional<Integer> next = wrapper.getIntegerOption("next");
Optional<Integer> positiveNext = next.map(integer -> 0 < integer ? integer : 0);
positiveNext.ifPresent(settings::setNextBoxCount);
return Optional.of(settings);
}
Aggregations