Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tile_pos_to_int_grid_with_grid_tiles_tile_maker checks grid_tiles #228

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ pub fn spawn_level(
tile_pos_to_tile_if_int_grid_nonzero_maker(
tile_pos_to_invisible_tile,
&layer_instance.int_grid_csv,
&grid_tiles,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm a little confused by this actually - the issue is for grid_tiles overflow, right? I thought that could only happen on AutoTile layers (and intgrid+autotile layers). However, this change only affects non-autotile intgrid layers. The match tileset_definition { ... } this is inside of is Some on autotile intgrids, and None on non-autotile intgrids.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going back and looking at my LDTK file, the intgrid I'm using has the auto-layer tileset field set, so I guess it's intgrid+autotile. Maybe since the map is using that vs an autotile layer that points to an intgrid it's different? I'll try to get a small repro example set up since I'm admittedly not very familiar with LDTK.

layer_instance.c_wid,
layer_instance.c_hei,
),
Expand Down
14 changes: 14 additions & 0 deletions src/tile_makers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,29 @@ pub(crate) fn tile_pos_to_tile_maker(
pub(crate) fn tile_pos_to_tile_if_int_grid_nonzero_maker(
mut tile_maker: impl FnMut(TilePos) -> Option<TileBundle>,
int_grid_csv: &[i32],
grid_tiles: &[TileInstance],
layer_width_in_tiles: i32,
layer_height_in_tiles: i32,
) -> impl FnMut(TilePos) -> Option<TileBundle> {
let int_grid_map =
tile_pos_to_int_grid_map(int_grid_csv, layer_width_in_tiles, layer_height_in_tiles);

let grid_tile_positions: Vec<TilePos> = grid_tiles
.iter()
.map(|x| TilePos::new(x.src.x as u32, x.src.y as u32))
.collect();

move |tile_pos: TilePos| -> Option<TileBundle> {
int_grid_map
.get(&tile_pos)
.and_then(|_| tile_maker(tile_pos))
.and_then(|tb| {
if grid_tile_positions.contains(&tb.position) {
Some(tb)
} else {
None
}
})
}
}

Expand All @@ -171,6 +184,7 @@ pub(crate) fn tile_pos_to_int_grid_with_grid_tiles_tile_maker(
let mut invisible_tile_maker = tile_pos_to_tile_if_int_grid_nonzero_maker(
tile_pos_to_invisible_tile,
int_grid_csv,
grid_tiles,
layer_width_in_tiles,
layer_height_in_tiles,
);
Expand Down
Loading