Skip to content

Commit

Permalink
feat: Adding default stocks file
Browse files Browse the repository at this point in the history
  • Loading branch information
martin committed May 22, 2026
1 parent fd86479 commit 575acb8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 14 deletions.
58 changes: 44 additions & 14 deletions src/main/java/millions/view/StartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.io.File;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Objects;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
Expand All @@ -27,6 +31,9 @@ public StartView(Stage stage) {
setSpacing(12);
setPadding(new Insets(40));

Label infoField = new Label("Select stock file, or use default");
// infoField.setMaxWidth(250);

nameField = new TextField("user");
nameField.setPromptText("Player name:");
nameField.setMaxWidth(250);
Expand All @@ -38,26 +45,32 @@ public StartView(Stage stage) {
startingAmountField
.textProperty()
.addListener((obs, oldVal, newVal) -> checkStartButtonValid());
startingAmountField.setTextFormatter(new TextFormatter<>(change -> {
if (change.getControlNewText().matches("([0-9]*)?")) {
return change;
}
return null;
}));
startingAmountField.setTextFormatter(
new TextFormatter<>(
change -> {
if (change.getControlNewText().matches("([0-9]*)?")) {
return change;
}
return null;
}));
// Pre run weeks to run simulated weeks before the player starts
preRunWeeksField = new TextField("12");
preRunWeeksField.setPromptText("Pre run weeks:");
preRunWeeksField.setMaxWidth(250);
preRunWeeksField.textProperty().addListener((obs, oldVal, newVal) -> checkStartButtonValid());
preRunWeeksField.setTextFormatter(new TextFormatter<>(change -> {
if (change.getControlNewText().matches("([0-9]*)?")) {
return change;
}
return null;
}));
preRunWeeksField.setTextFormatter(
new TextFormatter<>(
change -> {
if (change.getControlNewText().matches("([0-9]*)?")) {
return change;
}
return null;
}));

selectedFile = loadDefaultStocksFile();

filepickerButton = new Button();
filepickerButton.setText("Pick file");
filepickerButton.setText("Default stocks");
filepickerButton.setMaxWidth(250);
filepickerButton.setOnAction(
e -> {
Expand All @@ -81,7 +94,24 @@ public StartView(Stage stage) {

getChildren()
.addAll(
title, nameField, startingAmountField, preRunWeeksField, filepickerButton, startButton);
title,
nameField,
startingAmountField,
preRunWeeksField,
infoField,
filepickerButton,
startButton);

checkStartButtonValid();
}

private File loadDefaultStocksFile() {
try {
URL resource = Objects.requireNonNull(getClass().getResource("/data/default-stocks.csv"));
return Paths.get(resource.toURI()).toFile();
} catch (URISyntaxException e) {
throw new IllegalStateException("Could not load default stocks file", e);
}
}

/** Enables/Disables start button */
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/data/default-stocks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Default stock data for Millions
# symbol,name,price
AAPL,Pear Inc.,276.43
MSFT,MacroHard,404.68
GOOGL,Googly Eyes Inc.,187.34
AMZN,The Great Bazillion,214.10
TSLA,Formerly Twitter,342.58
NVDA,GPUs,191.27
META,Still Facebook,593.11
NFLX,And Chill,982.44
AMD,Advanced Meme Devices,156.79
JPM,Just Plain Money Chase,245.33
WFC,Wealthy Folks Credit,82.15
BAC,Bank of Awkward Capital,48.92
DIS,Disknee,112.55
KO,Cocaine,67.14
PEP,Pepe Cola Co.,159.03
IBM,Incredibly Boring Machines,241.07
ORCL,Databases?,171.62
SAP,Sadly Applying Patches,292.88

0 comments on commit 575acb8

Please sign in to comment.