This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.concurrent.CancellationException;
|
||||
import gui.SudokuRenderer;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiStyle;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.solver.Solver;
|
||||
import sudoku.structure.MultiDoku;
|
||||
|
||||
@@ -14,6 +15,7 @@ public class SudokuView extends BaseView {
|
||||
private final SudokuRenderer sudokuRenderer;
|
||||
private Thread resolveThread;
|
||||
private final MultiDoku doku;
|
||||
private String lastSavePath = null;
|
||||
|
||||
private boolean resolved = false;
|
||||
|
||||
@@ -94,10 +96,23 @@ public class SudokuView extends BaseView {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderSaveButton() {
|
||||
if (ImGui.button("Sauvegarder l'état de la grille")) {
|
||||
lastSavePath = SudokuSerializer.saveMultiDoku(doku);
|
||||
ImGui.openPopup("saveDone");
|
||||
}
|
||||
if (ImGui.beginPopup("saveDone")) {
|
||||
ImGui.text("Sudoku sauvegardé dans ");
|
||||
ImGui.text(lastSavePath);
|
||||
ImGui.endPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
sudokuRenderer.render();
|
||||
renderSolveButton();
|
||||
renderSaveButton();
|
||||
renderCancelButton();
|
||||
renderReturnButton();
|
||||
}
|
||||
|
||||
@@ -106,9 +106,9 @@ public class SudokuSerializer {
|
||||
/**
|
||||
* Save a serialized MultiDoku in a JSON file.
|
||||
* @param doku MultiDoku, MultiDoku to save.
|
||||
* @return int, number of the save.
|
||||
* @return String, the path of the save.
|
||||
*/
|
||||
public static int saveMultiDoku(final MultiDoku doku) {
|
||||
public static String saveMultiDoku(final MultiDoku doku) {
|
||||
|
||||
JSONObject jsonRoot = serializeSudoku(doku);
|
||||
|
||||
@@ -123,9 +123,9 @@ public class SudokuSerializer {
|
||||
try (FileWriter file = new FileWriter(f)) {
|
||||
file.write(jsonRoot.toString(3));
|
||||
} catch (IOException e) {
|
||||
e.fillInStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return i;
|
||||
return f.getAbsolutePath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package sudoku;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.Random;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class SudokuSerializerTest {
|
||||
|
||||
void testSerializeWithSize(int blockWidth, int blockHeight) {
|
||||
@@ -24,10 +20,10 @@ public class SudokuSerializerTest {
|
||||
|
||||
void testSaveWithSize(int blockWidth, int blockHeight) {
|
||||
MultiDoku doku = SudokuFactory.createBasicEmptyRectangleSudoku(blockWidth, blockHeight);
|
||||
int saveNumber = SudokuSerializer.saveMultiDoku(doku);
|
||||
String savePath = SudokuSerializer.saveMultiDoku(doku);
|
||||
MultiDoku otherDoku = null;
|
||||
try {
|
||||
otherDoku = SudokuSerializer.getSavedMultiDoku(saveNumber);
|
||||
otherDoku = SudokuFactory.fromfile(savePath);
|
||||
assert (otherDoku != null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user