Class TileGridManager
java.lang.Object
io.hymods.lib.tiles.TileGridManager
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of a grid update operation. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]calculateSlotOffset(int slot, double playerBlockX, double playerBlockZ, int viewportSize) Calculate the pixel offset for a slot based on player position.intfindSlotForTile(TileCoord tile) Find which slot holds a specific tile coordinate.Get the current center tile.getTileAtSlot(int slot) Get the tile coordinate for a specific slot.intGet the tile pixel size.intGet the tile size in chunks.booleanCheck if the grid has been initialized.voidmarkSlotInitialized(int slot) Mark a slot as initialized (has valid image data).voidsetTilePixelSize(int size) Set the tile pixel size (determined after generation).updateCenter(TileCoord newCenter) Initialize or update the grid centered on a new tile.
-
Field Details
-
GRID_SIZE
public static final int GRID_SIZE- See Also:
-
TOTAL_SLOTS
public static final int TOTAL_SLOTS- See Also:
-
CENTER_SLOT
public static final int CENTER_SLOT- See Also:
-
-
Constructor Details
-
TileGridManager
public TileGridManager(int tileSizeChunks)
-
-
Method Details
-
updateCenter
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
Get the current center tile. -
getTileAtSlot
Get the tile coordinate for a specific slot. -
findSlotForTile
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 blocksplayerBlockZ- Player's Z position in blocksviewportSize- 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.
-