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

Don't store TileMapLayer data if empty #90907

Merged
merged 1 commit into from
Apr 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion doc/classes/TileMapLayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
The quadrant size does not apply on a Y-sorted [TileMapLayer], as tiles are be grouped by Y position instead in that case.
[b]Note:[/b] As quadrants are created according to the map's coordinate system, the quadrant's "square shape" might not look like square in the [TileMapLayer]'s local coordinate system.
</member>
<member name="tile_map_data" type="PackedByteArray" setter="set_tile_map_data_from_array" getter="get_tile_map_data_as_array" default="PackedByteArray(&quot;AAA=&quot;)">
<member name="tile_map_data" type="PackedByteArray" setter="set_tile_map_data_from_array" getter="get_tile_map_data_as_array" default="PackedByteArray()">
The raw tile map data as a byte array.
</member>
<member name="tile_set" type="TileSet" setter="set_tile_set" getter="get_tile_set">
Expand Down
9 changes: 9 additions & 0 deletions scene/2d/tile_map_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,11 @@ TileMapLayer::HighlightMode TileMapLayer::get_highlight_mode() const {
}

void TileMapLayer::set_tile_map_data_from_array(const Vector<uint8_t> &p_data) {
if (p_data.is_empty()) {
clear();
return;
}

const int cell_data_struct_size = 12;

int size = p_data.size();
Expand Down Expand Up @@ -2630,6 +2635,10 @@ Vector<uint8_t> TileMapLayer::get_tile_map_data_as_array() const {
const int cell_data_struct_size = 12;

Vector<uint8_t> tile_map_data_array;
if (tile_map_layer_data.is_empty()) {
return tile_map_data_array;
}

tile_map_data_array.resize(2 + tile_map_layer_data.size() * cell_data_struct_size);
uint8_t *ptr = tile_map_data_array.ptrw();

Expand Down
Loading