Skip to content
Snippets Groups Projects
Commit 152f9cc9 authored by Trym Hamer Gudvangen's avatar Trym Hamer Gudvangen
Browse files

docs: add javadoc to classes without doc

parent 76a17268
Branches
No related tags found
2 merge requests!34Feat/create story gui,!7Feat/part three
Pipeline #230719 passed
Showing
with 187 additions and 10 deletions
...@@ -169,8 +169,8 @@ public enum PathsSingleton { ...@@ -169,8 +169,8 @@ public enum PathsSingleton {
* Returns a list of all the non-null goals. * 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. * @return A list of all the non-null goals, given as a List of Goal objects.
*/ */
public List<Goal> getGoals() { public List<Goal<?>> getGoals() {
List<Goal> goals = Stream List<Goal<?>> goals = Stream
.of(healthGoal, scoreGoal, goldGoal) .of(healthGoal, scoreGoal, goldGoal)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
......
...@@ -21,6 +21,10 @@ public class Controller { ...@@ -21,6 +21,10 @@ public class Controller {
protected final StageManager STAGE_MANAGER = StageManager.getInstance(); protected final StageManager STAGE_MANAGER = StageManager.getInstance();
protected final Map<Class<? extends View<?>>, Runnable> availableViews = new HashMap<>(); 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 @SafeVarargs
public Controller(Class<? extends View<?>>... viewClasses) { public Controller(Class<? extends View<?>>... viewClasses) {
for (Class<? extends View<?>> viewClass : viewClasses) { for (Class<? extends View<?>> viewClass : viewClasses) {
...@@ -53,10 +57,17 @@ public class Controller { ...@@ -53,10 +57,17 @@ public class Controller {
return actionEvent -> STAGE_MANAGER.goBackTo(viewClass); 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() { public Stage getRootStage() {
return STAGE_MANAGER.getStage(); return STAGE_MANAGER.getStage();
} }
/**
* This method is used to go to the home view.
*/
public void goToHome() { public void goToHome() {
STAGE_MANAGER.setCurrentView(ViewFactory.createView(HomeView.class)); STAGE_MANAGER.setCurrentView(ViewFactory.createView(HomeView.class));
} }
......
...@@ -2,8 +2,16 @@ package edu.ntnu.idatt2001.group_30.paths.controller; ...@@ -2,8 +2,16 @@ package edu.ntnu.idatt2001.group_30.paths.controller;
import edu.ntnu.idatt2001.group_30.paths.view.views.LoadGameView; 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 { public class CreatePlayerController extends Controller {
/**
* Creates a new CreatePlayerController.
*/
public CreatePlayerController() { public CreatePlayerController() {
super(LoadGameView.class); super(LoadGameView.class);
} }
......
...@@ -9,6 +9,9 @@ import edu.ntnu.idatt2001.group_30.paths.view.views.HomeView; ...@@ -9,6 +9,9 @@ import edu.ntnu.idatt2001.group_30.paths.view.views.HomeView;
*/ */
public class HelpController extends Controller { public class HelpController extends Controller {
/**
* Creates a new HelpController.
*/
public HelpController() { public HelpController() {
super(HomeView.class); super(HomeView.class);
} }
......
...@@ -8,12 +8,24 @@ import edu.ntnu.idatt2001.group_30.paths.view.views.PlaythroughView; ...@@ -8,12 +8,24 @@ import edu.ntnu.idatt2001.group_30.paths.view.views.PlaythroughView;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
/**
* This class is used to control the NewGameView.
*
* @author Trym Hamer Gudvangen
*/
public class NewGameController extends Controller { public class NewGameController extends Controller {
/**
* Creates a new NewGameController.
*/
public NewGameController() { public NewGameController() {
super(PlaythroughView.class, NewStoryView.class); 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) { public void setStory(File storyFile) {
StoryFileReader storyFileReader = new StoryFileReader(); StoryFileReader storyFileReader = new StoryFileReader();
try { try {
......
...@@ -12,12 +12,26 @@ import java.io.IOException; ...@@ -12,12 +12,26 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
/**
* This class is used to control the NewStoryView.
*
* @author Trym Hamer Gudvangen
*/
public class NewStoryController extends Controller { public class NewStoryController extends Controller {
/**
* Creates a new NewStoryController.
*/
public NewStoryController() { public NewStoryController() {
super(NewStoryView.class); 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 { public void addStory(String title, List<Passage> passages) throws IOException {
Story story = new Story(title, passages.isEmpty() ? null : passages.get(0)); Story story = new Story(title, passages.isEmpty() ? null : passages.get(0));
passages.forEach(story::addPassage); passages.forEach(story::addPassage);
...@@ -26,6 +40,11 @@ public class NewStoryController extends Controller { ...@@ -26,6 +40,11 @@ public class NewStoryController extends Controller {
saveStory(story); 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 { public void saveStory(Story story) throws IOException {
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(new File("./src/main/resources/story-files")); fileChooser.setInitialDirectory(new File("./src/main/resources/story-files"));
......
...@@ -9,7 +9,7 @@ import java.util.List; ...@@ -9,7 +9,7 @@ import java.util.List;
* *
* @author Nicolai H. Brand, Trym Hamer Gudvangen * @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. * This method constructs a Game object with the given parameters.
* *
......
...@@ -18,7 +18,6 @@ public class GoldAction implements Action<Integer> { ...@@ -18,7 +18,6 @@ public class GoldAction implements Action<Integer> {
*/ */
public GoldAction(int gold) { public GoldAction(int gold) {
this.gold = gold; this.gold = gold;
//TODO: Add exception?
} }
/** /**
......
...@@ -18,7 +18,6 @@ public class HealthAction implements Action<Integer> { ...@@ -18,7 +18,6 @@ public class HealthAction implements Action<Integer> {
*/ */
public HealthAction(int health) { public HealthAction(int health) {
this.health = health; this.health = health;
//TODO: Add exception?
} }
/** /**
......
...@@ -18,7 +18,6 @@ public class InventoryAction implements Action<String> { ...@@ -18,7 +18,6 @@ public class InventoryAction implements Action<String> {
*/ */
public InventoryAction(String item) { public InventoryAction(String item) {
this.item = item; this.item = item;
//TODO: Add exception?
} }
/** /**
......
...@@ -18,7 +18,6 @@ public class ScoreAction implements Action<Integer> { ...@@ -18,7 +18,6 @@ public class ScoreAction implements Action<Integer> {
*/ */
public ScoreAction(int points) { public ScoreAction(int points) {
this.points = points; this.points = points;
//TODO: Add exception?
} }
/** /**
......
package edu.ntnu.idatt2001.group_30.paths.model.goals; package edu.ntnu.idatt2001.group_30.paths.model.goals;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* This class is a factory for creating Goal objects.
*
* @author Trym Hamer Gudvangen
*/
public class GoalFactory { 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 { public static Goal<?> getGoal(GoalType goalType, Object goalValue) throws IllegalArgumentException {
switch (goalType) { switch (goalType) {
case GOLD_GOAL, HEALTH_GOAL, SCORE_GOAL -> { case GOLD_GOAL, HEALTH_GOAL, SCORE_GOAL -> {
...@@ -37,6 +48,13 @@ public class GoalFactory { ...@@ -37,6 +48,13 @@ public class GoalFactory {
throw new IllegalArgumentException("Invalid goal type or value"); 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 { public static Goal<?> getGoal(String goalType, Object goalValue) throws IllegalArgumentException {
return getGoal(GoalType.getGoalType(goalType), goalValue); return getGoal(GoalType.getGoalType(goalType), goalValue);
} }
......
...@@ -3,6 +3,11 @@ package edu.ntnu.idatt2001.group_30.paths.model.goals; ...@@ -3,6 +3,11 @@ package edu.ntnu.idatt2001.group_30.paths.model.goals;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* This enum represents the different types of goals.
*
* @author Trym Hamer Gudvangen
*/
public enum GoalType { public enum GoalType {
GOLD_GOAL("GoldGoal"), GOLD_GOAL("GoldGoal"),
HEALTH_GOAL("HealthGoal"), HEALTH_GOAL("HealthGoal"),
...@@ -18,14 +23,27 @@ public enum GoalType { ...@@ -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) { GoalType(String stringVal) {
this.stringVal = 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) { public static GoalType getGoalType(String goalType) {
return stringToEnum.get(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() { public String getStringVal() {
return stringVal; return stringVal;
} }
......
...@@ -18,7 +18,6 @@ public class GoldGoal implements Goal<Integer> { ...@@ -18,7 +18,6 @@ public class GoldGoal implements Goal<Integer> {
*/ */
public GoldGoal(int minimumGold) { public GoldGoal(int minimumGold) {
this.minimumGold = minimumGold; this.minimumGold = minimumGold;
//TODO: Add exception?
} }
/** /**
......
...@@ -18,7 +18,6 @@ public class ScoreGoal implements Goal<Integer> { ...@@ -18,7 +18,6 @@ public class ScoreGoal implements Goal<Integer> {
*/ */
public ScoreGoal(int minimumPoints) { public ScoreGoal(int minimumPoints) {
this.minimumPoints = minimumPoints; this.minimumPoints = minimumPoints;
//TODO: Add exception?
} }
/** /**
......
...@@ -3,12 +3,26 @@ package edu.ntnu.idatt2001.group_30.paths.model.utils; ...@@ -3,12 +3,26 @@ package edu.ntnu.idatt2001.group_30.paths.model.utils;
import javafx.scene.control.TextFormatter; import javafx.scene.control.TextFormatter;
import javafx.util.converter.IntegerStringConverter; import javafx.util.converter.IntegerStringConverter;
/**
* This class represents a text validation.
*
* @author Trym Hamer Gudvangen
*/
public class TextValidation { public class TextValidation {
/**
* This method creates a text formatter for integers.
* @return A text formatter for integers.
*/
public static TextFormatter<Integer> createIntegerTextFormatter() { public static TextFormatter<Integer> createIntegerTextFormatter() {
return createIntegerTextFormatter(100); 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) { public static TextFormatter<Integer> createIntegerTextFormatter(int startValue) {
return new TextFormatter<>( return new TextFormatter<>(
new IntegerStringConverter(), new IntegerStringConverter(),
......
...@@ -18,6 +18,9 @@ public class CreatePlayer extends GridPane { ...@@ -18,6 +18,9 @@ public class CreatePlayer extends GridPane {
private final TextField goldField; private final TextField goldField;
private final ComboBox<String> goalBox; private final ComboBox<String> goalBox;
/**
* Constructor for the CreatePlayer component.
*/
public CreatePlayer() { public CreatePlayer() {
setHgap(10); setHgap(10);
setVgap(5); setVgap(5);
...@@ -38,18 +41,34 @@ public class CreatePlayer extends GridPane { ...@@ -38,18 +41,34 @@ public class CreatePlayer extends GridPane {
add(goalBox, 1, 3); add(goalBox, 1, 3);
} }
/**
* Method for getting the name of the player.
* @return The name of the player, as a String.
*/
public String getName() { public String getName() {
return nameField.getText(); return nameField.getText();
} }
/**
* Method for getting the health of the player.
* @return The health of the player, as an int.
*/
public int getHealth() { public int getHealth() {
return Integer.parseInt(healthField.getText()); 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() { public int getGold() {
return Integer.parseInt(goldField.getText()); 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() { public String getGoal() {
return goalBox.getValue(); return goalBox.getValue();
} }
......
...@@ -9,6 +9,11 @@ import javafx.scene.image.Image; ...@@ -9,6 +9,11 @@ import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
/**
* This class represents a component for displaying a carousel of images.
*
* @author Trym Hamer Gudvangen
*/
public class ImageCarousel { public class ImageCarousel {
private final LinkedList<Image> images = new LinkedList<>(); private final LinkedList<Image> images = new LinkedList<>();
...@@ -18,6 +23,10 @@ public class ImageCarousel { ...@@ -18,6 +23,10 @@ public class ImageCarousel {
private final int WIDTH = 150; private final int WIDTH = 150;
private final int HEIGHT = 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) { public ImageCarousel(List<String> imageNames) {
if (imageNames == null || imageNames.isEmpty()) { if (imageNames == null || imageNames.isEmpty()) {
throw new IllegalArgumentException("Image URI list must not be empty."); throw new IllegalArgumentException("Image URI list must not be empty.");
...@@ -39,6 +48,10 @@ public class ImageCarousel { ...@@ -39,6 +48,10 @@ public class ImageCarousel {
this.currentImage.setImage(images.getFirst()); this.currentImage.setImage(images.getFirst());
} }
/**
* Method for getting the carousel component.
* @return The carousel component, as an HBox.
*/
public HBox getCarousel() { public HBox getCarousel() {
Button leftButton = new Button("<"); Button leftButton = new Button("<");
leftButton.setOnAction(e -> previous()); leftButton.setOnAction(e -> previous());
...@@ -51,20 +64,34 @@ public class ImageCarousel { ...@@ -51,20 +64,34 @@ public class ImageCarousel {
return carousel; return carousel;
} }
/**
* Method for getting the next image.
*/
public void next() { public void next() {
currentIndex = (currentIndex + 1) % size; currentIndex = (currentIndex + 1) % size;
currentImage.setImage(images.get(currentIndex)); currentImage.setImage(images.get(currentIndex));
} }
/**
* Method for getting the previous image.
*/
public void previous() { public void previous() {
currentIndex = (currentIndex - 1 + size) % size; currentIndex = (currentIndex - 1 + size) % size;
currentImage.setImage(images.get(currentIndex)); 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() { public int size() {
return size; return size;
} }
/**
* Method for getting the current image.
* @return The current image, as an ImageView.
*/
public ImageView getCurrentImage() { public ImageView getCurrentImage() {
return currentImage; return currentImage;
} }
......
package edu.ntnu.idatt2001.group_30.paths.view.components.pop_up; 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 { public abstract class AbstractPopUp {
/**
* This method initializes the pop-up by setting up the UI components and the behavior.
*/
protected void initialize() { protected void initialize() {
setupUiComponents(); setupUiComponents();
setupBehavior(); setupBehavior();
} }
/**
* This method sets up the UI components of the pop-up.
*/
protected abstract void setupUiComponents(); protected abstract void setupUiComponents();
/**
* This method sets up the behavior of the pop-up.
*/
protected abstract void setupBehavior(); protected abstract void setupBehavior();
/**
* This method creates the pop-up.
*/
protected abstract void createPopUp(); protected abstract void createPopUp();
} }
...@@ -16,6 +16,11 @@ import javafx.scene.image.ImageView; ...@@ -16,6 +16,11 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; 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 { public class GoalsPopUp extends AbstractPopUp {
private TextField healthField; private TextField healthField;
...@@ -31,11 +36,17 @@ public class GoalsPopUp extends AbstractPopUp { ...@@ -31,11 +36,17 @@ public class GoalsPopUp extends AbstractPopUp {
private ScrollPane scrollPane; private ScrollPane scrollPane;
private PopUp<ScrollPane, ?> popUp; private PopUp<ScrollPane, ?> popUp;
/**
* This constructor creates a new GoalsPopUp.
*/
public GoalsPopUp() { public GoalsPopUp() {
initialize(); initialize();
createPopUp(); createPopUp();
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected void setupUiComponents() { protected void setupUiComponents() {
healthField = new TextField(); healthField = new TextField();
...@@ -122,6 +133,9 @@ public class GoalsPopUp extends AbstractPopUp { ...@@ -122,6 +133,9 @@ public class GoalsPopUp extends AbstractPopUp {
scrollPane.setFitToWidth(true); scrollPane.setFitToWidth(true);
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected void setupBehavior() { protected void setupBehavior() {
addButton.setOnAction(e -> { addButton.setOnAction(e -> {
...@@ -152,6 +166,9 @@ public class GoalsPopUp extends AbstractPopUp { ...@@ -152,6 +166,9 @@ public class GoalsPopUp extends AbstractPopUp {
}); });
} }
/**
* {@inheritDoc}
*/
@Override @Override
protected void createPopUp() { protected void createPopUp() {
popUp = popUp =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment