Class EditorTool

java.lang.Object
de.tum.cit.ase.editor.input.ToolInputAdapter
de.tum.cit.ase.editor.tools.EditorTool
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor, com.badlogic.gdx.utils.Pool.Poolable, ShortcutAdapter, Tool
Direct Known Subclasses:
Bucket, Eraser, Pen, Square

public abstract sealed class EditorTool extends ToolInputAdapter implements Tool, com.badlogic.gdx.utils.Pool.Poolable permits Bucket, Eraser, Pen, Square
The base class for all editor tools.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.badlogic.gdx.math.Bresenham2
     
    protected Canvas
     
    protected com.badlogic.gdx.math.GridPoint2
     
    protected com.badlogic.gdx.math.GridPoint2
     

    Fields inherited from interface de.tum.cit.ase.editor.input.ShortcutAdapter

    pressedKeys
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    draw(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer)
    Draws using the provided ShapeRenderer.
     
    Retrieves an instance of the Tool class with the provided Canvas.
    protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.math.GridPoint2>
    getLine(com.badlogic.gdx.math.GridPoint2 start, com.badlogic.gdx.math.GridPoint2 end)
    Returns an array of GridPoint2 objects representing a line between the given start and end points.
    protected void
    getStraightLineCoordinates(com.badlogic.gdx.math.GridPoint2 startGrid, com.badlogic.gdx.math.Vector2 start, com.badlogic.gdx.math.Vector2 end)
    Sets the start and end coordinates of a straight line based on the given start grid point.
    protected boolean
    Determines if the current tool is set to draw a straight line.
    protected abstract void
    markTile(com.badlogic.gdx.math.GridPoint2 gridPoint)
    Marks a tile on the grid based on the given grid point.
    com.badlogic.gdx.math.Vector2
    projectGridPointToWorld(com.badlogic.gdx.math.GridPoint2 gridPoint2)
    Projects a grid point to world coordinates.
    com.badlogic.gdx.math.Vector2
    projectGridPointToWorld(com.badlogic.gdx.math.GridPoint2 gridPoint2, boolean edge)
    Projects a grid point to world coordinates.
    void
    Resets the state of the tool.
    boolean
    touchDown(int screenX, int screenY, int pointer, int button)
    Handles the touch down event in the editor.
    boolean
    touchDragged(int screenX, int screenY, int pointer)
    Handles the touch dragged event in the editor.
    boolean
    touchUp(int screenX, int screenY, int pointer, int button)
     
    void
    Validates the current state of the tool.

    Methods inherited from class de.tum.cit.ase.editor.input.ToolInputAdapter

    keyDown, keyTyped, keyUp, mouseMoved, scrolled, touchCancelled

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface de.tum.cit.ase.editor.input.ShortcutAdapter

    addKey, isShortcut, isShortcut, isShortcut, removeKey
  • Field Details

    • bresenham2

      protected com.badlogic.gdx.math.Bresenham2 bresenham2
    • canvas

      protected Canvas canvas
    • lastPosition

      protected com.badlogic.gdx.math.GridPoint2 lastPosition
    • lastGridPosition

      protected com.badlogic.gdx.math.GridPoint2 lastGridPosition
  • Constructor Details

    • EditorTool

      public EditorTool()
  • Method Details

    • draw

      public void draw(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer)
      Description copied from interface: Tool
      Draws using the provided ShapeRenderer.
      Specified by:
      draw in interface Tool
      Parameters:
      shapeRenderer - the ShapeRenderer object to use for drawing
    • isStraightLine

      protected boolean isStraightLine()
      Determines if the current tool is set to draw a straight line.
      Returns:
      true if the tool is set to draw a straight line, false otherwise
    • getStraightLineCoordinates

      protected void getStraightLineCoordinates(com.badlogic.gdx.math.GridPoint2 startGrid, com.badlogic.gdx.math.Vector2 start, com.badlogic.gdx.math.Vector2 end)
      Sets the start and end coordinates of a straight line based on the given start grid point.
      Parameters:
      startGrid - the starting grid point
      start - the starting point of the line
      end - the ending point of the line
    • getGrid

      public TileTypes[][] getGrid()
    • getInstance

      public Tool getInstance(Canvas canvas)
      Description copied from interface: Tool
      Retrieves an instance of the Tool class with the provided Canvas.
      Specified by:
      getInstance in interface Tool
      Parameters:
      canvas - The Canvas object to associate with the Tool instance.
      Returns:
      The Tool instance with the provided Canvas.
    • getLine

      protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.math.GridPoint2> getLine(com.badlogic.gdx.math.GridPoint2 start, com.badlogic.gdx.math.GridPoint2 end)
      Returns an array of GridPoint2 objects representing a line between the given start and end points.
      Parameters:
      start - the starting point of the line
      end - the ending point of the line
      Returns:
      an array of GridPoint2 objects representing the line
    • projectGridPointToWorld

      public com.badlogic.gdx.math.Vector2 projectGridPointToWorld(com.badlogic.gdx.math.GridPoint2 gridPoint2)
      Projects a grid point to world coordinates.
      Parameters:
      gridPoint2 - the grid point to project
      Returns:
      the projected world coordinates as a Vector2
    • projectGridPointToWorld

      public com.badlogic.gdx.math.Vector2 projectGridPointToWorld(com.badlogic.gdx.math.GridPoint2 gridPoint2, boolean edge)
      Projects a grid point to world coordinates.
      Parameters:
      gridPoint2 - the grid point to project
      edge - indicates whether to project the edge or center of the grid point
      Returns:
      the projected world coordinates as a Vector2
    • validate

      public void validate()
      Description copied from interface: Tool
      Validates the current state of the tool. This method is called internally to ensure the tool is in a valid state. It performs necessary validations and updates to the tool's internal state.
      Specified by:
      validate in interface Tool
    • touchDown

      public boolean touchDown(int screenX, int screenY, int pointer, int button)
      Handles the touch down event in the editor.
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDown in class ToolInputAdapter
      Parameters:
      screenX - The x coordinate of the touch position
      screenY - The y coordinate of the touch position
      pointer - The pointer for the event
      button - The button that was pressed
      Returns:
      true if the touch event is handled, false otherwise
    • markTile

      protected abstract void markTile(com.badlogic.gdx.math.GridPoint2 gridPoint) throws InvalidGridCellException
      Marks a tile on the grid based on the given grid point.
      Parameters:
      gridPoint - the grid point representing the tile to be marked
      Throws:
      InvalidGridCellException - if the grid point is invalid
    • touchUp

      public boolean touchUp(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchUp in class ToolInputAdapter
    • touchDragged

      public boolean touchDragged(int screenX, int screenY, int pointer)
      Handles the touch dragged event in the editor.
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDragged in class ToolInputAdapter
      Parameters:
      screenX - The x coordinate of the touch position
      screenY - The y coordinate of the touch position
      pointer - The pointer for the event
      Returns:
      true if the touch event is handled, false otherwise
    • reset

      public void reset()
      Resets the state of the tool.

      This method is responsible for resetting the tool to its initial state by setting the canvas field to null, and clearing the lastPosition and lastGridPosition fields.

      Specified by:
      reset in interface com.badlogic.gdx.utils.Pool.Poolable