Merge pull request #16971 from Noshyaar/tilemap
TileMap: add fix_invalid_tiles
This commit is contained in:
commit
c81356153e
|
@ -19,6 +19,13 @@
|
|||
Clear all cells.
|
||||
</description>
|
||||
</method>
|
||||
<method name="fix_invalid_tiles">
|
||||
<return type="void">
|
||||
</return>
|
||||
<description>
|
||||
Clear cells that does not exist in the tileset.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_cell" qualifiers="const">
|
||||
<return type="int">
|
||||
</return>
|
||||
|
|
|
@ -147,6 +147,15 @@ void TileMapEditor::_menu_option(int p_option) {
|
|||
|
||||
canvas_item_editor->update();
|
||||
} break;
|
||||
case OPTION_FIX_INVALID: {
|
||||
|
||||
undo_redo->create_action(TTR("Fix Invalid Tiles"));
|
||||
undo_redo->add_undo_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
node->fix_invalid_tiles();
|
||||
undo_redo->add_do_method(node, "set", "tile_data", node->get("tile_data"));
|
||||
undo_redo->commit_action();
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1583,6 +1592,8 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
|
|||
p->add_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_MASK_CMD + KEY_B), OPTION_SELECT);
|
||||
p->add_shortcut(ED_SHORTCUT("tile_map_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_CMD + KEY_D), OPTION_DUPLICATE);
|
||||
p->add_shortcut(ED_GET_SHORTCUT("tile_map_editor/erase_selection"), OPTION_ERASE_SELECTION);
|
||||
p->add_separator();
|
||||
p->add_item(TTR("Fix Invalid Tiles"), OPTION_FIX_INVALID);
|
||||
|
||||
p->connect("id_pressed", this, "_menu_option");
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ class TileMapEditor : public VBoxContainer {
|
|||
OPTION_DUPLICATE,
|
||||
OPTION_ERASE_SELECTION,
|
||||
OPTION_PAINTING,
|
||||
OPTION_FIX_INVALID,
|
||||
};
|
||||
|
||||
TileMap *node;
|
||||
|
|
|
@ -834,6 +834,16 @@ void TileMap::update_dirty_bitmask() {
|
|||
}
|
||||
}
|
||||
|
||||
void TileMap::fix_invalid_tiles() {
|
||||
|
||||
for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
|
||||
|
||||
if (!tile_set->has_tile(get_cell(E->key().x, E->key().y))) {
|
||||
set_cell(E->key().x, E->key().y, INVALID_CELL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int TileMap::get_cell(int p_x, int p_y) const {
|
||||
|
||||
PosKey pk(p_x, p_y);
|
||||
|
@ -1519,6 +1529,7 @@ void TileMap::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("is_cell_y_flipped", "x", "y"), &TileMap::is_cell_y_flipped);
|
||||
ClassDB::bind_method(D_METHOD("is_cell_transposed", "x", "y"), &TileMap::is_cell_transposed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("fix_invalid_tiles"), &TileMap::fix_invalid_tiles);
|
||||
ClassDB::bind_method(D_METHOD("clear"), &TileMap::clear);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_used_cells"), &TileMap::get_used_cells);
|
||||
|
|
|
@ -310,6 +310,7 @@ public:
|
|||
void set_clip_uv(bool p_enable);
|
||||
bool get_clip_uv() const;
|
||||
|
||||
void fix_invalid_tiles();
|
||||
void clear();
|
||||
|
||||
TileMap();
|
||||
|
|
Loading…
Reference in New Issue