Skip to content

Commit

Permalink
Docs: JavaDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 26, 2026
1 parent e658f84 commit 5be283a
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void initInteractions() {
}

/**
* Synchronizes the controller pointers with the active game engine state references.
* Synchronizes the controller pointers with the active exchange and player objects.
*
* @param criticalExchange the current active exchange engine.
* @param activePlayer the current active player context profile.
Expand All @@ -98,16 +98,13 @@ public void handleContextUpdate(final Exchange criticalExchange, final Player ac
}
this.playerNetWorthHistory.clear();

// 1. Recover history from the updated player instance if available
if (this.player.getNetWorthHistory() != null && !this.player.getNetWorthHistory().isEmpty()) {
this.playerNetWorthHistory.addAll(this.player.getNetWorthHistory());
} else {
// Safe fallback trajectory baseline points
this.playerNetWorthHistory.add(this.player.getStartingMoney());
this.playerNetWorthHistory.add(this.player.getNetWorth());
}

// Flush updates directly into view layer
getViewElement().setWeek(this.exchange.getWeek());
getViewElement().updateChart(this.playerNetWorthHistory.stream().map(BigDecimal::floatValue).toList());
getViewElement().setBalance(this.player.getMoney().floatValue(), this.player.getNetWorth().floatValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.ntnu.idi.idatt2003.g40.mappe.model.PlayerStatus;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import java.util.List;
import javafx.geometry.Pos;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
Expand All @@ -12,19 +13,63 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import java.util.List;

/**
* Summary view is a view that is found under the topbar.
* It includes balance, status, current week, and a chart
* representing net worth over time.
*
* <p>Extends {@link ViewElement}</p>
* */
public class SummaryView extends ViewElement<HBox, SummaryActions> {
/**
* Current balance.
* */
private Label balanceLabel;

/**
* Current {@link PlayerStatus}.
* */
private Label statusLabel;

/**
* Current week.
* */
private Label weekLabel;

/**
* Balance title ("Balance/NetWorth").
* */
private Label titleLabel;

/**
* Chart representing net worth over time.
* */
private LineChart<Number, Number> chart;

/**
* Data series for chart.
* */
private XYChart.Series<Number, Number> dataSeries;

/**
* Next week button (advances week).
* */
private Button nextBtn;

/**
* X axis for chart.
* */
private NumberAxis xAxis;

/**
* Y axis for chart.
* */
private NumberAxis yAxis;

/**
* Constructor.
* */
public SummaryView() {
super(new HBox(), SummaryActions.class);
}
Expand All @@ -43,7 +88,7 @@ protected void initLayout() {

VBox balanceInfo = new VBox();

titleLabel = new Label("Networth");
titleLabel = new Label("Balance/NetWorth");
balanceLabel = new Label("0$");
statusLabel = new Label(PlayerStatus.NOOB.getDisplayName());

Expand Down Expand Up @@ -113,6 +158,12 @@ protected void initStyling() {
nextBtn.getStyleClass().add("next-button");
}

/**
* Sets the current balance and money label values.
*
* @param money the current balance.
* @param netWorth the current total networth.
* */
public void setBalance(final float money, final float netWorth) {
balanceLabel.setText(Math.round(money*100f)/100f + "NOK / " + Math.round(netWorth*100f)/100f + "NOK");
}
Expand All @@ -137,10 +188,21 @@ public void setStatus(final PlayerStatus status) {
statusLabel.getStyleClass().add("status-tier-" + status.name().toLowerCase());
}

/**
* Sets the week label text to a new week.
*
* @param week week to set.
* */
public void setWeek(int week) {
weekLabel.setText("week: " + week);
}

/**
* Updates the chart based on player net worth history.
*
* @param playerNetWorthHistory list of float values
* representing all net worth values.
* */
public void updateChart(final List<Float> playerNetWorthHistory) {
dataSeries.getData().clear();
xAxis.setLowerBound(Math.max(1, playerNetWorthHistory.size() - 10));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar;

/**
* Action set for top bar.
* */
public enum TopBarActions {
/**
* Returns to main menu.
* */
EXIT,

/**
* Go to stats page.
* */
STATS,

/**
* Go to market page.
* */
MARKET,

/**
* Go to settings page.
* */
SETTINGS,

/**
* Go to transactions page.
* */
TRANSACTIONS,

/**
* Go to minigames page.
* */
MINIGAMES;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import javafx.scene.Node;

import java.util.function.Consumer;
import javafx.scene.Node;

/**
* Controller class for {@link TopBarView}.
*
* <p>Extends {@link ViewController}</p>
* */
public class TopBarController extends ViewController<TopBarView> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,70 @@

import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryView;
import java.util.stream.Stream;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

import java.util.stream.Stream;

/**
* View element containing navigation buttons and summary.
*
* <p>Extends {@link ViewElement}</p>
* */
public class TopBarView extends ViewElement<VBox, TopBarActions> {
/**
* Quit button.
* */
private Button quitBtn;

/**
* Stats button.
* */
private Button statsBtn;

/**
* Market button.
* */
private Button marketBtn;

/**
* Settings button.
* */
private Button settingsBtn;

/**
* Transactions button.
* */
private Button transactionsBtn;

/**
* Minigames button.
* */
private Button minigamesBtn;
private SummaryView summaryView;

/**
* Summary section.
*
* @see SummaryView
* */
private SummaryView summaryView;

/**
* Constructor.
*
* @param summaryView the {@link SummaryView} section to include.
* */
public TopBarView(final SummaryView summaryView) {
this.summaryView = summaryView;
super(new VBox(10), TopBarActions.class);
}

/**
* Constructor without summary section.
* */
public TopBarView() {
super(new VBox(10), TopBarActions.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions;

import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import java.util.List;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
Expand All @@ -9,7 +10,6 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import java.util.List;

/**
* View for displaying a history of all transactions for the active player.
Expand Down

0 comments on commit 5be283a

Please sign in to comment.