diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java index 55b7fb4ba905505741b875ecda09bb2276d4b115..9946f5eb6901098847ad10f86195f520b032559c 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/PathsSingleton.java @@ -169,8 +169,8 @@ public enum PathsSingleton { * Returns a list of all the non-null goals. * @return A list of all the non-null goals, given as a List of Goal objects. */ - public List<Goal> getGoals() { - List<Goal> goals = Stream + public List<Goal<?>> getGoals() { + List<Goal<?>> goals = Stream .of(healthGoal, scoreGoal, goldGoal) .filter(Objects::nonNull) .collect(Collectors.toList()); diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/Controller.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/Controller.java index 4a62d0acd5453a9fbbda8ba8aa3494761a393c77..7ea189bd035cc0f2fbf24cb3cc0f00c9598b8957 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/Controller.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/Controller.java @@ -21,6 +21,10 @@ public class Controller { protected final StageManager STAGE_MANAGER = StageManager.getInstance(); protected final Map<Class<? extends View<?>>, Runnable> availableViews = new HashMap<>(); + /** + * Creates a new Controller with the given view classes. + * @param viewClasses The view classes that this controller is responsible for. + */ @SafeVarargs public Controller(Class<? extends View<?>>... viewClasses) { for (Class<? extends View<?>> viewClass : viewClasses) { @@ -53,10 +57,17 @@ public class Controller { return actionEvent -> STAGE_MANAGER.goBackTo(viewClass); } + /** + * This method is used to get the root stage of the application. + * @return The root stage of the application, which is the stage that is used to display the views. + */ public Stage getRootStage() { return STAGE_MANAGER.getStage(); } + /** + * This method is used to go to the home view. + */ public void goToHome() { STAGE_MANAGER.setCurrentView(ViewFactory.createView(HomeView.class)); } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/CreatePlayerController.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/CreatePlayerController.java index 8515eca9ec84886300f56842c17ad0e0768d209e..e197403d78fe5133cf606840d8e82b49f0d910b2 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/CreatePlayerController.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/CreatePlayerController.java @@ -2,8 +2,16 @@ package edu.ntnu.idatt2001.group_30.paths.controller; import edu.ntnu.idatt2001.group_30.paths.view.views.LoadGameView; +/** + * The class CreatePlayerController is responsible for managing the CreatePlayerView. + * + * @author Trym Hamer Gudvangen + */ public class CreatePlayerController extends Controller { + /** + * Creates a new CreatePlayerController. + */ public CreatePlayerController() { super(LoadGameView.class); } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/HelpController.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/HelpController.java index 71d54a3c1d9e2db538ed3100a82b83a00b10278d..e2019fdca619ac953be249ef30894d5c21a025f1 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/HelpController.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/HelpController.java @@ -9,6 +9,9 @@ import edu.ntnu.idatt2001.group_30.paths.view.views.HomeView; */ public class HelpController extends Controller { + /** + * Creates a new HelpController. + */ public HelpController() { super(HomeView.class); } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java index f9e49bc5dcc03c2eb2fedb6d120878ef1df87a5e..7df50729abee2e0e5a6c06f3e6cb6ae0be566104 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewGameController.java @@ -8,12 +8,24 @@ import edu.ntnu.idatt2001.group_30.paths.view.views.PlaythroughView; import java.io.File; import java.io.IOException; +/** + * This class is used to control the NewGameView. + * + * @author Trym Hamer Gudvangen + */ public class NewGameController extends Controller { + /** + * Creates a new NewGameController. + */ public NewGameController() { super(PlaythroughView.class, NewStoryView.class); } + /** + * Sets the story to the storyFile. + * @param storyFile The story to set, as a File. + */ public void setStory(File storyFile) { StoryFileReader storyFileReader = new StoryFileReader(); try { diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewStoryController.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewStoryController.java index 762f9b5841f653e88c86712103a51bbbfa3106de..6a646143eafc077e06fdb225f1a0047a4ac98e63 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewStoryController.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/controller/NewStoryController.java @@ -12,12 +12,26 @@ import java.io.IOException; import java.util.List; import javafx.stage.FileChooser; +/** + * This class is used to control the NewStoryView. + * + * @author Trym Hamer Gudvangen + */ public class NewStoryController extends Controller { + /** + * Creates a new NewStoryController. + */ public NewStoryController() { super(NewStoryView.class); } + /** + * Adds a story to the PathsSingleton. + * @param title The title of the story, as a String. + * @param passages The passages of the story, as a List of Passages. + * @throws IOException If the story could not be saved to file system. + */ public void addStory(String title, List<Passage> passages) throws IOException { Story story = new Story(title, passages.isEmpty() ? null : passages.get(0)); passages.forEach(story::addPassage); @@ -26,6 +40,11 @@ public class NewStoryController extends Controller { saveStory(story); } + /** + * This method saves the story to the file system. + * @param story The story to save, as a Story. + * @throws IOException If the story could not be saved to file system. + */ public void saveStory(Story story) throws IOException { FileChooser fileChooser = new FileChooser(); fileChooser.setInitialDirectory(new File("./src/main/resources/story-files")); diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Game.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Game.java index 287a0131c96daa0f057331ac88f3a9fb7d484b40..f1399d8c02934cadba13d12ba55b69ad7d3d60ac 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Game.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/Game.java @@ -9,7 +9,7 @@ import java.util.List; * * @author Nicolai H. Brand, Trym Hamer Gudvangen */ -public record Game(Player player, Story story, List<Goal> goals) { +public record Game(Player player, Story story, List<Goal<?>> goals) { /** * This method constructs a Game object with the given parameters. * diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/GoldAction.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/GoldAction.java index 1101d8c660bbc86d1207c26adcc070c35d6a35af..f479b4826f43348845ddf5d583ff51b87cd76763 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/GoldAction.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/GoldAction.java @@ -18,7 +18,6 @@ public class GoldAction implements Action<Integer> { */ public GoldAction(int gold) { this.gold = gold; - //TODO: Add exception? } /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/HealthAction.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/HealthAction.java index bf588fe6767b34ffe4dc4f26c41238032ef579b5..55a4afd0def466b0947c3ba49f16881a21dbbdfa 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/HealthAction.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/HealthAction.java @@ -18,7 +18,6 @@ public class HealthAction implements Action<Integer> { */ public HealthAction(int health) { this.health = health; - //TODO: Add exception? } /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/InventoryAction.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/InventoryAction.java index a8b5939b85a62fb5fce85ab0ad6a1ed7827b177f..040768f0cd0e2e59ba83e4564cd45fed6c6f6901 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/InventoryAction.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/InventoryAction.java @@ -18,7 +18,6 @@ public class InventoryAction implements Action<String> { */ public InventoryAction(String item) { this.item = item; - //TODO: Add exception? } /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/ScoreAction.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/ScoreAction.java index bf20494e9decc5c7910fe1d5842d0f0b8f3dd4c9..9c09207642e0b830dd1a90578c38a7aff1e2bd21 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/ScoreAction.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/actions/ScoreAction.java @@ -18,7 +18,6 @@ public class ScoreAction implements Action<Integer> { */ public ScoreAction(int points) { this.points = points; - //TODO: Add exception? } /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalFactory.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalFactory.java index d18f5aca79e7d6cc095031c106cc2aa6757bc99e..92cd32b22b19d5de62826f245e7b56bce350ef0d 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalFactory.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalFactory.java @@ -1,12 +1,23 @@ package edu.ntnu.idatt2001.group_30.paths.model.goals; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +/** + * This class is a factory for creating Goal objects. + * + * @author Trym Hamer Gudvangen + */ public class GoalFactory { + /** + * This method creates a Goal object based on the given goal type and goal value. + * @param goalType The type of goal, given as a GoalType object. + * @param goalValue The value of the goal, given as an Object. + * @return A Goal object. + * @throws IllegalArgumentException If the goal type or value is invalid. + */ public static Goal<?> getGoal(GoalType goalType, Object goalValue) throws IllegalArgumentException { switch (goalType) { case GOLD_GOAL, HEALTH_GOAL, SCORE_GOAL -> { @@ -37,6 +48,13 @@ public class GoalFactory { throw new IllegalArgumentException("Invalid goal type or value"); } + /** + * This method creates a Goal object based on the given goal type and goal value. + * @param goalType The type of goal, given as a String. + * @param goalValue The value of the goal, given as an Object. + * @return A Goal object. + * @throws IllegalArgumentException If the goal type or value is invalid. + */ public static Goal<?> getGoal(String goalType, Object goalValue) throws IllegalArgumentException { return getGoal(GoalType.getGoalType(goalType), goalValue); } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalType.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalType.java index b164bc07972740fa0a901c84fde99c1f568a7fb9..0d369287e785abccae76c20a16577372f6afc9c8 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalType.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoalType.java @@ -3,6 +3,11 @@ package edu.ntnu.idatt2001.group_30.paths.model.goals; import java.util.HashMap; import java.util.Map; +/** + * This enum represents the different types of goals. + * + * @author Trym Hamer Gudvangen + */ public enum GoalType { GOLD_GOAL("GoldGoal"), HEALTH_GOAL("HealthGoal"), @@ -18,14 +23,27 @@ public enum GoalType { } } + /** + * This constructor creates a GoalType object based on the given string value. + * @param stringVal The string value of the GoalType object. + */ GoalType(String stringVal) { this.stringVal = stringVal; } + /** + * This method retrieves the GoalType object based on the given string value. + * @param goalType The string value of the GoalType object. + * @return The GoalType object. + */ public static GoalType getGoalType(String goalType) { return stringToEnum.get(goalType); } + /** + * This method retrieves the string value of the GoalType object. + * @return The string value of the GoalType object. + */ public String getStringVal() { return stringVal; } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoldGoal.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoldGoal.java index 2f51d2165a9119654d5222d1ffaf3726e37f5abf..79ebf1121f6a17db6510b49bf46567444614298f 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoldGoal.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/GoldGoal.java @@ -18,7 +18,6 @@ public class GoldGoal implements Goal<Integer> { */ public GoldGoal(int minimumGold) { this.minimumGold = minimumGold; - //TODO: Add exception? } /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/ScoreGoal.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/ScoreGoal.java index def6210020b1873a56698fab33ed53fde778fb77..a0d688e1a83839e47d140a9cf9fdeba326abb315 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/ScoreGoal.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/goals/ScoreGoal.java @@ -18,7 +18,6 @@ public class ScoreGoal implements Goal<Integer> { */ public ScoreGoal(int minimumPoints) { this.minimumPoints = minimumPoints; - //TODO: Add exception? } /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/utils/TextValidation.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/utils/TextValidation.java index 57610f010601a59de1a2a514bc3cc0e1fbad11e3..edfd723757903064ad2f91e31b1a8a0799b8ec70 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/utils/TextValidation.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/model/utils/TextValidation.java @@ -3,12 +3,26 @@ package edu.ntnu.idatt2001.group_30.paths.model.utils; import javafx.scene.control.TextFormatter; import javafx.util.converter.IntegerStringConverter; +/** + * This class represents a text validation. + * + * @author Trym Hamer Gudvangen + */ public class TextValidation { + /** + * This method creates a text formatter for integers. + * @return A text formatter for integers. + */ public static TextFormatter<Integer> createIntegerTextFormatter() { return createIntegerTextFormatter(100); } + /** + * This method creates a text formatter for integers. + * @param startValue The start value of the text formatter, given as an integer. + * @return A text formatter for integers. + */ public static TextFormatter<Integer> createIntegerTextFormatter(int startValue) { return new TextFormatter<>( new IntegerStringConverter(), diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/CreatePlayer.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/CreatePlayer.java index bc00aca590e12118c59f808f3e0e7bac31c6598f..004702c843a858ab8e3fa8116170b0569e8ce169 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/CreatePlayer.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/CreatePlayer.java @@ -18,6 +18,9 @@ public class CreatePlayer extends GridPane { private final TextField goldField; private final ComboBox<String> goalBox; + /** + * Constructor for the CreatePlayer component. + */ public CreatePlayer() { setHgap(10); setVgap(5); @@ -38,18 +41,34 @@ public class CreatePlayer extends GridPane { add(goalBox, 1, 3); } + /** + * Method for getting the name of the player. + * @return The name of the player, as a String. + */ public String getName() { return nameField.getText(); } + /** + * Method for getting the health of the player. + * @return The health of the player, as an int. + */ public int getHealth() { return Integer.parseInt(healthField.getText()); } + /** + * Method for getting the gold of the player. + * @return The gold of the player, as an int. + */ public int getGold() { return Integer.parseInt(goldField.getText()); } + /** + * Method for getting the goal of the player. + * @return The goal of the player, as a String. + */ public String getGoal() { return goalBox.getValue(); } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/ImageCarousel.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/ImageCarousel.java index 7858c3660988b7b2c5fc96b46d8ce4d473f7e1fe..a95573f21a490516385765e79f952d6f1154b2f9 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/ImageCarousel.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/ImageCarousel.java @@ -9,6 +9,11 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; +/** + * This class represents a component for displaying a carousel of images. + * + * @author Trym Hamer Gudvangen + */ public class ImageCarousel { private final LinkedList<Image> images = new LinkedList<>(); @@ -18,6 +23,10 @@ public class ImageCarousel { private final int WIDTH = 150; private final int HEIGHT = 150; + /** + * Constructor for the ImageCarousel component. + * @param imageNames A list of image names, as Strings. + */ public ImageCarousel(List<String> imageNames) { if (imageNames == null || imageNames.isEmpty()) { throw new IllegalArgumentException("Image URI list must not be empty."); @@ -39,6 +48,10 @@ public class ImageCarousel { this.currentImage.setImage(images.getFirst()); } + /** + * Method for getting the carousel component. + * @return The carousel component, as an HBox. + */ public HBox getCarousel() { Button leftButton = new Button("<"); leftButton.setOnAction(e -> previous()); @@ -51,20 +64,34 @@ public class ImageCarousel { return carousel; } + /** + * Method for getting the next image. + */ public void next() { currentIndex = (currentIndex + 1) % size; currentImage.setImage(images.get(currentIndex)); } + /** + * Method for getting the previous image. + */ public void previous() { currentIndex = (currentIndex - 1 + size) % size; currentImage.setImage(images.get(currentIndex)); } + /** + * Method for getting the size of the list of images. + * @return The size of the list of images, as an int. + */ public int size() { return size; } + /** + * Method for getting the current image. + * @return The current image, as an ImageView. + */ public ImageView getCurrentImage() { return currentImage; } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java index c4a13e4efc61bbd6be6a9da00aae2c31d61bc2e0..35fa07f2d7b7444bbcb12bba3eb96c8004d17b1e 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/AbstractPopUp.java @@ -1,15 +1,32 @@ package edu.ntnu.idatt2001.group_30.paths.view.components.pop_up; +/** + * This class provides a template for creating pop-ups. + * + * @author Trym Hamer Gudvangen + */ public abstract class AbstractPopUp { + /** + * This method initializes the pop-up by setting up the UI components and the behavior. + */ protected void initialize() { setupUiComponents(); setupBehavior(); } + /** + * This method sets up the UI components of the pop-up. + */ protected abstract void setupUiComponents(); + /** + * This method sets up the behavior of the pop-up. + */ protected abstract void setupBehavior(); + /** + * This method creates the pop-up. + */ protected abstract void createPopUp(); } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java index 2a27394fb5c090c36f46de6b78bc368df129fbd0..71e19b86a45896a37c987674488faaadb51b28ef 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/GoalsPopUp.java @@ -16,6 +16,11 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +/** + * This class contains a pop-up for creating and editing goals. + * + * @author Trym Hamer Gudvangen + */ public class GoalsPopUp extends AbstractPopUp { private TextField healthField; @@ -31,11 +36,17 @@ public class GoalsPopUp extends AbstractPopUp { private ScrollPane scrollPane; private PopUp<ScrollPane, ?> popUp; + /** + * This constructor creates a new GoalsPopUp. + */ public GoalsPopUp() { initialize(); createPopUp(); } + /** + * {@inheritDoc} + */ @Override protected void setupUiComponents() { healthField = new TextField(); @@ -122,6 +133,9 @@ public class GoalsPopUp extends AbstractPopUp { scrollPane.setFitToWidth(true); } + /** + * {@inheritDoc} + */ @Override protected void setupBehavior() { addButton.setOnAction(e -> { @@ -152,6 +166,9 @@ public class GoalsPopUp extends AbstractPopUp { }); } + /** + * {@inheritDoc} + */ @Override protected void createPopUp() { popUp = diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java index 43fdb67e0290ba9ce22aa0a07ea222a8d5c61cf1..54bd0ee6d0f05d650d73ff237281e3cbbda0e58d 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/LinkPopUp.java @@ -16,6 +16,11 @@ import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +/** + * This class is a pop-up for creating a new link or editing an existing one. + * + * @author Trym Hamer Gudvangen + */ public class LinkPopUp extends AbstractPopUp { private TextField textField; @@ -33,6 +38,10 @@ public class LinkPopUp extends AbstractPopUp { private Link link; private PopUp<VBox, ?> popUp; + /** + * This constructor allows a new link to be created. + * @param passages Other passages in the story, given as an ObservableList of passages. + */ public LinkPopUp(ObservableList<Passage> passages) { this.actions = FXCollections.observableArrayList(); this.passages = passages; @@ -43,6 +52,11 @@ public class LinkPopUp extends AbstractPopUp { createPopUp(); } + /** + * This constructor allows a pre-existing link to be edited. + * @param passages Other passages in the story, given as an ObservableList of passages. + * @param link The link to be edited, given as a Link object. + */ public LinkPopUp(ObservableList<Passage> passages, Link link) { this.link = link; this.actions = FXCollections.observableArrayList(link.getActions()); @@ -55,6 +69,9 @@ public class LinkPopUp extends AbstractPopUp { createPopUp(); } + /** + * This method loads the link to be edited into the pop-up. + */ @Override protected void setupUiComponents() { textField = new TextField(); @@ -108,6 +125,9 @@ public class LinkPopUp extends AbstractPopUp { content.setSpacing(20); } + /** + * This method sets up the behavior of the Ui components. + */ @Override protected void setupBehavior() { removeActionButton.setOnAction(event -> actions.remove(actionTable.getSelectionModel().getSelectedItem())); @@ -159,6 +179,9 @@ public class LinkPopUp extends AbstractPopUp { actionComboBox.setButtonCell(actionComboBox.getCellFactory().call(null)); } + /** + * This method creates the pop-up. + */ @Override protected void createPopUp() { popUp = @@ -172,6 +195,9 @@ public class LinkPopUp extends AbstractPopUp { popUp.showAndWait(); } + /** + * This method loads the link to be edited into the pop-up. + */ private void loadLink() { textField.setText(this.link.getText()); reference.setValue(this.link.getReference()); diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java index 3ada0e59ee26ed9ed3b3d0120781ec5426a1b9b5..3b25186dcc066391c7d7de2ac6678e971d28efbe 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PassagePopUp.java @@ -31,6 +31,10 @@ public class PassagePopUp extends AbstractPopUp { private Passage passage; private PopUp<VBox, ?> popUp; + /** + * This constructor allows a new passage to be created. + * @param passages Other passages in the story, given as an ObservableList of passages. + */ public PassagePopUp(ObservableList<Passage> passages) { this.passages = passages; this.links = FXCollections.observableArrayList(); @@ -52,6 +56,9 @@ public class PassagePopUp extends AbstractPopUp { createPopUp(); } + /** + * This method sets up the UI components for the pop-up. + */ @Override protected void setupUiComponents() { titleField = new TextField(); @@ -99,6 +106,9 @@ public class PassagePopUp extends AbstractPopUp { content.setSpacing(20); } + /** + * This method sets up the behavior for the pop-up. + */ @Override protected void setupBehavior() { editLinkButton.setOnAction(e -> { @@ -142,6 +152,9 @@ public class PassagePopUp extends AbstractPopUp { }); } + /** + * {@inheritDoc} + */ @Override protected void createPopUp() { popUp = @@ -155,6 +168,10 @@ public class PassagePopUp extends AbstractPopUp { popUp.showAndWait(); } + /** + * This method loads a passage into the pop-up. + * @param passage Passage to load, given as a Passage object. + */ private void loadPassage(Passage passage) { titleField.setText(passage.getTitle()); contentArea.setText(passage.getContent()); diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PopUp.java index 7b38f065463c9e8b0261fcbe23728c39c34cfd7d..9fff0bfd999acf0d5a905339dcb4daf1a60c1473 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/PopUp.java @@ -3,15 +3,28 @@ package edu.ntnu.idatt2001.group_30.paths.view.components.pop_up; import javafx.scene.control.*; import javafx.scene.layout.Region; +/** + * This class provides a template for creating pop-ups. + * @param <T> The type of the content of the pop-up. + * @param <SELF> The type of the pop-up. + */ public class PopUp<T extends Region, SELF extends PopUp<T, SELF>> extends Dialog<Void> { private final DialogPane dialogPane; + /** + * This constructor sets up the dialog pane. + */ protected PopUp() { dialogPane = new DialogPane(); setDialogPane(dialogPane); } + /** + * This method creates a pop-up. + * @return The pop-up. + * @param <T> The type of the content of the pop-up. + */ public static <T extends Region> PopUp<T, ?> create() { return new PopUp<>(); } @@ -21,16 +34,30 @@ public class PopUp<T extends Region, SELF extends PopUp<T, SELF>> extends Dialog return self(); } + /** + * This method returns the dialog pane. + * @param content The content of the dialog pane. + * @return The dialog pane. + */ public SELF withContent(T content) { dialogPane.setContent(content); return self(); } + /** + * This method returns the dialog pane. + * @param buttonType The button type of the dialog pane. + * @return The dialog pane. + */ public SELF withButton(ButtonType buttonType) { dialogPane.getButtonTypes().add(buttonType); return self(); } + /** + * This method returns the dialog pane. + * @return The dialog pane. + */ public SELF withoutCloseButton() { // Add a close button type to the dialog ButtonType closeButtonType = new ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE); @@ -44,12 +71,22 @@ public class PopUp<T extends Region, SELF extends PopUp<T, SELF>> extends Dialog return self(); } + /** + * This method returns the dialog pane. + * @param width The width of the dialog pane. + * @param height The height of the dialog pane. + * @return The dialog pane. + */ public SELF withDialogSize(double width, double height) { getDialogPane().setMinSize(width, height); getDialogPane().setMaxSize(width, height); return self(); } + /** + * This method returns the dialog pane. + * @return The dialog pane. + */ @SuppressWarnings("unchecked") protected SELF self() { return (SELF) this; diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java index 4818eeb2395f6c8687cf03738e21bd98528fd87c..5e6ba2692d8d81b5937c13fac36729ab07d5ff52 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/pop_up/StatsPopUp.java @@ -9,6 +9,11 @@ import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; +/** + * This class contains a pop-up for adding stats to the player. + * + * @author Trym Hamer Gudvangen + */ public class StatsPopUp extends AbstractPopUp { private TextField healthField; @@ -17,19 +22,33 @@ public class StatsPopUp extends AbstractPopUp { private VBox content; private PopUp<VBox, ?> popUp; + /** + * This constructor creates a new StatsPopUp. + */ public StatsPopUp() { initialize(); createPopUp(); } + /** + * This method retrieves the health value from the pop-up. + * @return The health value, as an int. + */ public int getHealth() { return Integer.parseInt(healthField.getText()); } + /** + * This method retrieves the gold value from the pop-up. + * @return The gold value, as an int. + */ public int getGold() { return Integer.parseInt(goldField.getText()); } + /** + * {@inheritDoc} + */ @Override protected void setupUiComponents() { healthField = new TextField(); @@ -48,6 +67,9 @@ public class StatsPopUp extends AbstractPopUp { content.setSpacing(20); } + /** + * {@inheritDoc} + */ @Override protected void setupBehavior() { saveButton.setOnAction(e -> { @@ -61,6 +83,9 @@ public class StatsPopUp extends AbstractPopUp { }); } + /** + * {@inheritDoc} + */ @Override protected void createPopUp() { popUp = diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/StatsTable.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/StatsTable.java index a0fec2282aa03daa29e5e0eeb6a1aab3ade3f70f..e639b45d7b44b74cc947efa52a7400eacce32c61 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/StatsTable.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/components/table/StatsTable.java @@ -1,5 +1,9 @@ package edu.ntnu.idatt2001.group_30.paths.view.components.table; +/** + * This class concerns itself with the aspects intrinsic to a stats table. + * @param <Player> The type of the table, represented using a Player object. + */ public class StatsTable<Player> extends TableDisplay<Player> { /** diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java index 96c9d4189ffef8bb1376793f1678e3aea190e344..30947754877071704ec83cfa210b0d0ff006d75e 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/CreatePlayerView.java @@ -24,12 +24,21 @@ import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; +/** + * The view for creating a player. This view therefore contains the character layout implementation and pop-ups + * for goals and stats. + * + * @author Trym Hamer Gudvangen + */ public class CreatePlayerView extends View<BorderPane> { private final CreatePlayerController createPlayerController; private TextField nameField; private Button continueButton, returnButton; + /** + * Creates the view for creating a player. + */ public CreatePlayerView() { super(BorderPane.class); createPlayerController = new CreatePlayerController(); @@ -166,6 +175,12 @@ public class CreatePlayerView extends View<BorderPane> { returnButton.setOnAction(e -> StageManager.getInstance().goBack()); } + /** + * Copies the image onto the writable image. + * @param image the image to copy + * @param writer the pixel writer + * @param yOffset the y offset + */ private void copyImageOnto(Image image, PixelWriter writer, int yOffset) { PixelReader reader = image.getPixelReader(); for (int y = 0; y < image.getHeight(); y++) { diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/HelpView.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/HelpView.java index 715e930126add6ef7e7fc5dcaa394da14d1c6c0c..d4df12b733ef8de4db37e94681b0556c644d8bbb 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/HelpView.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/HelpView.java @@ -22,6 +22,9 @@ public class HelpView extends View<VBox> { private final HelpController controller = new HelpController(); + /** + * Creates the help page. + */ public HelpView() { super(VBox.class); VBox parent = getParentPane(); diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java index 14ed35eb46cdd99769e274b17e7d239fdff41f9a..a4c2f3ba84ab8c86488377534a1f5b08cfdf3948 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/LoadGameView.java @@ -59,6 +59,11 @@ public class LoadGameView extends View<BorderPane> { setupParentPane(mainContainer); } + /** + * Adds the story pane to the view. + * @param titlePane The title pane of the view. + * @return The main container of the view. + */ private VBox createMainContainerVBox(BorderPane titlePane) { VBox mainContainer = new VBox(); mainContainer.getChildren().addAll(titlePane); @@ -79,6 +84,10 @@ public class LoadGameView extends View<BorderPane> { return containerWithButtons; } + /** + * Sets up the parent pane of the view. + * @param mainContainer The main container of the view. + */ private void setupParentPane(VBox mainContainer) { getParentPane().setCenter(mainContainer); getParentPane().setStyle("-fx-background-color: #f5f5f5"); @@ -89,6 +98,10 @@ public class LoadGameView extends View<BorderPane> { getParentPane().setPadding(new Insets(20)); } + /** + * Adds the story pane to the view. + * @return The story pane. + */ private BorderPane createTitlePane() { BorderPane titlePane = new BorderPane(); titlePane.setPadding(new Insets(20)); @@ -135,6 +148,13 @@ public class LoadGameView extends View<BorderPane> { return titlePane; } + /** + * Creates an icon button. + * @param imagePath The path to the image. + * @param width The width of the image. + * @param height The height of the image. + * @return The button. + */ private Button createIconButton(String imagePath, int width, int height) { Button button = new Button(); URL imageUrl = getClass().getResource(imagePath); @@ -149,6 +169,10 @@ public class LoadGameView extends View<BorderPane> { return button; } + /** + * Adds the story pane to the view. + * @throws IOException If the story pane cannot be added. + */ private void addStoryPane() throws IOException { VBox storyVBox = new StoryDisplay.Builder(INSTANCE.getStory()) .addStoryName() diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/NewStoryView.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/NewStoryView.java index d4a2e43cd7c7ff89a16ca183a86a1dc8be067af8..eedaa1d4d4c259148d1d926a775dab26a37dae03 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/NewStoryView.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/NewStoryView.java @@ -28,6 +28,12 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Text; +/** + * This class contains the view for creating/writing a new story. It, therefore, contains the title and passages. + * The passages can be changed and the corresponding object variables such as links and actions can also be changed. + * + * @author Trym Hamer Gudvangen + */ public class NewStoryView extends View<BorderPane> { private final NewStoryController newStoryController; @@ -37,6 +43,9 @@ public class NewStoryView extends View<BorderPane> { private final Button removePassageButton; private final Button editPassageButton; + /** + * The constructor to create the NewStoryView. + */ public NewStoryView() { super(BorderPane.class); newStoryController = new NewStoryController(); diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/View.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/View.java index 0ba45db74582e52ac25b7b09f433cb7dc6d7e523..e549e73a5ab571aae955301d855b93469f3804ab 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/View.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/View.java @@ -7,7 +7,6 @@ import java.util.Objects; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.layout.*; -import javafx.scene.shape.SVGPath; /** * A View is a wrapper for a JavaFX Pane. @@ -40,7 +39,6 @@ public class View<T extends Pane> { } catch ( InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e ) { - //TODO: better error handling e.printStackTrace(); } } diff --git a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/ViewFactory.java b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/ViewFactory.java index ce9cabadbe943f5063446ede9b28fa1894fc4ae0..9674ac5f1536e3f4d80b3f4cfe498d80661cb24b 100644 --- a/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/ViewFactory.java +++ b/src/main/java/edu/ntnu/idatt2001/group_30/paths/view/views/ViewFactory.java @@ -2,8 +2,17 @@ package edu.ntnu.idatt2001.group_30.paths.view.views; import java.lang.reflect.InvocationTargetException; +/** + * A factory for creating views. + */ public class ViewFactory { + /** + * Given a class of a view, this method creates an instance of that view. + * @param viewClass The class of the view to be created. + * @return An instance of the view. + * @param <T> The type of the view. + */ public static <T extends View<?>> T createView(Class<T> viewClass) { try { return viewClass.getDeclaredConstructor().newInstance(); diff --git a/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/GameTest.java b/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/GameTest.java index 7c6cdd07e3a182b89bc5350d3fa10daf6c039b82..093517875e56dcadcc3b7817896dc990b3209219 100644 --- a/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/GameTest.java +++ b/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/GameTest.java @@ -22,7 +22,7 @@ public class GameTest { Passage attackPassage; Story story; - List<Goal> goals; + List<Goal<?>> goals; @BeforeEach void setup() { diff --git a/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/PlaythroughTest.java b/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/PlaythroughTest.java index fd49df0b77d10fee055a9072165ac5806dd63a88..d90ddb67c9bdb85ec0620905778dfc576218d61b 100644 --- a/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/PlaythroughTest.java +++ b/src/test/java/edu/ntnu/idatt2001/group_30/paths/model/PlaythroughTest.java @@ -18,7 +18,7 @@ class PlaythroughTest { openingPassage = new Passage("Opening passage", "This is the opening passage"); Player player = new Player("Player", 10, 20, 30); Story story = new Story("My story", openingPassage); - List<Goal> goals = List.of(new GoldGoal(50)); + List<Goal<?>> goals = List.of(new GoldGoal(50)); Game game = new Game(player, story, goals); playthrough = new Playthrough(game);