Skip to content

Commit a33ea44

Browse files
committed
Aluminium Iris Mercury
In preparation for a release. Version incremented slightly for internal revisions. `GraphType` was moved to its own file. `Main` got some deprecated features removed. More render work. Controls for adding and removing columns. Fully removed deprecated `RBMKFrame` field from `RBMKColumnBase` class.
1 parent b82187a commit a33ea44

27 files changed

+299
-215
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.uffr.rbmksim</groupId>
44
<artifactId>rbmksim</artifactId>
5-
<version>0.5.2-SNAPSHOT</version>
5+
<version>0.5.3-SNAPSHOT</version>
66
<name>RBMKSim</name>
77
<description>RBMK designer and simulator for the Minecraft mod: Hbm's Nuclear Tech Mod</description>
88
<properties>

src/org/uffr/rbmksim/main/FrameRunner.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ public class FrameRunner implements Runnable
1010
private static final Logger LOGGER = LoggerFactory.getLogger(FrameRunner.class);
1111
private Optional<RBMKFrame> frame = Optional.empty();
1212
private boolean active;
13-
/*public FrameRunner(RBMKFrame frame)
14-
{
15-
this.frame = Optional.ofNullable(frame);
16-
}*/
1713

1814
public FrameRunner()
1915
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.uffr.rbmksim.main;
2+
3+
import org.uffr.rbmksim.util.I18n;
4+
5+
public enum GraphType
6+
{
7+
HEAT("heat"),
8+
FLUX("flux"),
9+
STEAM("steam"),
10+
POWER("power"),
11+
COOLANT("coolant");
12+
13+
public final String uloc;
14+
private GraphType(String uloc)
15+
{
16+
this.uloc = "app.graphType." + uloc;
17+
}
18+
19+
@Override
20+
public String toString()
21+
{
22+
return I18n.resolve(uloc);
23+
}
24+
}

src/org/uffr/rbmksim/main/Main.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import java.util.Optional;
44

5+
import javax.annotation.Nullable;
6+
57
import org.slf4j.Logger;
68
import org.slf4j.LoggerFactory;
79
import org.uffr.rbmksim.config.ProgramConfig;
8-
import org.uffr.rbmksim.simulation.ColumnType;
910
import org.uffr.rbmksim.util.I18n;
1011
import org.uffr.uffrlib.misc.Version;
1112

@@ -22,12 +23,11 @@
2223
public class Main extends Application
2324
{
2425
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
25-
// Useful for tracking discrepancies between saved files and the currently running program.
26-
private static final Version VERSION = new Version(0, 5, 0, "SNAPSHOT");
26+
// Useful for tracking discrepancies between saved files and the currently running program. Doesn't track metadata due to how I calculate it though.
27+
private static final Version VERSION = new Version(0, 5, 3, "SNAPSHOT");
2728
// Basic strings reused in various places.
2829
public static final String EXT_BPRINT = "rbmk",
29-
EXT_RSIM = "rsim",
30-
KEY;
30+
EXT_RSIM = "rsim";
3131
// Icon of the program.
3232
public static final Image ICON_IMAGE = new Image(Main.class.getClassLoader().getResourceAsStream("resources/rad.png"));
3333

@@ -40,15 +40,6 @@ public class Main extends Application
4040
// If the simulation is running, paused otherwise.
4141
// private static boolean running = false;
4242

43-
static
44-
{
45-
// TODO Probably deprecate this
46-
final StringBuilder builder = new StringBuilder(150);
47-
for (ColumnType type : ColumnType.values())
48-
builder.append(type.symbol).append(": ").append(type.fullName).append(" Column\n");
49-
KEY = builder.toString();
50-
}
51-
5243
public static void main(String[] args)
5344
{
5445
LOGGER.debug("Entry point begun, launching...");
@@ -59,6 +50,12 @@ public static void main(String[] args)
5950
public void start(Stage primaryStage) throws Exception
6051
{
6152
LOGGER.info("Starting application...");
53+
Thread.setDefaultUncaughtExceptionHandler((t, e) ->
54+
{
55+
LOGGER.warn("Uncaught exception in program in {}", t);
56+
LOGGER.warn("Stack trace:", e);
57+
openErrorDialog(e);
58+
});
6259
stage = primaryStage;
6360
final Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("resources/main_window.fxml"));
6461
primaryStage.setTitle(I18n.resolve("app.title"));
@@ -90,7 +87,7 @@ public static Optional<RBMKFrame> getFrame()
9087
return runner.getFrame();
9188
}
9289

93-
public static void setFrame(RBMKFrame frame)
90+
public static void setFrame(@Nullable RBMKFrame frame)
9491
{
9592
runner.setFrame(frame);
9693
}
@@ -128,7 +125,7 @@ public static void openDialog(String title, String headerMessage, String content
128125
alert.show();
129126
}
130127

131-
public static void openErrorDialog(Exception e)
128+
public static void openErrorDialog(Throwable e)
132129
{
133130
LOGGER.debug("Main.openErrorDialog() triggered");
134131
openDialog(I18n.resolve("dialog.error.title"), I18n.resolve("dialog.error.header"), e.toString(), AlertType.ERROR);

src/org/uffr/rbmksim/main/MainController.java

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.uffr.rbmksim.simulation.ColumnType;
2020
import org.uffr.rbmksim.simulation.GridLocation;
2121
import org.uffr.rbmksim.simulation.RBMKColumnBase;
22-
import org.uffr.rbmksim.simulation.bcolumns.RBMKBlueprintColumn;
2322
import org.uffr.rbmksim.util.I18n;
2423
import org.uffr.rbmksim.util.InfoProviderNT;
2524
import org.uffr.rbmksim.util.RBMKRenderHelper;
@@ -32,6 +31,7 @@
3231
import javafx.fxml.Initializable;
3332
import javafx.scene.canvas.Canvas;
3433
import javafx.scene.control.Alert.AlertType;
34+
import javafx.scene.control.Button;
3535
import javafx.scene.control.ChoiceBox;
3636
import javafx.scene.control.DatePicker;
3737
import javafx.scene.control.Label;
@@ -74,6 +74,10 @@ public class MainController implements Initializable
7474
@FXML
7575
private ChoiceBox<GraphType> graphSelectionBox;
7676
@FXML
77+
private ChoiceBox<ColumnType> columnTypeBox;
78+
@FXML
79+
private Button setColumnButton, resetColumnButton;
80+
@FXML
7781
private Pane canvasPane;
7882
@FXML
7983
private AnchorPane canvasAnchor;
@@ -82,28 +86,7 @@ public class MainController implements Initializable
8286
@FXML
8387
private Label nameLabel, creatorLabel, versionLabel, dateLabel, zoomLabel;
8488
@FXML
85-
private Tooltip nameTooltip, creatorNameTooltip, versionTooltip, dateTooltip;
86-
87-
private enum GraphType
88-
{
89-
HEAT("heat"),
90-
FLUX("flux"),
91-
STEAM("steam"),
92-
POWER("power"),
93-
COOLANT("coolant");
94-
95-
public final String key;
96-
private GraphType(String key)
97-
{
98-
this.key = key;
99-
}
100-
101-
@Override
102-
public String toString()
103-
{
104-
return I18n.resolve("app.graphType." + key);
105-
}
106-
}
89+
private Tooltip nameTooltip, creatorNameTooltip, versionTooltip, dateTooltip, setColumnButtonTooltip;
10790

10891
@Override
10992
public void initialize(URL url, ResourceBundle bundle)
@@ -166,7 +149,8 @@ public void initialize(URL url, ResourceBundle bundle)
166149
method.invoke(item, I18n.resolve(unlocalized));
167150
} catch (IllegalArgumentException | InvocationTargetException | SecurityException e)
168151
{
169-
LOGGER.warn("Either assumed property controlled by setter method [" + method.getName() + "] has entry in lang file but does not have associated assumed getter method or method is not a string", e);
152+
LOGGER.warn("Either assumed property controlled by setter method [{}] has entry in lang file but does not have associated assumed getter method or method is not a string", method.getName());
153+
LOGGER.warn("Got exception:", e);
170154
}
171155
}
172156
}
@@ -176,20 +160,20 @@ public void initialize(URL url, ResourceBundle bundle)
176160
LOGGER.error("Unable to retrieve field!", e);
177161
}
178162
}
179-
LOGGER.trace("I18n complete");
163+
LOGGER.trace("I18n complete. Setting up miscellaneous fields...");
180164

181-
LOGGER.trace("Setting up miscellaneous fields...");
182-
183165
mainCanvas.heightProperty().bind(canvasPane.heightProperty());
184166
mainCanvas.widthProperty().bind(canvasPane.widthProperty());
185167

186-
for (GraphType type : GraphType.values())
187-
graphSelectionBox.getItems().add(type);
168+
graphSelectionBox.getItems().addAll(GraphType.values());
188169
graphSelectionBox.selectionModelProperty().get().selectFirst();
170+
columnTypeBox.getItems().addAll(ColumnType.values());
171+
columnTypeBox.selectionModelProperty().get().selectFirst();
189172

173+
// The "-fx-text-fill" thing doesn't do anything, doesn't seem to work
190174
infoTextArea.setStyle("-fx-font-family: monospace; -fx-background-color: DIMGRAY; -fx-text-fill: WHITE;");
191175

192-
versionTextField.setTextFormatter(new TextFormatter<>(new StringConverter<Version>()
176+
versionTextField.setTextFormatter(new TextFormatter<Version>(new StringConverter<Version>()
193177
{
194178
@Override
195179
public Version fromString(String arg0)
@@ -238,7 +222,7 @@ private void onFrameChanged()
238222
{
239223
nameTextField.setText(currentFrame.getName());
240224
creatorTextField.setText(currentFrame.getCreatorName());
241-
versionTextField.setText(currentFrame.getVersion());
225+
versionTextField.setText(currentFrame.getVersion().toString());
242226
dateInput.setValue(currentFrame.getDate());
243227
canvasAnchor.setPrefWidth(currentFrame.columns * RBMKRenderHelper.CELL_SIZE);
244228
canvasAnchor.setPrefHeight(currentFrame.rows * RBMKRenderHelper.CELL_SIZE);
@@ -255,12 +239,12 @@ private void onClickNewBlueprint()
255239
Main.setFrame(new RBMKBlueprint(mainCanvas));
256240

257241
// TODO Remove
258-
final ColumnType testType = ColumnType.BLANK;
242+
/*final ColumnType testType = ColumnType.BLANK;
259243
final RBMKFrame frame = Main.getFrame().get();
260-
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(0, 0), frame, testType, false));
261-
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(0, 10), frame, testType, false));
262-
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(10, 0), frame, testType, false));
263-
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(10, 10), frame, testType, false));
244+
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(0, 0), testType, false));
245+
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(0, 10), testType, false));
246+
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(10, 0), testType, false));
247+
frame.addColumn(new RBMKBlueprintColumn(new GridLocation(10, 10), testType, false));*/
264248

265249
onFrameChanged();
266250
}
@@ -407,10 +391,7 @@ private void onCanvasClicked(MouseEvent event)
407391
final GridLocation loc = new GridLocation(x, y);
408392
final RBMKColumnBase column = currentFrame.getColumnAtCoords(loc);
409393
currentFrame.setSelectedLocation(Optional.of(loc));
410-
if (column != null && currentFrame.getSelectedLocation().isPresent())
411-
setInfoArea(column);
412-
else
413-
infoTextArea.getChildren().clear();
394+
setInfoArea(column != null && currentFrame.getSelectedLocation().isPresent() ? column : null);
414395
currentFrame.render();
415396
}
416397
}
@@ -453,7 +434,7 @@ private void onVersionTextChanged(KeyEvent event)
453434
{
454435
LOGGER.trace("onVersionTextChanged() triggered");
455436
if (currentFrame != null && event.getCode() == KeyCode.ENTER)
456-
currentFrame.setVersion(versionTextField.getText());
437+
currentFrame.setVersion((Version) versionTextField.getTextFormatter().getValue());
457438
}
458439

459440
@FXML
@@ -484,15 +465,38 @@ private void onZoomLevelTextChanged(KeyEvent event)
484465
}
485466
}
486467

468+
@FXML
469+
private void onClickSetColumn()
470+
{
471+
LOGGER.debug("onClickSetColumn() triggered");
472+
if (currentFrame != null && currentFrame.selectedLocation.isPresent())
473+
{
474+
currentFrame.setColumn(currentFrame.selectedLocation.get(), columnTypeBox.getValue());
475+
setInfoArea(currentFrame.getColumnAtCoords(currentFrame.selectedLocation.get()));
476+
currentFrame.render();
477+
}
478+
}
479+
480+
@FXML
481+
private void onClickResetColumn()
482+
{
483+
LOGGER.debug("onClickResetColumn() triggered");
484+
if (currentFrame != null && currentFrame.selectedLocation.isPresent())
485+
{
486+
currentFrame.setColumn(currentFrame.selectedLocation.get(), null);
487+
setInfoArea(null);
488+
// Better performance?
489+
RBMKRenderHelper.eraseColumn(currentFrame.selectedLocation.get(), mainCanvas.getGraphicsContext2D(), currentFrame.getRenderer().zoom);
490+
RBMKRenderHelper.drawSelectionRect(currentFrame.selectedLocation.get(), mainCanvas.getGraphicsContext2D(), currentFrame.getRenderer().zoom);
491+
}
492+
}
493+
487494
public void setInfoArea(@Nullable InfoProviderNT infoProvider)
488495
{
489496
LOGGER.debug("Set infoTextArea with data provided by InfoProvider instance");
490497
infoTextArea.getChildren().clear();
491498
if (infoProvider != null)
492499
infoTextArea.getChildren().addAll(infoProvider.getText());
493-
494-
// infoTextArea.getChildren().add(new Text(infoProvider.asProperString()));
495-
// infoTextArea.setText(infoProvider.asProperString());
496500
}
497501

498502
private static double clampZoom(double amount)

src/org/uffr/rbmksim/main/RBMKBlueprint.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
9+
import org.uffr.rbmksim.simulation.ColumnType;
910
import org.uffr.rbmksim.simulation.GridLocation;
1011
import org.uffr.rbmksim.simulation.RBMKColumnBase;
1112
import org.uffr.rbmksim.simulation.bcolumns.RBMKBlueprintBoiler;
13+
import org.uffr.rbmksim.simulation.bcolumns.RBMKBlueprintColumn;
1214
import org.uffr.rbmksim.simulation.bcolumns.RBMKBlueprintFuel;
1315
import org.uffr.rbmksim.simulation.scolumns.RBMKBoiler;
1416
import org.uffr.rbmksim.simulation.scolumns.RBMKFuel;
@@ -45,6 +47,18 @@ else if (!(frame instanceof RBMKBlueprint))
4547
throw new IllegalArgumentException("Frame is of unknown type: " + frame.getClass());
4648
}
4749

50+
@Override
51+
protected RBMKColumnBase newOfType(GridLocation location, ColumnType type)
52+
{
53+
// Experimenting with new switches
54+
switch (type)
55+
{
56+
default -> {return new RBMKBlueprintColumn(location, type, false);}
57+
case FUEL, FUEL_SIM -> {return new RBMKBlueprintFuel(location, type, false, null);}
58+
case BOILER -> {return new RBMKBlueprintBoiler(location, type);}
59+
}
60+
}
61+
4862
@Override
4963
public void checkForDiscrepancies(List<String> discrepancies, boolean repair)
5064
{

0 commit comments

Comments
 (0)