Skip to content

Commit

Permalink
fix: Remove hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsa committed May 14, 2026
1 parent c821d69 commit 72fce32
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
7 changes: 1 addition & 6 deletions src/main/java/edu/ntnu/idi/idatt/model/Exchange.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.ntnu.idi.idatt.model;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;

Expand All @@ -11,7 +10,6 @@
import edu.ntnu.idi.idatt.model.transaction.Purchase;
import edu.ntnu.idi.idatt.model.transaction.Sale;
import edu.ntnu.idi.idatt.model.transaction.Transaction;
import edu.ntnu.idi.idatt.session.UserSession;

/**
* Exchange class
Expand Down Expand Up @@ -201,10 +199,7 @@ public void advance() {
Random random = new Random();
stockMap.values()
.forEach(s -> s.addNewSalesPrice(s.getSalesPrice()
.multiply(BigDecimal.valueOf(random.nextDouble(0.8, 1.4)).setScale(2, RoundingMode.HALF_UP))));
UserSession.getInstance().netWorthProperty().set(
UserSession.getInstance().getPlayer().getNetWorth().doubleValue()); // TODO: Remove hook from here, just for
// testing
.multiply(BigDecimal.valueOf(random.nextDouble(0.8, 1.4))).setScale(2, RoundingMode.HALF_UP)));
}

}
17 changes: 9 additions & 8 deletions src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@
import edu.ntnu.idi.idatt.view.primary.transactions.TransactionView;
import javafx.scene.Parent;

import java.math.BigDecimal;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;

public class SceneFactory {

@FunctionalInterface
public interface MVCInitializer {
public interface MVCInitInterface {
Parent execute();
}

private static Deque<MVCInitializer> navigation = new ArrayDeque<>();
private static Deque<MVCInitInterface> navigation = new ArrayDeque<>();
private static boolean navigatingBack = false;

public static void goBack() {
Expand All @@ -50,7 +48,7 @@ public static void reloadCurrent() {
navigatingBack = false;
}

private static void mark(MVCInitializer initializer) {
private static void mark(MVCInitInterface initializer) {
if (!navigatingBack) {
navigation.push(initializer);
}
Expand All @@ -62,6 +60,8 @@ public static boolean isFinal() {

public static Parent createStartView() {

navigation.clear();

StartModel model = new StartModel();
StartView view = new StartView();
StartController controller = new StartController(model);
Expand All @@ -72,13 +72,14 @@ public static Parent createStartView() {
return view.getInstance();

}
public static Parent createPortfolioView(){

public static Parent createPortfolioView() {

mark(() -> createPortfolioView());

PortfolioModel model = new PortfolioModel();
PortfolioView view = new PortfolioView();
PortfolioController controller = new PortfolioController(model);
PortfolioController controller = new PortfolioController(model);

view.setModel(model);
view.setController(controller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;

public class PlayerPortfolioComponent extends HBox {

public PlayerPortfolioComponent(Portfolio portfolio){
this.setMaxSize(Double.MAX_VALUE, 500);
this.getStyleClass().add("light");
public PlayerPortfolioComponent(Portfolio portfolio) {
this.setMaxSize(Double.MAX_VALUE, 500);
this.getStyleClass().add("light");

Label userTitle = new Label(String.format("%s's Portfolio", UserSession.getInstance().getPlayer().getName()));
Label netWorth = new Label();
netWorth.textProperty().bind(
UserSession.getInstance().netWorthProperty().asString("Net Worth: %.2f $"));
Label percentageChange = new Label("Percentage change: "+ UserSession.getInstance().netWorthProperty().doubleValue());
Label playerStatus = new Label("Player status: "+ UserSession.getInstance().getPlayer().getStatus());
Label totalShares = new Label("Total shares owned: "+ UserSession.getInstance().getPlayer().getPortfolio().getShares().size());
ArrayList<Label> labels = new ArrayList<>();
Collections.addAll(labels, netWorth, percentageChange, playerStatus, totalShares);
labels.forEach(e -> e.getStyleClass().add("portfolio-box-text"));
userTitle.getStyleClass().add("portfolio-box-title");
Label userTitle = new Label(String.format("%s's Portfolio", UserSession.getInstance().getPlayer().getName()));
Label netWorth = new Label();
netWorth.textProperty().bind(
UserSession.getInstance().netWorthProperty().asString("Net Worth: %.2f $"));
Label percentageChange = new Label(
"Percentage change: " + UserSession.getInstance().netWorthProperty().get());
Label playerStatus = new Label("Player status: " + UserSession.getInstance().getPlayer().getStatus());
Label totalShares = new Label(
"Total shares owned: " + UserSession.getInstance().getPlayer().getPortfolio().getShares().size());
ArrayList<Label> labels = new ArrayList<>();
Collections.addAll(labels, netWorth, percentageChange, playerStatus, totalShares);
labels.forEach(e -> e.getStyleClass().add("portfolio-box-text"));
userTitle.getStyleClass().add("portfolio-box-title");

UICompositor playerPortfolioComponent = new UICompositor.Builder()
.parent(new HBox())
.growWithAlignment(Pos.CENTER)
.wrap(new VBox())
.addAllContent(userTitle, netWorth, percentageChange)
.unwrap()
.filler()
.wrap(new VBox())
.growWithAlignment(Pos.BOTTOM_CENTER)
.addAllContent(playerStatus, totalShares)
.unwrap()
.build();
UICompositor playerPortfolioComponent = new UICompositor.Builder()
.parent(new HBox())
.growWithAlignment(Pos.CENTER)
.wrap(new VBox())
.addAllContent(userTitle, netWorth, percentageChange)
.unwrap()
.filler()
.wrap(new VBox())
.growWithAlignment(Pos.BOTTOM_CENTER)
.addAllContent(playerStatus, totalShares)
.unwrap()
.build();

this.getChildren().add(playerPortfolioComponent.makeUI());
}
}
this.getChildren().add(playerPortfolioComponent.makeUI());
}
}

0 comments on commit 72fce32

Please sign in to comment.