diff --git a/src/database/QueryGenerator.java b/src/database/QueryGenerator.java index 26edb9c..2cb44a7 100644 --- a/src/database/QueryGenerator.java +++ b/src/database/QueryGenerator.java @@ -1,21 +1,35 @@ package database; -public class QueryGenerator { +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectOutputStream; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; - public static String AllFrom(String table) { - return "SELECT * FROM " + getTable(table); +public class QueryGenerator { + + private final static String url = "jdbc:postgresql://localhost:5432/ShadowHunterDatabase"; + private final static String user = "shManager"; + private final static String password = "shadowhunter1234"; + + public static String AllFrom(String tableName) { + return "SELECT * FROM " + getTable(tableName); } - public static String WithId(String table, int d) { - return "SELECT * FROM " + getTable(table) + "WHERE id =" + d; + public static String WithId(String tableName, int d) { + return "SELECT * FROM " + getTable(tableName) + "WHERE id =" + d; } - public static String WithName(String table, String name) { - return "SELECT * FROM " + getTable(table) + "WHERE nom ='" + name + "'"; + public static String WithName(String tableName, String name) { + return "SELECT * FROM " + getTable(tableName) + "WHERE nom ='" + name + "'"; } - public static String getTable(String s) { - return "public." + '"' + s + '"'; + public static String getTable(String tableName) { + return "public." + '"' + tableName + '"'; } public static String getIdWithNameFrom(String table, String name) { @@ -25,4 +39,52 @@ public class QueryGenerator { public static String getNameWithIdFrom(String table, int d) { return "SELECT name FROM " + getTable(table) + "WHERE id =" + d; } + + public static String selectObjectWithId(int id, String tableName) { + return "SELECT objet FROM" + getTable(tableName) + " WHERE id =" + id; + } + + public static Connection connect() throws SQLException { + return DriverManager.getConnection(url, user, password); + } + + public static String queryInsertObject(int id, Object o) throws IOException, SQLException { + + String table = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos; + + oos = new ObjectOutputStream(baos); + oos.writeObject(o); + oos.close(); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + + byte[] object = bais.readAllBytes(); + InputStream objectIS = new ByteArrayInputStream(object); + + if(id <= 16) { + table = getTable("CartesLumiere"); + } else if(id <= 32) { + table = getTable("CartesTenebre"); + } else if(id <= 47) { + table = getTable("CartesVision"); + } else if(id <= 57) { + table = getTable("CartesPersonnage"); + } else if(id <= 61) { + table = getTable("CartesDos"); + } + + String query = null; + query = "UPDATE" + table + " SET objet = "; + + Connection conn = connect(); + PreparedStatement pst = conn.prepareStatement(query); + pst.setBinaryStream(4, objectIS); + pst.executeUpdate(); + + return query; + } + + } diff --git a/src/domaine/properties/langue_fr.properties b/src/domaine/properties/langue_fr.properties index 4b8faf2..56790ca 100644 --- a/src/domaine/properties/langue_fr.properties +++ b/src/domaine/properties/langue_fr.properties @@ -67,5 +67,5 @@ se.soigner=Se soigner mode.claire=Mode clair musique=Musique langue=Langue -parametre=Paramétre +parametre=Paramètre enregistrer=Enregistrer \ No newline at end of file diff --git a/src/ihm/controller/MenuController.java b/src/ihm/controller/MenuController.java index 5db3678..4dc6e02 100644 --- a/src/ihm/controller/MenuController.java +++ b/src/ihm/controller/MenuController.java @@ -16,6 +16,7 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Pane; import javafx.stage.Stage; public class MenuController implements Initializable{ @@ -48,6 +49,22 @@ public class MenuController implements Initializable{ appStage.show(); + } + + @FXML + public void ouvrirParametres(MouseEvent mouseEvent) throws IOException{ + InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav"); + EffetSonore.playSoundEffect(fileSound1); + + System.out.println("Passage à l'écran des paramètres"); + final URL fxmlURL = getClass().getResource("/ihm/ressources/parametre.fxml"); + final ResourceBundle bundle = ResourceBundle.getBundle("domaine.properties.langue", Locale.FRANCE); + final FXMLLoader fxmlLoader = new FXMLLoader(fxmlURL, bundle); + Pane pane = fxmlLoader.load(); + + rootPane.getChildren().setAll(pane); + + } public void afficherRegle(MouseEvent mouseEvent) { diff --git a/src/ihm/controller/PauseController.java b/src/ihm/controller/PauseController.java index d2b2278..80ead1f 100644 --- a/src/ihm/controller/PauseController.java +++ b/src/ihm/controller/PauseController.java @@ -28,7 +28,7 @@ public class PauseController implements Initializable { private CheckBox cbEffet; String filepathMusique = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"; - InputStream fileMusique = getClass().getResourceAsStream("src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"); + InputStream fileMusique = getClass().getResourceAsStream("/ihm/ressources/musique/The_Red_Fox_Tavern.wav"); boolean MusiqueLancee = ParametreController.cbMusiqueCoche; boolean SonLance = ParametreController.cbSonCoche; @@ -53,24 +53,21 @@ public class PauseController implements Initializable { // Pour la musique if (fileMusique != null) { - System.out.println("point d'arret 1"); if (cbMusique.isSelected()) { System.out.println("\tLancement de la musique"); if (Musique.clipTimePosition == 0 && MusiqueLancee == false) { // si la musique n'a jamais été lancé Musique.playMusique(fileMusique); MusiqueLancee = true; - System.out.println("point d'arret 2"); } else - Musique.resumeMusique(Musique.clip); // si elle a deja été lancé mais mis en pause, reprend a partir du point d'arret - System.out.println("point d'arret 3"); + Musique.resumeMusique(Musique.clip); // si elle a deja été lancé mais mis en pause, reprend a partir du point d'arret } else { Musique.pauseMusique(Musique.clip); // met en pause la musique System.out.println("\tMise en pause de la musique"); } } else { - System.out.println("ON A UN PROBLEME, AUCUN POINT D'ARRET N'EST PASSE"); + System.out.println("fichier audio non trouvé"); } // Pour les effets sonores diff --git a/src/ihm/ressources/Menu.fxml b/src/ihm/ressources/Menu.fxml index 857a225..c60402b 100644 --- a/src/ihm/ressources/Menu.fxml +++ b/src/ihm/ressources/Menu.fxml @@ -9,11 +9,11 @@ - + - + +