Class LadderGameBoardCreatorController
java.lang.Object
edu.ntnu.idi.idatt.controller.common.BoardCreatorController
edu.ntnu.idi.idatt.controller.laddergame.LadderGameBoardCreatorController
- All Implemented Interfaces:
ButtonClickObserver
LadderGameBoardCreatorController.
Controller responsible for the logic behind creating and editing LadderGameBoard
s.
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:
-
Field Summary
Fields inherited from class edu.ntnu.idi.idatt.controller.common.BoardCreatorController
board, boardFactory, boardPane, logger, onBackToMenu, view
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a LadderGameBoardCreatorController. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
handleImportBoard
(Map<String, Object> params) Handles the import of a board configuration from a file.protected void
handleSaveBoard
(Map<String, Object> params) Handles saving the current board configuration to a file.protected void
Handles the action to update the board's grid dimensions (rows and columns) based on values from the view's spinners.protected void
Initializes theBoardCreatorController.board
instance as a new, blankLadderGameBoard
using aLadderBoardFactory
with default dimensions.protected void
Initializes theLadderGameBoardCreatorView
.void
onButtonClicked
(String buttonId) Handles button click events from theLadderGameBoardCreatorView
.void
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).Methods inherited from class edu.ntnu.idi.idatt.controller.common.BoardCreatorController
handleBackToMenu, onButtonClickedWithParams, setOnBackToMenu
-
Constructor Details
-
LadderGameBoardCreatorController
Constructs a LadderGameBoardCreatorController.- Parameters:
view
- TheBoardCreatorView
(expected to be aLadderGameBoardCreatorView
) associated with this controller.
-
-
Method Details
-
initializeBoard
protected void initializeBoard()Initializes theBoardCreatorController.board
instance as a new, blankLadderGameBoard
using aLadderBoardFactory
with default dimensions.- Specified by:
initializeBoard
in classBoardCreatorController
-
initializeBoardCreatorView
protected void initializeBoardCreatorView()Initializes theLadderGameBoardCreatorView
. 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 classBoardCreatorController
-
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 classBoardCreatorController
-
handleImportBoard
Handles the import of a board configuration from a file. Updates the internalBoardCreatorController.board
model and refreshes the view's input fields (name, description, rows, columns, background, pattern) and the board display.- Specified by:
handleImportBoard
in classBoardCreatorController
- Parameters:
params
- A map containing the "path" (String) to the board file.
-
handleSaveBoard
Handles saving the current board configuration to a file. Updates the board model with values from the view's input fields before saving. UsesLadderGameBoardFileHandlerGson
for serialization.- Specified by:
handleSaveBoard
in classBoardCreatorController
- Parameters:
params
- A map containing the "path" (String) to save the file to.
-
onButtonClicked
Handles button click events from theLadderGameBoardCreatorView
. Delegates actions based on the button ID (e.g., back to menu, update grid, update background, update pattern).- Specified by:
onButtonClicked
in interfaceButtonClickObserver
- Overrides:
onButtonClicked
in classBoardCreatorController
- Parameters:
buttonId
- The ID of the button that was clicked.
-