partially improved launcher functionnality

This commit is contained in:
François Autin 2021-06-23 17:14:57 +02:00
parent e645f66dc8
commit e36955d948
4 changed files with 52 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import org.json.simple.parser.*;
public class Config {
public int width, height, rounds;
public boolean fullscreen;
public boolean fullscreen, hitboxes;
public String stage;
public String p1, p2;
@ -37,9 +37,8 @@ public class Config {
// print a case of this element
stage = (String) settings.get("stage");
// nb players selection
/* JSONArray nb_players = (JSONArray) jsonO.get("nb_players");
System.out.println("nb_player : " + nb_players.get(1)); */
// rounds
rounds = Integer.parseInt((String) settings.get("rounds"));
// character selection
p1 = (String) settings.get("character1");
@ -54,6 +53,12 @@ public class Config {
fullscreen = true;
} else fullscreen = false;
String hb = (String) settings.get("hitboxes");
if (hb == null) hb = "false";
if (hb.equals("true")) {
hitboxes = true;
} else hitboxes = false;
// rounds
String temprounds = (String) settings.get("rounds");
switch (temprounds) {
@ -63,13 +68,6 @@ public class Config {
default: rounds = 1;
}
// button selection
/* JSONArray allButton = (JSONArray) jsonO.get("button");
System.out.println(allButton);
String up = (String) allButton.get(0);
System.out.println("button for up is : " + up); */
} catch (FileNotFoundException e) {
File f = new File("game.set");
try {
@ -88,7 +86,7 @@ public class Config {
}
@SuppressWarnings("unchecked")
public void write(int width, int height, int rounds, boolean fullscreen, String character1, String character2, String stage) throws Exception {
public void write(int width, int height, int rounds, boolean fullscreen, boolean hitboxes, String character1, String character2, String stage) throws Exception {
JSONObject metafile = new JSONObject();
JSONArray array = new JSONArray();
@ -98,6 +96,7 @@ public class Config {
set.put("height", Integer.toString(height));
set.put("rounds", Integer.toString(rounds));
set.put("fullscreen", Boolean.toString(fullscreen));
set.put("hitboxes", Boolean.toString(hitboxes));
set.put("character1", character1);
set.put("character2", character2);
set.put("stage", stage);

View File

@ -75,6 +75,22 @@ public class Launcher extends Application {
fs.setSelected(false);
}
ChoiceBox<String> cbr = (ChoiceBox<String>) namespace.get("rounds");
ObservableList<String> nbrounds = FXCollections.observableArrayList("1", "3", "5", "7", "9");
cbr.setItems(nbrounds);
if (!nbrounds.contains(setter.getRounds())) {
cb.setValue("3");
} else {
cb.setValue(setter.getRounds());
}
CheckBox hb = (CheckBox) namespace.get("hitboxes");
if (setter.getHitboxes()) {
hb.setSelected(true);
} else {
hb.setSelected(false);
}
VBox v1 = (VBox) namespace.get("p1");
ChoiceBox<String> b1 = (ChoiceBox<String>) v1.getChildren().get(1);
VBox v2 = (VBox) namespace.get("p2");
@ -139,9 +155,14 @@ public class Launcher extends Application {
}
pointer.arraysettings.put("width", width);
pointer.arraysettings.put("height", height);
CheckBox fs = (CheckBox) namespace.get("fullscreen");
pointer.arraysettings.put("fullscreen", fs.isSelected());
pointer.arraysettings.put("rounds", 3);
CheckBox hb = (CheckBox) namespace.get("hitboxes");
pointer.arraysettings.put("hitboxes", hb.isSelected());
ChoiceBox<String> rnd = (ChoiceBox<String>) namespace.get("rounds");
pointer.arraysettings.put("rounds", rnd.getValue());
VBox vp1 = (VBox) namespace.get("p1");
ChoiceBox<String> p1 = (ChoiceBox<String>) vp1.getChildren().get(1);

View File

@ -22,12 +22,13 @@ public class Settings {
int height = (Integer) set.get("height");
int rounds = (Integer) set.get("rounds");
boolean fullscreen = (Boolean) set.get("fullscreen");
boolean hitboxes = (Boolean) set.get("hitboxes");
String character1 = (String) set.get("character1");
String character2 = (String) set.get("character2");
String stage = (String) set.get("stage");
config.write(width, height, rounds, fullscreen, character1, character2, stage);
config.write(width, height, rounds, fullscreen, hitboxes, character1, character2, stage);
} catch (Exception e) {
config.write(800, 600, 3, false, "blue", "blue", "default");
config.write(800, 600, 3, false, false, "blue", "blue", "default");
System.out.println("Incorrect config file");
}
}
@ -40,6 +41,14 @@ public class Settings {
return config.fullscreen;
}
public boolean getHitboxes() {
return config.hitboxes;
}
public String getRounds() {
return Integer.toString(config.rounds);
}
public String getChar1() {
return config.p1;
}

View File

@ -42,6 +42,14 @@
<CheckBox fx:id="fullscreen"/>
</children>
</HBox>
<Label text="Rounds"/>
<ChoiceBox fx:id="rounds" styleClass="res_box"/>
<HBox fx:id="hb_box" styleClass="fs_box">
<children>
<Label text="Hitboxes "/>
<CheckBox fx:id="hitboxes"/>
</children>
</HBox>
<Button text="Play" fx:id="btn_launch" onAction="#launch"
prefWidth="110" prefHeight="15"/>
<Button text="Quit" fx:id="btn_quit" onAction="#quit"