From f7ae9aba07c1e8ed6e95ccfcd4fb8a49ea684209 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 26 May 2026 04:04:54 +0200 Subject: [PATCH] Docs: doc fixes, and gitignore .csv files --- .gitignore | 1 + .../ntnu/idi/idatt2003/g40/mappe/Main.java | 72 ++++++++++++------- .../idatt2003/g40/mappe/engine/Exchange.java | 10 +-- .../idi/idatt2003/g40/mappe/model/Player.java | 10 ++- .../idatt2003/g40/mappe/model/SaveGame.java | 5 +- 5 files changed, 60 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index baa62d6..5b1c7f5 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ jacoco.exec # ====== Stock data files and save files ======= # *.txt *.json +*.csv \ No newline at end of file diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java index f5470bf..348cf5c 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java @@ -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; @@ -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; @@ -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. + * + *

Extends {@link Application}

+ * + *

Launches the javafx thread and starts the program.

+ * */ 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); } @@ -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 stocksInFile = fileParser.getStocksFromStrings(fileManager.readFile()); @@ -152,34 +174,35 @@ 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 void handleEvent(final edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData eventData) { - if (eventData.data() instanceof SaveGame save) { + public void handleEvent(final EventData 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 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()); @@ -187,7 +210,6 @@ public void handleEvent(final edu.ntnu.idi.idatt2003.g40.mappe.service.event } } }, EventType.STATE_RESET); - // --------------------------------------------- topBarController.setMarketIntegration( inGameView::changeCenterView, dashBoardView.getRootPane(), marketView.getRootPane(), @@ -231,4 +253,4 @@ public void handleEvent(final edu.ntnu.idi.idatt2003.g40.mappe.service.event stage.show(); } -} \ No newline at end of file +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java index 25402a3..bfeaad4 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/engine/Exchange.java @@ -24,7 +24,8 @@ * *

Delegates buying and selling to player elements using calculators

* - *

Advances week.

+ *

Additionally controls the time in weeks, and therefore has the main + * responsibility for advancing weeks.

* * @see Player * @see edu.ntnu.idi.idatt2003.g40.mappe.service.TransactionCalculator @@ -372,7 +373,7 @@ public List 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. * @@ -398,12 +399,13 @@ public List 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. * *

Used when loading a save game that uses a completely different set of * stocks than the currently active simulation context.

* - * @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 newStocks) throws IllegalArgumentException { diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Player.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Player.java index 1c3cbbd..cf63d80 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Player.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Player.java @@ -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; @@ -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 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 history) { this.netWorthHistory.clear(); diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGame.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGame.java index 74bfaf9..a0f2ec9 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGame.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGame.java @@ -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. * *

* Holds the display name, current balance, starting capital, @@ -49,7 +48,7 @@ public class SaveGame { private final List 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.