Skip to content

Commit

Permalink
Docs: doc fixes, and gitignore .csv files
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 26, 2026
1 parent 8b3220e commit f7ae9ab
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ jacoco.exec
# ====== Stock data files and save files ======= #
*.txt
*.json
*.csv
72 changes: 47 additions & 25 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.SaveGameService;
import edu.ntnu.idi.idatt2003.g40.mappe.service.StockFileManager;
import edu.ntnu.idi.idatt2003.g40.mappe.service.StockFileParser;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventSubscriber;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.utils.ConfigValues;
import edu.ntnu.idi.idatt2003.g40.mappe.utils.ThemeManager;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewManager;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.creategame.CreateGameController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.creategame.CreateGameView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController;
Expand All @@ -25,18 +27,17 @@
import edu.ntnu.idi.idatt2003.g40.mappe.view.playgame.PlayGameView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.settings.SettingsController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.settings.SettingsView;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.*;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.GameEngineController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.GameEngineView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.ClickerGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.FindStockGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.TimeInputsGame;
Expand All @@ -46,19 +47,40 @@
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions.TransactionsController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions.TransactionsView;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType; // Added EventType import
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
* Main class.
*
* <p>Extends {@link Application}</p>
*
* <p>Launches the javafx thread and starts the program.</p>
* */
public class Main extends Application {

/**
* Active {@link Exchange} object.
* */
private Exchange exchange;

/**
* Active {@link Player} object.
* */
private Player player;

public static void main(String[] args) {
/**
* Main method, launches the start javafx method.
*
* @param args standard Java parameter.
* */
public static void main(final String[] args) {
launch(args);
}

Expand All @@ -77,7 +99,7 @@ public void start(final Stage stage) throws Exception {
EventManager eventManager = new EventManager();
ViewManager viewManager = new ViewManager(stage, eventManager);

// Initial fallback data loop configuration
// Loads a default file in case of misreading (fallback)
StockFileManager fileManager = new StockFileManager("src/main/resources/sp500.csv");
StockFileParser fileParser = new StockFileParser();
List<Stock> stocksInFile = fileParser.getStocksFromStrings(fileManager.readFile());
Expand Down Expand Up @@ -152,42 +174,42 @@ public void start(final Stage stage) throws Exception {
gameEngineController, clickerGame, inGameView, findStockGame, timeInputsGame
);

// --- NEW: Dynamic Context Interceptor Hook ---
// When a game loads, update controllers that keep internal stock arrays
eventManager.addSubscriber(new edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventSubscriber() {
// Adds a generic event subscriber to the event manager
// that handles STATE_RESET events. These events are
// triggered when a new save file is loaded.
// We define this implementation here, because
// this class has the highest level overview of the application.
eventManager.addSubscriber(new EventSubscriber() {
@Override
public <T> void handleEvent(final edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData<T> eventData) {
if (eventData.data() instanceof SaveGame save) {
public <T> void handleEvent(final EventData<T> eventData) {
if (eventData.data() instanceof SaveGame) {

// Only pull from CreateGameController if it contains references
if (createGameController.getExchange() != null && createGameController.getPlayer() != null) {
gameStateLoader.setExchange(createGameController.getExchange());

exchange = createGameController.getExchange();
player = createGameController.getPlayer();
} else {
// Default directly to what GameStateLoader just populated from disk
exchange = gameStateLoader.getExchange();
player = gameStateLoader.getPlayer();
}

// Pull from the explicitly assigned exchange instance
List<Stock> dynamicStocks = exchange.getStocks();

// Update UI contexts
// Updates the various UI components that
// depend on an exchange, player, or list of stocks.
findStockGame.updateStockPool(dynamicStocks.stream().map(Stock::getSymbol).toList());
summaryController.handleContextUpdate(exchange, player);
summaryController.handleContextUpdate(Main.this.exchange, Main.this.player);
dashBoardController.handleStockPoolUpdate(dynamicStocks);
statsController.handleContextUpdate(exchange, player);
marketController.handleStockPoolUpdate(exchange, player, dynamicStocks);
statsController.handleContextUpdate(Main.this.exchange, Main.this.player);
marketController.handleStockPoolUpdate(Main.this.exchange, Main.this.player, dynamicStocks);

if (!dynamicStocks.isEmpty()) {
miniGamesController.setActiveStock(dynamicStocks.getFirst());
}
}
}
}, EventType.STATE_RESET);
// ---------------------------------------------

topBarController.setMarketIntegration(
inGameView::changeCenterView, dashBoardView.getRootPane(), marketView.getRootPane(),
Expand Down Expand Up @@ -231,4 +253,4 @@ public <T> void handleEvent(final edu.ntnu.idi.idatt2003.g40.mappe.service.event

stage.show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
*
* <p>Delegates buying and selling to player elements using calculators</p>
*
* <p>Advances week.</p>
* <p>Additionally controls the time in weeks, and therefore has the main
* responsibility for advancing weeks.</p>
*
* @see Player
* @see edu.ntnu.idi.idatt2003.g40.mappe.service.TransactionCalculator
Expand Down Expand Up @@ -372,7 +373,7 @@ public List<Stock> getGainers(final int limit)
* Method for getting the stocks with the highest
* loss of price since last week.
*
* @param limit the maximum amount of stocks returned
* @param limit the maximum amount of stocks returned
*
* @return list of {@link Stock} objects.
*
Expand All @@ -398,12 +399,13 @@ public List<Stock> getLosers(final int limit)
}

/**
* Clears the current stock listings and replaces them with a new pool of stocks.
* Replaces list of stocks with a new list.
*
* <p>Used when loading a save game that uses a completely different set of
* stocks than the currently active simulation context.</p>
*
* @param newStocks the new list of {@link Stock} objects to list on the exchange.
* @param newStocks the new list of {@link Stock}
* objects to list on the exchange.
* @throws IllegalArgumentException if the provided list is null or empty.
*/
public void updateStockPool(final List<Stock> newStocks) throws IllegalArgumentException {
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javafx.beans.property.ReadOnlyFloatProperty;
import javafx.beans.property.ReadOnlyFloatWrapper;

Expand Down Expand Up @@ -131,19 +130,18 @@ public BigDecimal getMoney() {
}

/**
* Returns a read-only list of the player's historical net worth data points.
* Returns a read-only list of the player's net worth history.
*
* @return immutable sequence list of tracking records.
* @return read only list of players net-worth instances.
*/
public List<BigDecimal> getNetWorthHistory() {
return List.copyOf(netWorthHistory);
}

/**
* Clears out current history logs and replaces them with an explicit sequence list.
* Essential utility hook used by the save-game parsing framework.
* Replaces the net-worth history list of this player with a new list.
*
* @param history the historic snapshots sequence data payload.
* @param history the list to replace current list with.
*/
public void setNetWorthHistory(final List<BigDecimal> history) {
this.netWorthHistory.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package edu.ntnu.idi.idatt2003.g40.mappe.model;

import edu.ntnu.idi.idatt2003.g40.mappe.utils.Validator;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

/**
* Represents one save game entry.
* Represents one save entry for the game.
*
* <p>
* Holds the display name, current balance, starting capital,
Expand Down Expand Up @@ -49,7 +48,7 @@ public class SaveGame {
private final List<BigDecimal> netWorthHistory;

/**
* Full constructor including exchange stocks and net worth history state tracking.
* Constructor.
*
* @param name the display name of the save.
* @param balance the current balance value.
Expand Down

0 comments on commit f7ae9ab

Please sign in to comment.