Skip to content

Commit

Permalink
feat: Make player status a observable field in UserSession
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsa committed May 25, 2026
1 parent e2a5eb2 commit 20a8e50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt/session/UserSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import edu.ntnu.idi.idatt.storage.SessionManager;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;

/**
* Class for managing current session.
Expand Down Expand Up @@ -83,6 +84,7 @@ public void setExchange(Exchange exchange) {
private final SimpleObjectProperty<BigDecimal> moneyProperty = new SimpleObjectProperty<>(BigDecimal.ZERO);
private final SimpleObjectProperty<BigDecimal> netWorthProperty = new SimpleObjectProperty<>(BigDecimal.ZERO);
private final SimpleIntegerProperty weekProperty = new SimpleIntegerProperty();
private final SimpleStringProperty statusProperty = new SimpleStringProperty();

/**
* Getter for moneyProperty.
Expand Down Expand Up @@ -111,6 +113,15 @@ public SimpleIntegerProperty weekProperty() {
return weekProperty;
}

/**
* Getter for statusProperty.
*
* @return SimpleStringProperty;
*/
public SimpleStringProperty statusProperty() {
return statusProperty;
}

/**
* Method used for updating the game state.
* <p>
Expand All @@ -128,6 +139,7 @@ public void updateGameState() {
moneyProperty.set(player.getMoney());
netWorthProperty.set(player.getNetWorth());
weekProperty.set(exchange.getWeek());
statusProperty.set(player.getStatus());
SessionManager.saveSession();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ public static Parent createToolbar(ActionEventHandler menuHandle, ActionEventHan
week.textProperty().bind(
UserSession.getInstance().weekProperty().asString("Week: %d"));

// Player status only advances at purchases, doesn't need to be a observable
// value when saving game state.
Label playerStatus = new Label("Status: " + UserSession.getInstance().getPlayer().getStatus());
Label playerStatus = new Label();
playerStatus.textProperty().bind(Bindings.format("Status: %s",
UserSession.getInstance().statusProperty()));

Label playerNetWorth = new Label();
playerNetWorth.textProperty().bind(
Expand Down

0 comments on commit 20a8e50

Please sign in to comment.