This commit is contained in:
@@ -2,6 +2,8 @@ package gui;
|
||||
|
||||
import common.Signal;
|
||||
import imgui.ImGui;
|
||||
import imgui.extension.imguifiledialog.ImGuiFileDialog;
|
||||
import imgui.extension.imguifiledialog.flag.ImGuiFileDialogFlags;
|
||||
import imgui.type.ImInt;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
@@ -15,10 +17,10 @@ public class SudokuSelector {
|
||||
private final boolean canGenEmptyGrid;
|
||||
|
||||
private final ImInt sudokuType = new ImInt(0);
|
||||
|
||||
|
||||
private final ImInt difficulty = new ImInt(Difficulty.Medium.ordinal());
|
||||
private final String[] difficulties;
|
||||
|
||||
|
||||
private static final String[] sudokuTypes = { "Carré", "Rectangle", "Multidoku" };
|
||||
private static final int SQUARE = 0, RECTANGLE = 1, MULTIDOKU = 2;
|
||||
|
||||
@@ -48,6 +50,25 @@ public class SudokuSelector {
|
||||
this.onSelect.emit();
|
||||
}
|
||||
|
||||
public void renderFileDialog() {
|
||||
if (ImGuiFileDialog.display("browse-sudoku", ImGuiFileDialogFlags.None)) {
|
||||
if (ImGuiFileDialog.isOk()) {
|
||||
var selection = ImGuiFileDialog.getSelection();
|
||||
for (var entry : selection.entrySet()) {
|
||||
try {
|
||||
String filePath = entry.getValue();
|
||||
this.doku = SudokuFactory.fromfile(filePath);
|
||||
if (this.doku != null)
|
||||
this.onSelect.emit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGuiFileDialog.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void render() {
|
||||
ImGui.combo("Type de Sudoku", sudokuType, sudokuTypes);
|
||||
ImGui.combo("Difficulté", difficulty, difficulties);
|
||||
@@ -88,6 +109,10 @@ public class SudokuSelector {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (ImGui.button("À partir d'un fichier")) {
|
||||
ImGuiFileDialog.openDialog("browse-sudoku", "Choisissez un fichier", ".json", ".");
|
||||
}
|
||||
renderFileDialog();
|
||||
}
|
||||
|
||||
public MultiDoku getDoku() {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package sudoku.structure;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -10,6 +13,7 @@ import sudoku.constraint.BlockConstraint;
|
||||
import sudoku.constraint.ColumnConstraint;
|
||||
import sudoku.constraint.IConstraint;
|
||||
import sudoku.constraint.LineConstraint;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.solver.Solver;
|
||||
|
||||
public class SudokuFactory {
|
||||
@@ -148,7 +152,7 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un Sudoku vide dont les Blocks sont de taille widthBlock par heightBlock.
|
||||
@@ -246,4 +250,15 @@ public class SudokuFactory {
|
||||
}
|
||||
doku.setFilledCellsImmutable();
|
||||
}
|
||||
|
||||
public static MultiDoku fromfile(String filePath) {
|
||||
try {
|
||||
String content = Files.readString(Paths.get(filePath));
|
||||
MultiDoku doku = SudokuSerializer.deserializeSudoku(content);
|
||||
return doku;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user