Class LadderGameBoardCreatorController

java.lang.Object
edu.ntnu.idi.idatt.controller.common.BoardCreatorController
edu.ntnu.idi.idatt.controller.laddergame.LadderGameBoardCreatorController
All Implemented Interfaces:
ButtonClickObserver

public class LadderGameBoardCreatorController extends BoardCreatorController
LadderGameBoardCreatorController.

Controller responsible for the logic behind creating and editing LadderGameBoards. It extends BoardCreatorController and manages interactions with a LadderGameBoardCreatorView.

This controller handles tasks such as initializing the board with default or imported values, managing available components (ladders, slides, portals) and backgrounds, processing component placement and removal, updating the grid based on user input (rows, columns, pattern), and saving/importing board configurations.

See Also:
  • Constructor Details

  • Method Details

    • initializeBoard

      protected void initializeBoard()
      Initializes the BoardCreatorController.board instance as a new, blank LadderGameBoard using a LadderBoardFactory with default dimensions.
      Specified by:
      initializeBoard in class BoardCreatorController
    • initializeBoardCreatorView

      protected void initializeBoardCreatorView()
      Initializes the LadderGameBoardCreatorView. Sets this controller as an observer to the view, initializes the view with available components and the current board, and sets up event handlers for component drops and removal.
      Specified by:
      initializeBoardCreatorView in class BoardCreatorController
    • removeComponentsOutsideGrid

      public void removeComponentsOutsideGrid()
      Removes components from the board model and view if their origin or calculated destination falls outside the current grid boundaries (e.g., after grid dimensions are changed). It recalculates destinations for remaining valid components.
    • handleUpdateGrid

      protected void handleUpdateGrid()
      Handles the action to update the board's grid dimensions (rows and columns) based on values from the view's spinners. Updates the board model and refreshes the grid display.
      Specified by:
      handleUpdateGrid in class BoardCreatorController
    • handleImportBoard

      protected void handleImportBoard(Map<String,Object> params)
      Handles the import of a board configuration from a file. Updates the internal BoardCreatorController.board model and refreshes the view's input fields (name, description, rows, columns, background, pattern) and the board display.
      Specified by:
      handleImportBoard in class BoardCreatorController
      Parameters:
      params - A map containing the "path" (String) to the board file.
    • handleSaveBoard

      protected void handleSaveBoard(Map<String,Object> params)
      Handles saving the current board configuration to a file. Updates the board model with values from the view's input fields before saving. Uses LadderGameBoardFileHandlerGson for serialization.
      Specified by:
      handleSaveBoard in class BoardCreatorController
      Parameters:
      params - A map containing the "path" (String) to save the file to.
    • onButtonClicked

      public void onButtonClicked(String buttonId)
      Handles button click events from the LadderGameBoardCreatorView. Delegates actions based on the button ID (e.g., back to menu, update grid, update background, update pattern).
      Specified by:
      onButtonClicked in interface ButtonClickObserver
      Overrides:
      onButtonClicked in class BoardCreatorController
      Parameters:
      buttonId - The ID of the button that was clicked.