Class TileGridManager

java.lang.Object
io.hymods.lib.tiles.TileGridManager

public class TileGridManager extends Object
Manages a 3x3 grid of map tiles with wrapping support. The grid uses 9 "slots" (indices 0-8) which map to asset paths Map0.png through Map8.png. Each slot can hold a tile from any world position. When the player moves, slots are reassigned to new world positions, reusing slots that would otherwise go off-screen. Grid layout (slot indices): 0 | 1 | 2 --------- 3 | 4 | 5 --------- 6 | 7 | 8 Slot 4 is always the "center" slot where the player currently is.
  • Field Details

  • Constructor Details

    • TileGridManager

      public TileGridManager(int tileSizeChunks)
  • Method Details

    • updateCenter

      public TileGridManager.GridUpdateResult updateCenter(TileCoord newCenter)
      Initialize or update the grid centered on a new tile. Returns information about which tiles need to be generated.
      Parameters:
      newCenter - The new center tile coordinate
      Returns:
      Result containing tiles to generate and slot assignments
    • markSlotInitialized

      public void markSlotInitialized(int slot)
      Mark a slot as initialized (has valid image data).
    • isInitialized

      public boolean isInitialized()
      Check if the grid has been initialized.
    • getCenterTile

      public TileCoord getCenterTile()
      Get the current center tile.
    • getTileAtSlot

      public TileCoord getTileAtSlot(int slot)
      Get the tile coordinate for a specific slot.
    • findSlotForTile

      public int findSlotForTile(TileCoord tile)
      Find which slot holds a specific tile coordinate.
      Parameters:
      tile - The tile coordinate to find
      Returns:
      The slot index, or -1 if not found
    • calculateSlotOffset

      public int[] calculateSlotOffset(int slot, double playerBlockX, double playerBlockZ, int viewportSize)
      Calculate the pixel offset for a slot based on player position. The offset positions each tile correctly in the viewport, accounting for: 1. The tile's world position relative to the center tile 2. The player's position within the current tile
      Parameters:
      slot - The slot index (0-8)
      playerBlockX - Player's X position in blocks
      playerBlockZ - Player's Z position in blocks
      viewportSize - Size of the viewport in pixels
      Returns:
      int[2] containing {offsetX, offsetZ} in pixels
    • setTilePixelSize

      public void setTilePixelSize(int size)
      Set the tile pixel size (determined after generation).
    • getTilePixelSize

      public int getTilePixelSize()
      Get the tile pixel size.
    • getTileSizeChunks

      public int getTileSizeChunks()
      Get the tile size in chunks.