diff options
Diffstat (limited to 'scene')
| -rw-r--r-- | scene/2d/tile_map.cpp | 247 | ||||
| -rw-r--r-- | scene/2d/tile_map.h | 29 | ||||
| -rw-r--r-- | scene/animation/animation_cache.cpp | 95 | ||||
| -rw-r--r-- | scene/animation/animation_cache.h | 2 | ||||
| -rw-r--r-- | scene/animation/animation_player.cpp | 30 | ||||
| -rw-r--r-- | scene/animation/animation_player.h | 2 | ||||
| -rw-r--r-- | scene/animation/animation_tree_player.cpp | 20 | ||||
| -rw-r--r-- | scene/animation/animation_tree_player.h | 6 | ||||
| -rw-r--r-- | scene/animation/tween.cpp | 128 | ||||
| -rw-r--r-- | scene/animation/tween.h | 27 | ||||
| -rw-r--r-- | scene/gui/text_edit.cpp | 47 | ||||
| -rw-r--r--[-rwxr-xr-x] | scene/main/node.cpp | 101 | ||||
| -rw-r--r-- | scene/main/node.h | 2 | ||||
| -rw-r--r-- | scene/resources/tile_set.cpp | 397 | ||||
| -rw-r--r-- | scene/resources/tile_set.h | 80 |
15 files changed, 974 insertions, 239 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index f067b5a187..f8bc27ccf6 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -365,6 +365,11 @@ void TileMap::_update_dirty_quadrants() { } Rect2 r = tile_set->tile_get_region(c.id); + if (tile_set->tile_get_is_autotile(c.id)) { + int spacing = tile_set->autotile_get_spacing(c.id); + r.size = tile_set->autotile_get_size(c.id); + r.position += (r.size + Vector2(spacing, spacing)) * Vector2(c.autotile_coord_x, c.autotile_coord_y); + } Size2 s = tex->get_size(); if (r == Rect2()) @@ -456,21 +461,23 @@ void TileMap::_update_dirty_quadrants() { for (int i = 0; i < shapes.size(); i++) { Ref<Shape2D> shape = shapes[i].shape; if (shape.is_valid()) { - Transform2D xform; - xform.set_origin(offset.floor()); - - Vector2 shape_ofs = tile_set->tile_get_shape_offset(c.id, i); - - _fix_cell_transform(xform, c, shape_ofs + center_ofs, s); - - if (debug_canvas_item.is_valid()) { - vs->canvas_item_add_set_transform(debug_canvas_item, xform); - shape->draw(debug_canvas_item, debug_collision_color); + if (!tile_set->tile_get_is_autotile(c.id) || (shapes[i].autotile_coord.x == c.autotile_coord_x && shapes[i].autotile_coord.y == c.autotile_coord_y)) { + Transform2D xform; + xform.set_origin(offset.floor()); + + Vector2 shape_ofs = tile_set->tile_get_shape_offset(c.id, i); + + _fix_cell_transform(xform, c, shape_ofs + center_ofs, s); + + if (debug_canvas_item.is_valid()) { + vs->canvas_item_add_set_transform(debug_canvas_item, xform); + shape->draw(debug_canvas_item, debug_collision_color); + } + ps->body_add_shape(q.body, shape->get_rid(), xform); + ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y)); + ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[i].one_way_collision); + shape_idx++; } - ps->body_add_shape(q.body, shape->get_rid(), xform); - ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y)); - ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[i].one_way_collision); - shape_idx++; } } @@ -479,9 +486,17 @@ void TileMap::_update_dirty_quadrants() { } if (navigation) { - Ref<NavigationPolygon> navpoly = tile_set->tile_get_navigation_polygon(c.id); + Ref<NavigationPolygon> navpoly; + Vector2 npoly_ofs; + if (tile_set->tile_get_is_autotile(c.id)) { + navpoly = tile_set->autotile_get_navigation_polygon(c.id, Vector2(c.autotile_coord_x, c.autotile_coord_y)); + npoly_ofs = Vector2(); + } else { + navpoly = tile_set->tile_get_navigation_polygon(c.id); + npoly_ofs = tile_set->tile_get_navigation_polygon_offset(c.id); + } + if (navpoly.is_valid()) { - Vector2 npoly_ofs = tile_set->tile_get_navigation_polygon_offset(c.id); Transform2D xform; xform.set_origin(offset.floor() + q.pos); _fix_cell_transform(xform, c, npoly_ofs + center_ofs, s); @@ -495,10 +510,17 @@ void TileMap::_update_dirty_quadrants() { } } - Ref<OccluderPolygon2D> occluder = tile_set->tile_get_light_occluder(c.id); + Ref<OccluderPolygon2D> occluder; + Vector2 occluder_ofs; + if (tile_set->tile_get_is_autotile(c.id)) { + occluder = tile_set->autotile_get_light_occluder(c.id, Vector2(c.autotile_coord_x, c.autotile_coord_y)); + occluder_ofs = tile_set->tile_get_occluder_offset(c.id); + } else { + occluder = tile_set->tile_get_light_occluder(c.id); + occluder_ofs = Vector2(); + } if (occluder.is_valid()) { - Vector2 occluder_ofs = tile_set->tile_get_occluder_offset(c.id); Transform2D xform; xform.set_origin(offset.floor() + q.pos); _fix_cell_transform(xform, c, occluder_ofs + center_ofs, s); @@ -656,7 +678,7 @@ void TileMap::set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x, bool p_ set_cell(p_pos.x, p_pos.y, p_tile, p_flip_x, p_flip_y, p_transpose); } -void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose) { +void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose, Vector2 p_autotile_coord) { PosKey pk(p_x, p_y); @@ -702,15 +724,105 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_ c.flip_h = p_flip_x; c.flip_v = p_flip_y; c.transpose = p_transpose; + c.autotile_coord_x = (uint16_t)p_autotile_coord.x; + c.autotile_coord_y = (uint16_t)p_autotile_coord.y; _make_quadrant_dirty(Q); used_size_cache_dirty = true; } int TileMap::get_cellv(const Vector2 &p_pos) const { + return get_cell(p_pos.x, p_pos.y); } +void TileMap::make_bitmask_area_dirty(const Vector2 &p_pos) { + + for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) { + for (int y = p_pos.y - 1; x <= p_pos.y + 1; y++) { + PosKey p(x, y); + if (dirty_bitmask.find(p) == NULL) { + dirty_bitmask.push_back(p); + } + } + } +} + +void TileMap::update_bitmask_area(const Vector2 &p_pos) { + + for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) { + for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) { + update_cell_bitmask(x, y); + } + } +} + +void TileMap::update_cell_bitmask(int p_x, int p_y) { + + PosKey p(p_x, p_y); + Map<PosKey, Cell>::Element *E = tile_map.find(p); + if (E != NULL) { + int id = get_cell(p_x, p_y); + if (tile_set->tile_get_is_autotile(id)) { + uint16_t mask = 0; + if (tile_set->autotile_get_bitmask_mode(id) == TileSet::BITMASK_2X2) { + if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { + mask |= TileSet::BIND_TOPLEFT; + } + if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { + mask |= TileSet::BIND_TOPRIGHT; + } + if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { + mask |= TileSet::BIND_BOTTOMLEFT; + } + if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { + mask |= TileSet::BIND_BOTTOMRIGHT; + } + } else if (tile_set->autotile_get_bitmask_mode(id) == TileSet::BITMASK_3X3) { + if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { + mask |= TileSet::BIND_TOPLEFT; + } + if (tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1))) { + mask |= TileSet::BIND_TOP; + } + if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { + mask |= TileSet::BIND_TOPRIGHT; + } + if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { + mask |= TileSet::BIND_LEFT; + } + mask |= TileSet::BIND_CENTER; + if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { + mask |= TileSet::BIND_RIGHT; + } + if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { + mask |= TileSet::BIND_BOTTOMLEFT; + } + if (tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1))) { + mask |= TileSet::BIND_BOTTOM; + } + if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { + mask |= TileSet::BIND_BOTTOMRIGHT; + } + } + Vector2 coord = tile_set->autotile_get_subtile_for_bitmask(id, mask, this, Vector2(p_x, p_y)); + E->get().autotile_coord_x = (int)coord.x; + E->get().autotile_coord_y = (int)coord.y; + } else { + E->get().autotile_coord_x = 0; + E->get().autotile_coord_y = 0; + } + } +} + +void TileMap::update_dirty_bitmask() { + + while (dirty_bitmask.size() > 0) { + update_cell_bitmask(dirty_bitmask[0].x, dirty_bitmask[0].y); + dirty_bitmask.pop_front(); + } +} + int TileMap::get_cell(int p_x, int p_y) const { PosKey pk(p_x, p_y); @@ -756,6 +868,30 @@ bool TileMap::is_cell_transposed(int p_x, int p_y) const { return E->get().transpose; } +int TileMap::get_cell_autotile_coord_x(int p_x, int p_y) const { + + PosKey pk(p_x, p_y); + + const Map<PosKey, Cell>::Element *E = tile_map.find(pk); + + if (!E) + return 0; + + return E->get().autotile_coord_x; +} + +int TileMap::get_cell_autotile_coord_y(int p_x, int p_y) const { + + PosKey pk(p_x, p_y); + + const Map<PosKey, Cell>::Element *E = tile_map.find(pk); + + if (!E) + return 0; + + return E->get().autotile_coord_y; +} + void TileMap::_recreate_quadrants() { _clear_quadrants(); @@ -823,11 +959,13 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) { int c = p_data.size(); PoolVector<int>::Read r = p_data.read(); - for (int i = 0; i < c; i += 2) { + int offset = (format == FORMAT_2_1_5) ? 3 : 2; + + for (int i = 0; i < c; i += offset) { const uint8_t *ptr = (const uint8_t *)&r[i]; - uint8_t local[8]; - for (int j = 0; j < 8; j++) + uint8_t local[12]; + for (int j = 0; j < ((format == FORMAT_2_1_5) ? 12 : 8); j++) local[j] = ptr[j]; #ifdef BIG_ENDIAN_ENABLED @@ -836,6 +974,11 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) { SWAP(local[1], local[2]); SWAP(local[4], local[7]); SWAP(local[5], local[6]); + //TODO: ask someone to check this... + if (FORMAT == FORMAT_2_1_5) { + SWAP(local[8], local[11]); + SWAP(local[9], local[10]); + } #endif int16_t x = decode_uint16(&local[0]); @@ -845,24 +988,28 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) { bool flip_v = v & (1 << 30); bool transpose = v & (1 << 31); v &= (1 << 29) - 1; - + int16_t coord_x; + int16_t coord_y; + if (format == FORMAT_2_1_5) { + coord_x = decode_uint16(&local[8]); + coord_y = decode_uint16(&local[10]); + } /* if (x<-20 || y <-20 || x>4000 || y>4000) continue; */ - set_cell(x, y, v, flip_h, flip_v, transpose); + set_cell(x, y, v, flip_h, flip_v, transpose, Vector2(coord_x, coord_y)); } } PoolVector<int> TileMap::_get_tile_data() const { PoolVector<int> data; - data.resize(tile_map.size() * 2); + data.resize(tile_map.size() * 3); PoolVector<int>::Write w = data.write(); int idx = 0; for (const Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) { - uint8_t *ptr = (uint8_t *)&w[idx]; encode_uint16(E->key().x, &ptr[0]); encode_uint16(E->key().y, &ptr[2]); @@ -873,9 +1020,10 @@ PoolVector<int> TileMap::_get_tile_data() const { val |= (1 << 30); if (E->get().transpose) val |= (1 << 31); - encode_uint32(val, &ptr[4]); - idx += 2; + encode_uint16(E->get().autotile_coord_x, &ptr[8]); + encode_uint16(E->get().autotile_coord_y, &ptr[10]); + idx += 3; } w = PoolVector<int>::Write(); @@ -1119,10 +1267,50 @@ Vector2 TileMap::_map_to_world(int p_x, int p_y, bool p_ignore_ofs) const { } return ret; } + +bool TileMap::_set(const StringName &p_name, const Variant &p_value) { + + if (p_name == "format") { + if (p_value.get_type() == Variant::INT) { + format = (DataFormat)(p_value.operator int64_t()); + return true; + } + } else if (p_name == "tile_data") { + if (p_value.is_array()) { + _set_tile_data(p_value); + return true; + } + return false; + } + return false; +} + +bool TileMap::_get(const StringName &p_name, Variant &r_ret) const { + + if (p_name == "format") { + r_ret = FORMAT_2_1_5; + return true; + } else if (p_name == "tile_data") { + r_ret = _get_tile_data(); + return true; + } + return false; +} + +void TileMap::_get_property_list(List<PropertyInfo> *p_list) const { + + PropertyInfo p(Variant::INT, "format", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR); + p_list->push_back(p); + + p = PropertyInfo(Variant::OBJECT, "tile_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR); + p_list->push_back(p); +} + Vector2 TileMap::map_to_world(const Vector2 &p_pos, bool p_ignore_ofs) const { return _map_to_world(p_pos.x, p_pos.y, p_ignore_ofs); } + Vector2 TileMap::world_to_map(const Vector2 &p_pos) const { Vector2 ret = get_cell_transform().affine_inverse().xform(p_pos); @@ -1357,8 +1545,6 @@ void TileMap::_bind_methods() { ADD_GROUP("Occluder", "occluder_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "occluder_light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_occluder_light_mask", "get_occluder_light_mask"); - ADD_GROUP("", ""); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tile_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_tile_data", "_get_tile_data"); ADD_SIGNAL(MethodInfo("settings_changed")); @@ -1398,6 +1584,7 @@ TileMap::TileMap() { y_sort_mode = false; occluder_light_mask = 1; clip_uv = false; + format = FORMAT_2_1_4; //Always initialize with the lowest format fp_adjust = 0.00001; tile_origin = TILE_ORIGIN_TOP_LEFT; diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 9e14ec838a..a0ca2e6a35 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -60,6 +60,11 @@ public: }; private: + enum DataFormat { + FORMAT_2_1_4 = 0, + FORMAT_2_1_5 + }; + Ref<TileSet> tile_set; Size2i cell_size; int quadrant_size; @@ -81,6 +86,8 @@ private: //using a more precise comparison so the regions can be sorted later bool operator<(const PosKey &p_k) const { return (y == p_k.y) ? x < p_k.x : y < p_k.y; } + bool operator==(const PosKey &p_k) const { return (y == p_k.y && x == p_k.x); } + PosKey(int16_t p_x, int16_t p_y) { x = p_x; y = p_y; @@ -98,13 +105,17 @@ private: bool flip_h : 1; bool flip_v : 1; bool transpose : 1; + int16_t autotile_coord_x : 16; + int16_t autotile_coord_y : 16; }; - uint32_t _u32t; - Cell() { _u32t = 0; } + uint64_t _u64t; + Cell() { _u64t = 0; } }; Map<PosKey, Cell> tile_map; + List<PosKey> dirty_bitmask; + struct Quadrant { Vector2 pos; @@ -167,6 +178,7 @@ private: float bounce; uint32_t collision_layer; uint32_t collision_mask; + DataFormat format; TileOrigin tile_origin; @@ -198,6 +210,10 @@ private: _FORCE_INLINE_ Vector2 _map_to_world(int p_x, int p_y, bool p_ignore_ofs = false) const; protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; + void _notification(int p_what); static void _bind_methods(); @@ -220,17 +236,24 @@ public: void set_center_y(bool p_enable); bool get_center_y() const; - void set_cell(int p_x, int p_y, int p_tile, bool p_flip_x = false, bool p_flip_y = false, bool p_transpose = false); + void set_cell(int p_x, int p_y, int p_tile, bool p_flip_x = false, bool p_flip_y = false, bool p_transpose = false, Vector2 p_autotile_coord = Vector2()); int get_cell(int p_x, int p_y) const; bool is_cell_x_flipped(int p_x, int p_y) const; bool is_cell_y_flipped(int p_x, int p_y) const; bool is_cell_transposed(int p_x, int p_y) const; + int get_cell_autotile_coord_x(int p_x, int p_y) const; + int get_cell_autotile_coord_y(int p_x, int p_y) const; void set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x = false, bool p_flip_y = false, bool p_transpose = false); int get_cellv(const Vector2 &p_pos) const; Rect2 _edit_get_rect() const; + void make_bitmask_area_dirty(const Vector2 &p_pos); + void update_bitmask_area(const Vector2 &p_pos); + void update_cell_bitmask(int p_x, int p_y); + void update_dirty_bitmask(); + void set_collision_layer(uint32_t p_layer); uint32_t get_collision_layer() const; diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index b35b2568d1..fbe2593362 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -87,95 +87,90 @@ void AnimationCache::_update_cache() { Ref<Resource> res; - if (np.get_subname_count()) { - - if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) { + if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) { + if (np.get_subname_count() > 1) { path_cache.push_back(Path()); ERR_EXPLAIN("Transform tracks can't have a subpath: " + np); ERR_CONTINUE(animation->track_get_type(i) == Animation::TYPE_TRANSFORM); } - RES res; - - for (int j = 0; j < np.get_subname_count(); j++) { - res = j == 0 ? node->get(np.get_subname(j)) : res->get(np.get_subname(j)); - if (res.is_null()) - break; - } + Spatial *sp = Object::cast_to<Spatial>(node); - if (res.is_null()) { + if (!sp) { path_cache.push_back(Path()); - ERR_EXPLAIN("Invalid Track SubPath in Animation: " + np); - ERR_CONTINUE(res.is_null()); + ERR_EXPLAIN("Transform track not of type Spatial: " + np); + ERR_CONTINUE(!sp); } - path.resource = res; - path.object = res.ptr(); - - } else { - - if (animation->track_get_type(i) == Animation::TYPE_TRANSFORM) { - StringName property = np.get_property(); + if (np.get_subname_count() == 1) { + StringName property = np.get_subname(0); String ps = property; - Spatial *sp = Object::cast_to<Spatial>(node); + Skeleton *sk = Object::cast_to<Skeleton>(node); + if (!sk) { - if (!sp) { + path_cache.push_back(Path()); + ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton!: " + np); + ERR_CONTINUE(!sk); + } + int idx = sk->find_bone(ps); + if (idx == -1) { path_cache.push_back(Path()); - ERR_EXPLAIN("Transform track not of type Spatial: " + np); - ERR_CONTINUE(!sp); + ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton Bone!: " + np); + ERR_CONTINUE(idx == -1); } - if (ps != "") { + path.bone_idx = idx; + path.skeleton = sk; + } - Skeleton *sk = Object::cast_to<Skeleton>(node); - if (!sk) { + path.spatial = sp; - path_cache.push_back(Path()); - ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton!: " + np); - ERR_CONTINUE(!sk); - } + } else { + if (np.get_subname_count() > 0) { - int idx = sk->find_bone(ps); - if (idx == -1) { + RES res; + Vector<StringName> leftover_subpath; - path_cache.push_back(Path()); - ERR_EXPLAIN("Property defined in Transform track, but not a Skeleton Bone!: " + np); - ERR_CONTINUE(idx == -1); - } + // We don't want to cache the last resource unless it is a method call + bool is_method = animation->track_get_type(i) == Animation::TYPE_METHOD; + root->get_node_and_resource(np, res, leftover_subpath, is_method); - path.bone_idx = idx; - path.skeleton = sk; + if (res.is_valid()) { + path.resource = res; + } else { + path.node = node; } + path.object = res.is_valid() ? res.ptr() : (Object *)node; + path.subpath = leftover_subpath; - path.spatial = sp; - } + } else { - path.node = node; - path.object = node; + path.node = node; + path.object = node; + path.subpath = np.get_subnames(); + } } if (animation->track_get_type(i) == Animation::TYPE_VALUE) { - if (np.get_property().operator String() == "") { + if (np.get_subname_count() == 0) { path_cache.push_back(Path()); ERR_EXPLAIN("Value Track lacks property: " + np); - ERR_CONTINUE(np.get_property().operator String() == ""); + ERR_CONTINUE(np.get_subname_count() == 0); } - path.property = np.get_property(); - } else if (animation->track_get_type(i) == Animation::TYPE_METHOD) { - if (np.get_property().operator String() != "") { + if (path.subpath.size() != 0) { // Trying to call a method of a non-resource path_cache.push_back(Path()); ERR_EXPLAIN("Method Track has property: " + np); - ERR_CONTINUE(np.get_property().operator String() != ""); + ERR_CONTINUE(path.subpath.size() != 0); } } @@ -226,7 +221,7 @@ void AnimationCache::set_track_value(int p_idx, const Variant &p_value) { return; ERR_FAIL_COND(!p.object); - p.object->set(p.property, p_value); + p.object->set_indexed(p.subpath, p_value); } void AnimationCache::call_track(int p_idx, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { diff --git a/scene/animation/animation_cache.h b/scene/animation/animation_cache.h index e593668df6..481de59730 100644 --- a/scene/animation/animation_cache.h +++ b/scene/animation/animation_cache.h @@ -46,7 +46,7 @@ class AnimationCache : public Object { Spatial *spatial; int bone_idx; - StringName property; + Vector<StringName> subpath; bool valid; Path() { object = NULL; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 6be3ff88d9..010f5a586f 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -242,7 +242,8 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { p_anim->node_cache[i] = NULL; RES resource; - Node *child = parent->get_node_and_resource(a->track_get_path(i), resource); + Vector<StringName> leftover_path; + Node *child = parent->get_node_and_resource(a->track_get_path(i), resource, leftover_path); if (!child) { ERR_EXPLAIN("On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'"); } @@ -250,9 +251,9 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id(); int bone_idx = -1; - if (a->track_get_path(i).get_property() && Object::cast_to<Skeleton>(child)) { + if (a->track_get_path(i).get_subname_count() == 1 && Object::cast_to<Skeleton>(child)) { - bone_idx = Object::cast_to<Skeleton>(child)->find_bone(a->track_get_path(i).get_property()); + bone_idx = Object::cast_to<Skeleton>(child)->find_bone(a->track_get_path(i).get_subname(0)); if (bone_idx == -1) { continue; @@ -289,8 +290,8 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { p_anim->node_cache[i]->skeleton = Object::cast_to<Skeleton>(child); if (p_anim->node_cache[i]->skeleton) { - StringName bone_name = a->track_get_path(i).get_property(); - if (bone_name.operator String() != "") { + if (a->track_get_path(i).get_subname_count() == 1) { + StringName bone_name = a->track_get_path(i).get_subname(0); p_anim->node_cache[i]->bone_idx = p_anim->node_cache[i]->skeleton->find_bone(bone_name); if (p_anim->node_cache[i]->bone_idx < 0) { @@ -311,24 +312,23 @@ void AnimationPlayer::_generate_node_caches(AnimationData *p_anim) { if (a->track_get_type(i) == Animation::TYPE_VALUE) { - StringName property = a->track_get_path(i).get_property(); - if (!p_anim->node_cache[i]->property_anim.has(property)) { + if (!p_anim->node_cache[i]->property_anim.has(a->track_get_path(i).get_concatenated_subnames())) { TrackNodeCache::PropertyAnim pa; - pa.prop = property; + pa.subpath = leftover_path; pa.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child; pa.special = SP_NONE; pa.owner = p_anim->node_cache[i]; if (false && p_anim->node_cache[i]->node_2d) { - if (pa.prop == SceneStringNames::get_singleton()->transform_pos) + if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_pos) pa.special = SP_NODE2D_POS; - else if (pa.prop == SceneStringNames::get_singleton()->transform_rot) + else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_rot) pa.special = SP_NODE2D_ROT; - else if (pa.prop == SceneStringNames::get_singleton()->transform_scale) + else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_scale) pa.special = SP_NODE2D_SCALE; } - p_anim->node_cache[i]->property_anim[property] = pa; + p_anim->node_cache[i]->property_anim[a->track_get_path(i).get_concatenated_subnames()] = pa; } } } @@ -396,7 +396,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float //StringName property=a->track_get_path(i).get_property(); - Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.find(a->track_get_path(i).get_property()); + Map<StringName, TrackNodeCache::PropertyAnim>::Element *E = nc->property_anim.find(a->track_get_path(i).get_concatenated_subnames()); ERR_CONTINUE(!E); //should it continue, or create a new one? TrackNodeCache::PropertyAnim *pa = &E->get(); @@ -434,7 +434,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float case SP_NONE: { bool valid; - pa->object->set(pa->prop, value, &valid); //you are not speshul + pa->object->set_indexed(pa->subpath, value, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { ERR_PRINTS("Failed setting track value '" + String(pa->owner->path) + "'. Check if property exists or the type of key is valid. Animation '" + a->get_name() + "' at node '" + get_path() + "'."); @@ -622,7 +622,7 @@ void AnimationPlayer::_animation_update_transforms() { case SP_NONE: { bool valid; - pa->object->set(pa->prop, pa->value_accum, &valid); //you are not speshul + pa->object->set_indexed(pa->subpath, pa->value_accum, &valid); //you are not speshul #ifdef DEBUG_ENABLED if (!valid) { ERR_PRINTS("Failed setting key at time " + rtos(playback.current.pos) + " in Animation '" + get_current_animation() + "' at Node '" + get_path() + "', Track '" + String(pa->owner->path) + "'. Check if property exists or the type of key is right for the property"); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 83da3b2e5c..e4e021c7fe 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -83,7 +83,7 @@ private: TrackNodeCache *owner; SpecialProperty special; //small optimization - StringName prop; + Vector<StringName> subpath; Object *object; Variant value_accum; uint64_t accum_pass; diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index ad5329c94b..23eccec82f 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -811,7 +811,7 @@ void AnimationTreePlayer::_process_animation(float p_delta) { t.scale.y = 0; t.scale.z = 0; - t.value = t.object->get(t.property); + t.value = t.object->get_indexed(t.subpath); t.value.zero(); t.skip = false; @@ -890,8 +890,8 @@ void AnimationTreePlayer::_process_animation(float p_delta) { if (t.skip || !t.object) continue; - if (t.property) { // value track - t.object->set(t.property, t.value); + if (t.subpath.size()) { // value track + t.object->set_indexed(t.subpath, t.value); continue; } @@ -1475,7 +1475,8 @@ AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_p ERR_FAIL_COND_V(!parent, NULL); RES resource; - Node *child = parent->get_node_and_resource(p_path, resource); + Vector<StringName> leftover_path; + Node *child = parent->get_node_and_resource(p_path, resource, leftover_path); if (!child) { String err = "Animation track references unknown Node: '" + String(p_path) + "'."; WARN_PRINT(err.ascii().get_data()); @@ -1483,21 +1484,18 @@ AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_p } ObjectID id = child->get_instance_id(); - StringName property; int bone_idx = -1; - if (p_path.get_property()) { + if (p_path.get_subname_count()) { if (Object::cast_to<Skeleton>(child)) - bone_idx = Object::cast_to<Skeleton>(child)->find_bone(p_path.get_property()); - if (bone_idx == -1) - property = p_path.get_property(); + bone_idx = Object::cast_to<Skeleton>(child)->find_bone(p_path.get_subname(0)); } TrackKey key; key.id = id; key.bone_idx = bone_idx; - key.property = property; + key.subpath_concatenated = p_path.get_concatenated_subnames(); if (!track_map.has(key)) { @@ -1507,7 +1505,7 @@ AnimationTreePlayer::Track *AnimationTreePlayer::_find_track(const NodePath &p_p tr.skeleton = Object::cast_to<Skeleton>(child); tr.spatial = Object::cast_to<Spatial>(child); tr.bone_idx = bone_idx; - tr.property = property; + if (bone_idx == -1) tr.subpath = leftover_path; track_map[key] = tr; } diff --git a/scene/animation/animation_tree_player.h b/scene/animation/animation_tree_player.h index 3e2bb88198..c49b0c4d1b 100644 --- a/scene/animation/animation_tree_player.h +++ b/scene/animation/animation_tree_player.h @@ -78,14 +78,14 @@ private: struct TrackKey { uint32_t id; - StringName property; + StringName subpath_concatenated; int bone_idx; inline bool operator<(const TrackKey &p_right) const { if (id == p_right.id) { if (bone_idx == p_right.bone_idx) { - return property < p_right.property; + return subpath_concatenated < p_right.subpath_concatenated; } else return bone_idx < p_right.bone_idx; } else @@ -99,7 +99,7 @@ private: Spatial *spatial; Skeleton *skeleton; int bone_idx; - StringName property; + Vector<StringName> subpath; Vector3 loc; Quat rot; diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 40d06dc756..151632a0cb 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -264,12 +264,12 @@ Variant &Tween::_get_initial_val(InterpolateData &p_data) { if (p_data.type == TARGETING_PROPERTY) { bool valid = false; - initial_val = object->get(p_data.target_key, &valid); + initial_val = object->get_indexed(p_data.target_key, &valid); ERR_FAIL_COND_V(!valid, p_data.initial_val); } else { Variant::CallError error; - initial_val = object->call(p_data.target_key, NULL, 0, error); + initial_val = object->call(p_data.target_key[0], NULL, 0, error); ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, p_data.initial_val); } return initial_val; @@ -296,12 +296,12 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) { if (p_data.type == FOLLOW_PROPERTY) { bool valid = false; - final_val = target->get(p_data.target_key, &valid); + final_val = target->get_indexed(p_data.target_key, &valid); ERR_FAIL_COND_V(!valid, p_data.initial_val); } else { Variant::CallError error; - final_val = target->call(p_data.target_key, NULL, 0, error); + final_val = target->call(p_data.target_key[0], NULL, 0, error); ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK, p_data.initial_val); } @@ -462,6 +462,9 @@ Variant Tween::_run_equation(InterpolateData &p_data) { result = r; } break; + default: { + result = initial_val; + } break; }; #undef APPLY_EQUATION @@ -479,7 +482,7 @@ bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) { case FOLLOW_PROPERTY: case TARGETING_PROPERTY: { bool valid = false; - object->set(p_data.key, value, &valid); + object->set_indexed(p_data.key, value, &valid); return valid; } @@ -489,9 +492,9 @@ bool Tween::_apply_tween_value(InterpolateData &p_data, Variant &value) { Variant::CallError error; if (value.get_type() != Variant::NIL) { Variant *arg[1] = { &value }; - object->call(p_data.key, (const Variant **)arg, 1, error); + object->call(p_data.key[0], (const Variant **)arg, 1, error); } else { - object->call(p_data.key, NULL, 0, error); + object->call(p_data.key[0], NULL, 0, error); } if (error.error == Variant::CallError::CALL_OK) @@ -548,7 +551,7 @@ void Tween::_tween_process(float p_delta) { continue; else if (prev_delaying) { - emit_signal("tween_started", object, data.key); + emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false)); _apply_tween_value(data, data.initial_val); } @@ -562,7 +565,7 @@ void Tween::_tween_process(float p_delta) { case INTER_PROPERTY: case INTER_METHOD: { Variant result = _run_equation(data); - emit_signal("tween_step", object, data.key, data.elapsed, result); + emit_signal("tween_step", object, NodePath(Vector<StringName>(), data.key, false), data.elapsed, result); _apply_tween_value(data, result); if (data.finish) _apply_tween_value(data, data.final_val); @@ -574,22 +577,22 @@ void Tween::_tween_process(float p_delta) { switch (data.args) { case 0: - object->call_deferred(data.key); + object->call_deferred(data.key[0]); break; case 1: - object->call_deferred(data.key, data.arg[0]); + object->call_deferred(data.key[0], data.arg[0]); break; case 2: - object->call_deferred(data.key, data.arg[0], data.arg[1]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1]); break; case 3: - object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2]); break; case 4: - object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3]); break; case 5: - object->call_deferred(data.key, data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); + object->call_deferred(data.key[0], data.arg[0], data.arg[1], data.arg[2], data.arg[3], data.arg[4]); break; } } else { @@ -601,17 +604,18 @@ void Tween::_tween_process(float p_delta) { &data.arg[3], &data.arg[4], }; - object->call(data.key, (const Variant **)arg, data.args, error); + object->call(data.key[0], (const Variant **)arg, data.args, error); } } break; + default: {} } if (data.finish) { - emit_signal("tween_completed", object, data.key); + emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false)); // not repeat mode, remove completed action if (!repeat) - call_deferred("_remove", object, data.key, true); + call_deferred("_remove", object, NodePath(Vector<StringName>(), data.key, false), true); } } pending_update--; @@ -690,7 +694,7 @@ bool Tween::start() { return true; } -bool Tween::reset(Object *p_object, String p_key) { +bool Tween::reset(Object *p_object, StringName p_key) { pending_update++; for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { @@ -700,7 +704,7 @@ bool Tween::reset(Object *p_object, String p_key) { if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) { + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { data.elapsed = 0; data.finish = false; @@ -727,7 +731,7 @@ bool Tween::reset_all() { return true; } -bool Tween::stop(Object *p_object, String p_key) { +bool Tween::stop(Object *p_object, StringName p_key) { pending_update++; for (List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) { @@ -736,7 +740,7 @@ bool Tween::stop(Object *p_object, String p_key) { Object *object = ObjectDB::get_instance(data.id); if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) data.active = false; } pending_update--; @@ -758,7 +762,7 @@ bool Tween::stop_all() { return true; } -bool Tween::resume(Object *p_object, String p_key) { +bool Tween::resume(Object *p_object, StringName p_key) { set_active(true); _set_process(true); @@ -770,7 +774,7 @@ bool Tween::resume(Object *p_object, String p_key) { Object *object = ObjectDB::get_instance(data.id); if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) data.active = true; } pending_update--; @@ -792,12 +796,12 @@ bool Tween::resume_all() { return true; } -bool Tween::remove(Object *p_object, String p_key) { +bool Tween::remove(Object *p_object, StringName p_key) { _remove(p_object, p_key, false); return true; } -void Tween::_remove(Object *p_object, String p_key, bool first_only) { +void Tween::_remove(Object *p_object, StringName p_key, bool first_only) { if (pending_update != 0) { call_deferred("_remove", p_object, p_key, first_only); @@ -810,7 +814,7 @@ void Tween::_remove(Object *p_object, String p_key, bool first_only) { Object *object = ObjectDB::get_instance(data.id); if (object == NULL) continue; - if (object == p_object && (data.key == p_key || p_key == "")) { + if (object == p_object && (data.concatenated_key == p_key || p_key == "")) { for_removal.push_back(E); if (first_only) { break; @@ -850,8 +854,9 @@ bool Tween::seek(real_t p_time) { data.finish = true; data.elapsed = (data.delay + data.duration); - } else + } else { data.finish = false; + } switch (data.type) { case INTER_PROPERTY: @@ -993,11 +998,15 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final return true; } -bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("interpolate_property", p_object, p_property, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; } + p_property = p_property.get_as_property_path(); + + if (p_initial_val.get_type() == Variant::NIL) p_initial_val = p_object->get_indexed(p_property.get_subnames()); + // convert INT to REAL is better for interpolaters if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); @@ -1011,7 +1020,7 @@ bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_ ERR_FAIL_COND_V(p_delay < 0, false); bool prop_valid = false; - p_object->get(p_property, &prop_valid); + p_object->get_indexed(p_property.get_subnames(), &prop_valid); ERR_FAIL_COND_V(!prop_valid, false); InterpolateData data; @@ -1021,7 +1030,8 @@ bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_ data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_property; + data.key = p_property.get_subnames(); + data.concatenated_key = p_property.get_concatenated_subnames(); data.initial_val = p_initial_val; data.final_val = p_final_val; data.duration = p_duration; @@ -1036,7 +1046,7 @@ bool Tween::interpolate_property(Object *p_object, String p_property, Variant p_ return true; } -bool Tween::interpolate_method(Object *p_object, String p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("interpolate_method", p_object, p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; @@ -1063,7 +1073,8 @@ bool Tween::interpolate_method(Object *p_object, String p_method, Variant p_init data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_method; + data.key.push_back(p_method); + data.concatenated_key = p_method; data.initial_val = p_initial_val; data.final_val = p_final_val; data.duration = p_duration; @@ -1100,7 +1111,8 @@ bool Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_c data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_callback; + data.key.push_back(p_callback); + data.concatenated_key = p_callback; data.duration = p_duration; data.delay = 0; @@ -1152,7 +1164,8 @@ bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_callback; + data.key.push_back(p_callback); + data.concatenated_key = p_callback; data.duration = p_duration; data.delay = 0; @@ -1183,11 +1196,16 @@ bool Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S return true; } -bool Tween::follow_property(Object *p_object, String p_property, Variant p_initial_val, Object *p_target, String p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("follow_property", p_object, p_property, p_initial_val, p_target, p_target_property, p_duration, p_trans_type, p_ease_type, p_delay); return true; } + p_property = p_property.get_as_property_path(); + p_target_property = p_target_property.get_as_property_path(); + + if (p_initial_val.get_type() == Variant::NIL) p_initial_val = p_object->get_indexed(p_property.get_subnames()); + // convert INT to REAL is better for interpolaters if (p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t(); @@ -1201,11 +1219,11 @@ bool Tween::follow_property(Object *p_object, String p_property, Variant p_initi ERR_FAIL_COND_V(p_delay < 0, false); bool prop_valid = false; - p_object->get(p_property, &prop_valid); + p_object->get_indexed(p_property.get_subnames(), &prop_valid); ERR_FAIL_COND_V(!prop_valid, false); bool target_prop_valid = false; - Variant target_val = p_target->get(p_target_property, &target_prop_valid); + Variant target_val = p_target->get_indexed(p_target_property.get_subnames(), &target_prop_valid); ERR_FAIL_COND_V(!target_prop_valid, false); // convert INT to REAL is better for interpolaters @@ -1219,10 +1237,11 @@ bool Tween::follow_property(Object *p_object, String p_property, Variant p_initi data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_property; + data.key = p_property.get_subnames(); + data.concatenated_key = p_property.get_concatenated_subnames(); data.initial_val = p_initial_val; data.target_id = p_target->get_instance_id(); - data.target_key = p_target_property; + data.target_key = p_target_property.get_subnames(); data.duration = p_duration; data.trans_type = p_trans_type; data.ease_type = p_ease_type; @@ -1232,7 +1251,7 @@ bool Tween::follow_property(Object *p_object, String p_property, Variant p_initi return true; } -bool Tween::follow_method(Object *p_object, String p_method, Variant p_initial_val, Object *p_target, String p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("follow_method", p_object, p_method, p_initial_val, p_target, p_target_method, p_duration, p_trans_type, p_ease_type, p_delay); return true; @@ -1269,10 +1288,11 @@ bool Tween::follow_method(Object *p_object, String p_method, Variant p_initial_v data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_method; + data.key.push_back(p_method); + data.concatenated_key = p_method; data.initial_val = p_initial_val; data.target_id = p_target->get_instance_id(); - data.target_key = p_target_method; + data.target_key.push_back(p_target_method); data.duration = p_duration; data.trans_type = p_trans_type; data.ease_type = p_ease_type; @@ -1282,11 +1302,15 @@ bool Tween::follow_method(Object *p_object, String p_method, Variant p_initial_v return true; } -bool Tween::targeting_property(Object *p_object, String p_property, Object *p_initial, String p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { + if (pending_update != 0) { _add_pending_command("targeting_property", p_object, p_property, p_initial, p_initial_property, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; } + p_property = p_property.get_as_property_path(); + p_initial_property = p_initial_property.get_as_property_path(); + // convert INT to REAL is better for interpolaters if (p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t(); @@ -1300,11 +1324,11 @@ bool Tween::targeting_property(Object *p_object, String p_property, Object *p_in ERR_FAIL_COND_V(p_delay < 0, false); bool prop_valid = false; - p_object->get(p_property, &prop_valid); + p_object->get_indexed(p_property.get_subnames(), &prop_valid); ERR_FAIL_COND_V(!prop_valid, false); bool initial_prop_valid = false; - Variant initial_val = p_initial->get(p_initial_property, &initial_prop_valid); + Variant initial_val = p_initial->get_indexed(p_initial_property.get_subnames(), &initial_prop_valid); ERR_FAIL_COND_V(!initial_prop_valid, false); // convert INT to REAL is better for interpolaters @@ -1318,9 +1342,10 @@ bool Tween::targeting_property(Object *p_object, String p_property, Object *p_in data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_property; + data.key = p_property.get_subnames(); + data.concatenated_key = p_property.get_concatenated_subnames(); data.target_id = p_initial->get_instance_id(); - data.target_key = p_initial_property; + data.target_key = p_initial_property.get_subnames(); data.initial_val = initial_val; data.final_val = p_final_val; data.duration = p_duration; @@ -1335,7 +1360,7 @@ bool Tween::targeting_property(Object *p_object, String p_property, Object *p_in return true; } -bool Tween::targeting_method(Object *p_object, String p_method, Object *p_initial, String p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { +bool Tween::targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay) { if (pending_update != 0) { _add_pending_command("targeting_method", p_object, p_method, p_initial, p_initial_method, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay); return true; @@ -1372,9 +1397,10 @@ bool Tween::targeting_method(Object *p_object, String p_method, Object *p_initia data.elapsed = 0; data.id = p_object->get_instance_id(); - data.key = p_method; + data.key.push_back(p_method); + data.concatenated_key = p_method; data.target_id = p_initial->get_instance_id(); - data.target_key = p_initial_method; + data.target_key.push_back(p_initial_method); data.initial_val = initial_val; data.final_val = p_final_val; data.duration = p_duration; diff --git a/scene/animation/tween.h b/scene/animation/tween.h index fac1d346b4..44710b25f9 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -86,12 +86,13 @@ private: bool call_deferred; real_t elapsed; ObjectID id; - StringName key; + Vector<StringName> key; + StringName concatenated_key; Variant initial_val; Variant delta_val; Variant final_val; ObjectID target_id; - StringName target_key; + Vector<StringName> target_key; real_t duration; TransitionType trans_type; EaseType ease_type; @@ -132,7 +133,7 @@ private: void _tween_process(float p_delta); void _set_process(bool p_process, bool p_force = false); - void _remove(Object *p_object, String p_key, bool first_only); + void _remove(Object *p_object, StringName p_key, bool first_only); protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -156,34 +157,34 @@ public: float get_speed_scale() const; bool start(); - bool reset(Object *p_object, String p_key); + bool reset(Object *p_object, StringName p_key); bool reset_all(); - bool stop(Object *p_object, String p_key); + bool stop(Object *p_object, StringName p_key); bool stop_all(); - bool resume(Object *p_object, String p_key); + bool resume(Object *p_object, StringName p_key); bool resume_all(); - bool remove(Object *p_object, String p_key); + bool remove(Object *p_object, StringName p_key); bool remove_all(); bool seek(real_t p_time); real_t tell() const; real_t get_runtime() const; - bool interpolate_property(Object *p_object, String p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool interpolate_property(Object *p_object, NodePath p_property, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool interpolate_method(Object *p_object, String p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool interpolate_method(Object *p_object, StringName p_method, Variant p_initial_val, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); bool interpolate_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE); bool interpolate_deferred_callback(Object *p_object, real_t p_duration, String p_callback, VARIANT_ARG_DECLARE); - bool follow_property(Object *p_object, String p_property, Variant p_initial_val, Object *p_target, String p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool follow_property(Object *p_object, NodePath p_property, Variant p_initial_val, Object *p_target, NodePath p_target_property, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool follow_method(Object *p_object, String p_method, Variant p_initial_val, Object *p_target, String p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool follow_method(Object *p_object, StringName p_method, Variant p_initial_val, Object *p_target, StringName p_target_method, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool targeting_property(Object *p_object, String p_property, Object *p_initial, String p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool targeting_property(Object *p_object, NodePath p_property, Object *p_initial, NodePath p_initial_property, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); - bool targeting_method(Object *p_object, String p_method, Object *p_initial, String p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); + bool targeting_method(Object *p_object, StringName p_method, Object *p_initial, StringName p_initial_method, Variant p_final_val, real_t p_duration, TransitionType p_trans_type, EaseType p_ease_type, real_t p_delay = 0); Tween(); ~Tween(); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 69dc7b21fe..26ac4c5a7d 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -303,6 +303,8 @@ void TextEdit::_update_scrollbars() { int total_rows = (is_hiding_enabled() ? get_total_unhidden_rows() : text.size()); if (scroll_past_end_of_file_enabled) { total_rows += visible_rows - 1; + } else { + total_rows -= 1; } int vscroll_pixels = v_scroll->get_combined_minimum_size().width; @@ -355,6 +357,10 @@ void TextEdit::_update_scrollbars() { } update_line_scroll_pos(); + if (fabs(v_scroll->get_value() - get_line_scroll_pos()) >= 1) { + cursor.line_ofs += v_scroll->get_value() - get_line_scroll_pos(); + } + } else { cursor.line_ofs = 0; line_scroll_pos = 0; @@ -796,7 +802,9 @@ void TextEdit::_notification(int p_what) { update_line_scroll_pos(); int line = cursor.line_ofs - 1; - for (int i = 0; i < visible_rows; i++) { + // another row may be visible during smooth scrolling + int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0); + for (int i = 0; i < draw_amount; i++) { line++; @@ -3073,7 +3081,7 @@ void TextEdit::_scroll_down(real_t p_delta) { if (smooth_scroll_enabled) { int max_v_scroll = get_total_unhidden_rows(); if (!scroll_past_end_of_file_enabled) { - max_v_scroll -= get_visible_rows(); + max_v_scroll -= get_visible_rows() + 1; max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); } @@ -3114,12 +3122,12 @@ void TextEdit::_scroll_lines_up() { scrolling = false; // adjust the vertical scroll - if (get_v_scroll() > 0) { + if (get_v_scroll() >= 0) { set_v_scroll(get_v_scroll() - 1); } // adjust the cursor - int num_lines = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), get_visible_rows()) - 1; + int num_lines = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), get_visible_rows()); if (cursor.line >= cursor.line_ofs + num_lines && !selection.active) { cursor_set_line(cursor.line_ofs + num_lines, false, false); } @@ -3131,7 +3139,7 @@ void TextEdit::_scroll_lines_down() { // calculate the maximum vertical scroll position int max_v_scroll = get_total_unhidden_rows(); if (!scroll_past_end_of_file_enabled) { - max_v_scroll -= get_visible_rows(); + max_v_scroll -= get_visible_rows() + 1; max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows()); } @@ -3462,23 +3470,27 @@ void TextEdit::adjust_viewport_to_cursor() { visible_width -= 20; // give it a little more space int visible_rows = get_visible_rows(); - if (h_scroll->is_visible_in_tree()) + if (h_scroll->is_visible_in_tree() && !scroll_past_end_of_file_enabled) visible_rows -= ((h_scroll->get_combined_minimum_size().height - 1) / get_row_height()); int num_rows = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), MIN(visible_rows, text.size() - 1 - cursor.line_ofs)); - // if the cursor is off the screen - if (cursor.line >= (cursor.line_ofs + MAX(num_rows, visible_rows))) { - cursor.line_ofs = cursor.line - (num_lines_from(CLAMP(cursor.line, 0, text.size() - 1), -visible_rows) - 1); + // make sure the cursor is on the screen + if (cursor.line > (cursor.line_ofs + MAX(num_rows, visible_rows))) { + cursor.line_ofs = cursor.line - num_lines_from(cursor.line, -visible_rows) + 1; } if (cursor.line < cursor.line_ofs) { cursor.line_ofs = cursor.line; } - - // fixes deleting lines from moving the line ofs in a bad way - if (!scroll_past_end_of_file_enabled && get_total_unhidden_rows() > visible_rows && num_rows < visible_rows) { - cursor.line_ofs = text.size() - 1 - (num_lines_from(text.size() - 1, -visible_rows) - 1); + int line_ofs_max = text.size() - 1; + if (!scroll_past_end_of_file_enabled) { + line_ofs_max -= num_lines_from(text.size() - 1, -visible_rows) - 1; + line_ofs_max += (h_scroll->is_visible_in_tree() ? 1 : 0); + line_ofs_max += (cursor.line == text.size() - 1 ? 1 : 0); } + line_ofs_max = MAX(line_ofs_max, 0); + cursor.line_ofs = CLAMP(cursor.line_ofs, 0, line_ofs_max); + // adjust x offset int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]); if (cursor_x > (cursor.x_ofs + visible_width)) @@ -3487,11 +3499,9 @@ void TextEdit::adjust_viewport_to_cursor() { if (cursor_x < cursor.x_ofs) cursor.x_ofs = cursor_x; + h_scroll->set_value(cursor.x_ofs); update_line_scroll_pos(); - if (get_line_scroll_pos() == 0) - v_scroll->set_value(0); - else - v_scroll->set_value(get_line_scroll_pos() + 1); + v_scroll->set_value(get_line_scroll_pos()); update(); /* get_range()->set_max(text.size()); @@ -3530,6 +3540,7 @@ void TextEdit::center_viewport_to_cursor() { if (cursor_x < cursor.x_ofs) cursor.x_ofs = cursor_x; + h_scroll->set_value(cursor.x_ofs); update_line_scroll_pos(); v_scroll->set_value(get_line_scroll_pos()); @@ -4448,7 +4459,7 @@ int TextEdit::num_lines_from(int p_line_from, int unhidden_amount) const { ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(unhidden_amount)); if (!is_hiding_enabled()) - return unhidden_amount; + return ABS(unhidden_amount); int num_visible = 0; int num_total = 0; if (unhidden_amount >= 0) { diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 01e11962ff..31d423c808 100755..100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2104,37 +2104,59 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const ERR_FAIL_COND_V(!node, NULL); } - List<PropertyInfo> plist; - - get_property_list(&plist); + if (get_filename() != "") { //an instance + node->set_filename(get_filename()); + } StringName script_property_name = CoreStringNames::get_singleton()->_script; - if (p_flags & DUPLICATE_SCRIPTS) { - bool is_valid = false; - Variant script = get(script_property_name, &is_valid); - if (is_valid) { - node->set(script_property_name, script); + List<const Node *> node_tree; + node_tree.push_front(this); + + if (instanced) { + for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) { + for (int i = 0; i < N->get()->get_child_count(); ++i) { + node_tree.push_back(N->get()->get_child(i)); + } } } - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + for (List<const Node *>::Element *N = node_tree.front(); N; N = N->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) - continue; - String name = E->get().name; - if (name == script_property_name) - continue; + Node *current_node = node->get_node(get_path_to(N->get())); - Variant value = get(name); - // Duplicate dictionaries and arrays, mainly needed for __meta__ - if (value.get_type() == Variant::DICTIONARY) { - value = Dictionary(value).copy(); - } else if (value.get_type() == Variant::ARRAY) { - value = Array(value).duplicate(); + if (p_flags & DUPLICATE_SCRIPTS) { + bool is_valid = false; + Variant script = N->get()->get(script_property_name, &is_valid); + if (is_valid) { + current_node->set(script_property_name, script); + } } - node->set(name, value); + List<PropertyInfo> plist; + N->get()->get_property_list(&plist); + + if (!current_node) + continue; + + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + continue; + String name = E->get().name; + if (name == script_property_name) + continue; + + Variant value = N->get()->get(name); + // Duplicate dictionaries and arrays, mainly needed for __meta__ + if (value.get_type() == Variant::DICTIONARY) { + value = Dictionary(value).copy(); + } else if (value.get_type() == Variant::ARRAY) { + value = Array(value).duplicate(); + } + + current_node->set(name, value); + } } node->set_name(get_name()); @@ -2502,24 +2524,19 @@ bool Node::has_node_and_resource(const NodePath &p_path) const { return false; Node *node = get_node(p_path); - if (p_path.get_subname_count()) { + bool result = false; - RES r; - for (int j = 0; j < p_path.get_subname_count(); j++) { - r = j == 0 ? node->get(p_path.get_subname(j)) : r->get(p_path.get_subname(j)); - if (r.is_null()) - return false; - } - } + node->get_indexed(p_path.get_subnames(), &result); - return true; + return result; } Array Node::_get_node_and_resource(const NodePath &p_path) { Node *node; RES res; - node = get_node_and_resource(p_path, res); + Vector<StringName> leftover_path; + node = get_node_and_resource(p_path, res, leftover_path); Array result; if (node) @@ -2532,21 +2549,35 @@ Array Node::_get_node_and_resource(const NodePath &p_path) { else result.push_back(Variant()); + result.push_back(NodePath(Vector<StringName>(), leftover_path, false)); + return result; } -Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res) const { +Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property) const { Node *node = get_node(p_path); r_res = RES(); + r_leftover_subpath = Vector<StringName>(); if (!node) return NULL; if (p_path.get_subname_count()) { - for (int j = 0; j < p_path.get_subname_count(); j++) { - r_res = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); - ERR_FAIL_COND_V(r_res.is_null(), node); + int j = 0; + // If not p_last_is_property, we shouldn't consider the last one as part of the resource + for (; j < p_path.get_subname_count() - p_last_is_property; j++) { + RES new_res = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); + + if (new_res.is_null()) { + break; + } + + r_res = new_res; + } + for (; j < p_path.get_subname_count(); j++) { + // Put the rest of the subpath in the leftover path + r_leftover_subpath.push_back(p_path.get_subname(j)); } } diff --git a/scene/main/node.h b/scene/main/node.h index bd0b18c87a..2b71b71c8d 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -245,7 +245,7 @@ public: Node *get_node(const NodePath &p_path) const; Node *find_node(const String &p_mask, bool p_recursive = true, bool p_owned = true) const; bool has_node_and_resource(const NodePath &p_path) const; - Node *get_node_and_resource(const NodePath &p_path, RES &r_res) const; + Node *get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property = true) const; Node *get_parent() const; _FORCE_INLINE_ SceneTree *get_tree() const { diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 29ac7852bf..657d5f6c80 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "tile_set.h" +#include "array.h" bool TileSet::_set(const StringName &p_name, const Variant &p_value) { @@ -55,7 +56,74 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { tile_set_modulate(id, p_value); else if (what == "region") tile_set_region(id, p_value); - else if (what == "shape") + else if (what == "is_autotile") + tile_set_is_autotile(id, p_value); + else if (what.left(9) == "autotile/") { + what = what.right(9); + if (what == "bitmask_mode") + autotile_set_bitmask_mode(id, (BitmaskMode)((int)p_value)); + else if (what == "icon_coordinate") + autotile_set_icon_coordinate(id, p_value); + else if (what == "tile_size") + autotile_set_size(id, p_value); + else if (what == "spacing") + autotile_set_spacing(id, p_value); + else if (what == "bitmask_flags") { + tile_map[id].autotile_data.flags.clear(); + if (p_value.is_array()) { + Array p = p_value; + Vector2 last_coord; + while (p.size() > 0) { + if (p[0].get_type() == Variant::VECTOR2) { + last_coord = p[0]; + } else if (p[0].get_type() == Variant::INT) { + autotile_set_bitmask(id, last_coord, p[0]); + } + p.pop_front(); + } + } + } else if (what == "occluder_map") { + tile_map[id].autotile_data.ocludder_map.clear(); + Array p = p_value; + Vector2 last_coord; + while (p.size() > 0) { + if (p[0].get_type() == Variant::VECTOR2) { + last_coord = p[0]; + } else if (p[0].get_type() == Variant::OBJECT) { + autotile_set_light_occluder(id, p[0], last_coord); + } + p.pop_front(); + } + } else if (what == "navpoly_map") { + tile_map[id].autotile_data.navpoly_map.clear(); + Array p = p_value; + Vector2 last_coord; + while (p.size() > 0) { + if (p[0].get_type() == Variant::VECTOR2) { + last_coord = p[0]; + } else if (p[0].get_type() == Variant::OBJECT) { + autotile_set_navigation_polygon(id, p[0], last_coord); + } + p.pop_front(); + } + } else if (what == "priority_map") { + tile_map[id].autotile_data.priority_map.clear(); + Array p = p_value; + Vector3 val; + Vector2 v; + int priority; + while (p.size() > 0) { + val = p[0]; + if (val.z > 1) { + v.x = val.x; + v.y = val.y; + priority = (int)val.z; + tile_map[id].autotile_data.priority_map[v] = priority; + } + p.pop_front(); + } + } + } else if (what == "shape") tile_set_shape(id, 0, p_value); else if (what == "shape_offset") tile_set_shape_offset(id, 0, p_value); @@ -105,7 +173,54 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { r_ret = tile_get_modulate(id); else if (what == "region") r_ret = tile_get_region(id); - else if (what == "shape") + else if (what == "is_autotile") + r_ret = tile_get_is_autotile(id); + else if (what.left(9) == "autotile/") { + what = what.right(9); + if (what == "bitmask_mode") + r_ret = autotile_get_bitmask_mode(id); + else if (what == "icon_coordinate") + r_ret = autotile_get_icon_coordinate(id); + else if (what == "tile_size") + r_ret = autotile_get_size(id); + else if (what == "spacing") + r_ret = autotile_get_spacing(id); + else if (what == "bitmask_flags") { + Array p; + for (Map<Vector2, uint16_t>::Element *E = tile_map[id].autotile_data.flags.front(); E; E = E->next()) { + p.push_back(E->key()); + p.push_back(E->value()); + } + r_ret = p; + } else if (what == "occluder_map") { + Array p; + for (Map<Vector2, Ref<OccluderPolygon2D> >::Element *E = tile_map[id].autotile_data.ocludder_map.front(); E; E = E->next()) { + p.push_back(E->key()); + p.push_back(E->value()); + } + r_ret = p; + } else if (what == "navpoly_map") { + Array p; + for (Map<Vector2, Ref<NavigationPolygon> >::Element *E = tile_map[id].autotile_data.navpoly_map.front(); E; E = E->next()) { + p.push_back(E->key()); + p.push_back(E->value()); + } + r_ret = p; + } else if (what == "priority_map") { + Array p; + Vector3 v; + for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.priority_map.front(); E; E = E->next()) { + if (E->value() > 1) { + //Dont save default value + v.x = E->key().x; + v.y = E->key().y; + v.z = E->value(); + p.push_back(v); + } + } + r_ret = p; + } + } else if (what == "shape") r_ret = tile_get_shape(id, 0); else if (what == "shape_offset") r_ret = tile_get_shape_offset(id, 0); @@ -142,6 +257,17 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial")); p_list->push_back(PropertyInfo(Variant::COLOR, pre + "modulate")); p_list->push_back(PropertyInfo(Variant::RECT2, pre + "region")); + p_list->push_back(PropertyInfo(Variant::BOOL, pre + "is_autotile", PROPERTY_HINT_NONE, "")); + if (tile_get_is_autotile(id)) { + p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/bitmask_mode", PROPERTY_HINT_ENUM, "2X2,3X3", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::INT, pre + "autotile/spacing", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/bitmask_flags", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); + } p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "occluder_offset")); p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D")); p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "navigation_offset")); @@ -158,10 +284,25 @@ void TileSet::create_tile(int p_id) { ERR_FAIL_COND(tile_map.has(p_id)); tile_map[p_id] = TileData(); + tile_map[p_id].autotile_data = AutotileData(); + _change_notify(""); + emit_changed(); +} + +void TileSet::autotile_set_bitmask_mode(int p_id, BitmaskMode p_mode) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + tile_map[p_id].autotile_data.bitmask_mode = p_mode; _change_notify(""); emit_changed(); } +TileSet::BitmaskMode TileSet::autotile_get_bitmask_mode(int p_id) const { + + ERR_FAIL_COND_V(!tile_map.has(p_id), BITMASK_2X2); + return tile_map[p_id].autotile_data.bitmask_mode; +} + void TileSet::tile_set_texture(int p_id, const Ref<Texture> &p_texture) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -240,6 +381,152 @@ Rect2 TileSet::tile_get_region(int p_id) const { return tile_map[p_id].region; } +void TileSet::tile_set_is_autotile(int p_id, bool p_is_autotile) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + tile_map[p_id].is_autotile = p_is_autotile; + _change_notify(""); + emit_changed(); +} + +bool TileSet::tile_get_is_autotile(int p_id) const { + + ERR_FAIL_COND_V(!tile_map.has(p_id), false); + return tile_map[p_id].is_autotile; +} + +void TileSet::autotile_set_icon_coordinate(int p_id, Vector2 coord) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + tile_map[p_id].autotile_data.icon_coord = coord; + emit_changed(); +} + +Vector2 TileSet::autotile_get_icon_coordinate(int p_id) const { + + ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); + return tile_map[p_id].autotile_data.icon_coord; +} + +void TileSet::autotile_set_spacing(int p_id, int p_spacing) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + ERR_FAIL_COND(p_spacing < 0); + tile_map[p_id].autotile_data.spacing = p_spacing; + emit_changed(); +} + +int TileSet::autotile_get_spacing(int p_id) const { + + ERR_FAIL_COND_V(!tile_map.has(p_id), 0); + return tile_map[p_id].autotile_data.spacing; +} + +void TileSet::autotile_set_size(int p_id, Size2 p_size) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + ERR_FAIL_COND(p_size.x <= 0 || p_size.y <= 0); + tile_map[p_id].autotile_data.size = p_size; +} + +Size2 TileSet::autotile_get_size(int p_id) const { + + ERR_FAIL_COND_V(!tile_map.has(p_id), Size2()); + return tile_map[p_id].autotile_data.size; +} + +void TileSet::autotile_clear_bitmask_map(int p_id) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + tile_map[p_id].autotile_data.flags.clear(); +} + +void TileSet::autotile_set_subtile_priority(int p_id, const Vector2 &p_coord, int p_priority) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + ERR_FAIL_COND(p_priority <= 0); + tile_map[p_id].autotile_data.priority_map[p_coord] = p_priority; +} + +int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) { + + ERR_FAIL_COND_V(!tile_map.has(p_id), 1); + if (tile_map[p_id].autotile_data.priority_map.has(p_coord)) { + return tile_map[p_id].autotile_data.priority_map[p_coord]; + } + //When not custom priority set return the default value + return 1; +} + +const Map<Vector2, int> &TileSet::autotile_get_priority_map(int p_id) const { + + static Map<Vector2, int> dummy; + ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); + return tile_map[p_id].autotile_data.priority_map; +} + +void TileSet::autotile_set_bitmask(int p_id, Vector2 p_coord, uint16_t p_flag) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + if (p_flag == 0) { + if (tile_map[p_id].autotile_data.flags.has(p_coord)) + tile_map[p_id].autotile_data.flags.erase(p_coord); + } else { + tile_map[p_id].autotile_data.flags[p_coord] = p_flag; + } +} + +uint16_t TileSet::autotile_get_bitmask(int p_id, Vector2 p_coord) { + + ERR_FAIL_COND_V(!tile_map.has(p_id), 0); + if (!tile_map[p_id].autotile_data.flags.has(p_coord)) { + return 0; + } + return tile_map[p_id].autotile_data.flags[p_coord]; +} + +const Map<Vector2, uint16_t> &TileSet::autotile_get_bitmask_map(int p_id) { + + static Map<Vector2, uint16_t> dummy; + ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); + return tile_map[p_id].autotile_data.flags; +} + +Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node, const Vector2 &p_tile_location) { + + ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); + //First try to forward selection to script + if (p_tilemap_node->get_class_name() == "TileMap") { + if (get_script_instance() != NULL) { + if (get_script_instance()->has_method("_forward_subtile_selection")) { + Variant ret = get_script_instance()->call("_forward_subtile_selection", p_id, p_bitmask, p_tilemap_node, p_tile_location); + if (ret.get_type() == Variant::VECTOR2) { + return ret; + } + } + } + } + + List<Vector2> coords; + uint16_t mask; + for (Map<Vector2, uint16_t>::Element *E = tile_map[p_id].autotile_data.flags.front(); E; E = E->next()) { + mask = E->get(); + if (tile_map[p_id].autotile_data.bitmask_mode == BITMASK_2X2) { + mask &= (BIND_BOTTOMLEFT | BIND_BOTTOMRIGHT | BIND_TOPLEFT | BIND_TOPRIGHT); + } + if (mask == p_bitmask) { + for (int i = 0; i < autotile_get_subtile_priority(p_id, E->key()); i++) { + coords.push_back(E->key()); + } + } + } + if (coords.size() == 0) { + return autotile_get_icon_coordinate(p_id); + } else { + return coords[Math::random(0, (int)coords.size())]; + } +} + void TileSet::tile_set_name(int p_id, const String &p_name) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -257,7 +544,7 @@ void TileSet::tile_clear_shapes(int p_id) { tile_map[p_id].shapes_data.clear(); } -void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way) { +void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way, const Vector2 &p_autotile_coord) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -265,15 +552,17 @@ void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transf new_data.shape = p_shape; new_data.shape_transform = p_transform; new_data.one_way_collision = p_one_way; + new_data.autotile_coord = p_autotile_coord; tile_map[p_id].shapes_data.push_back(new_data); -}; +} + int TileSet::tile_get_shape_count(int p_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), 0); return tile_map[p_id].shapes_data.size(); -}; +} void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape) { @@ -351,6 +640,26 @@ Ref<OccluderPolygon2D> TileSet::tile_get_light_occluder(int p_id) const { return tile_map[p_id].occluder; } +void TileSet::autotile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder, const Vector2 &p_coord) { + ERR_FAIL_COND(!tile_map.has(p_id)); + if (p_light_occluder.is_null()) { + if (tile_map[p_id].autotile_data.ocludder_map.has(p_coord)) { + tile_map[p_id].autotile_data.ocludder_map.erase(p_coord); + } + } else { + tile_map[p_id].autotile_data.ocludder_map[p_coord] = p_light_occluder; + } +} + +Ref<OccluderPolygon2D> TileSet::autotile_get_light_occluder(int p_id, const Vector2 &p_coord) const { + ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<OccluderPolygon2D>()); + if (!tile_map[p_id].autotile_data.ocludder_map.has(p_coord)) { + return Ref<OccluderPolygon2D>(); + } else { + return tile_map[p_id].autotile_data.ocludder_map[p_coord]; + } +} + void TileSet::tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -358,6 +667,7 @@ void TileSet::tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offs } Vector2 TileSet::tile_get_navigation_polygon_offset(int p_id) const { + ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); return tile_map[p_id].navigation_polygon_offset; } @@ -374,6 +684,42 @@ Ref<NavigationPolygon> TileSet::tile_get_navigation_polygon(int p_id) const { return tile_map[p_id].navigation_polygon; } +const Map<Vector2, Ref<OccluderPolygon2D> > &TileSet::autotile_get_light_oclusion_map(int p_id) const { + + static Map<Vector2, Ref<OccluderPolygon2D> > dummy; + ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); + return tile_map[p_id].autotile_data.ocludder_map; +} + +void TileSet::autotile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon, const Vector2 &p_coord) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + if (p_navigation_polygon.is_null()) { + if (tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) { + tile_map[p_id].autotile_data.navpoly_map.erase(p_coord); + } + } else { + tile_map[p_id].autotile_data.navpoly_map[p_coord] = p_navigation_polygon; + } +} + +Ref<NavigationPolygon> TileSet::autotile_get_navigation_polygon(int p_id, const Vector2 &p_coord) const { + + ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<NavigationPolygon>()); + if (!tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) { + return Ref<NavigationPolygon>(); + } else { + return tile_map[p_id].autotile_data.navpoly_map[p_coord]; + } +} + +const Map<Vector2, Ref<NavigationPolygon> > &TileSet::autotile_get_navigation_map(int p_id) const { + + static Map<Vector2, Ref<NavigationPolygon> > dummy; + ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); + return tile_map[p_id].autotile_data.navpoly_map; +} + void TileSet::tile_set_occluder_offset(int p_id, const Vector2 &p_offset) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -381,6 +727,7 @@ void TileSet::tile_set_occluder_offset(int p_id, const Vector2 &p_offset) { } Vector2 TileSet::tile_get_occluder_offset(int p_id) const { + ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); return tile_map[p_id].occluder_offset; } @@ -405,6 +752,7 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { Vector<ShapeData> shapes_data; Transform2D default_transform = tile_get_shape_transform(p_id, 0); bool default_one_way = tile_get_shape_one_way(p_id, 0); + Vector2 default_autotile_coord = Vector2(); for (int i = 0; i < p_shapes.size(); i++) { ShapeData s = ShapeData(); @@ -415,6 +763,7 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { s.shape = shape; s.shape_transform = default_transform; s.one_way_collision = default_one_way; + s.autotile_coord = default_autotile_coord; } else if (p_shapes[i].get_type() == Variant::DICTIONARY) { Dictionary d = p_shapes[i]; @@ -435,6 +784,11 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { else s.one_way_collision = default_one_way; + if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2) + s.autotile_coord = d["autotile_coord"]; + else + s.autotile_coord = default_autotile_coord; + } else { ERR_EXPLAIN("Expected an array of objects or dictionaries for tile_set_shapes"); ERR_CONTINUE(true); @@ -457,6 +811,7 @@ Array TileSet::_tile_get_shapes(int p_id) const { shape_data["shape"] = data[i].shape; shape_data["shape_transform"] = data[i].shape_transform; shape_data["one_way"] = data[i].one_way_collision; + shape_data["autotile_coord"] = data[i].autotile_coord; arr.push_back(shape_data); } @@ -487,6 +842,21 @@ bool TileSet::has_tile(int p_id) const { return tile_map.has(p_id); } +bool TileSet::is_tile_bound(int p_drawn_id, int p_neighbor_id) { + + if (p_drawn_id == p_neighbor_id) { + return true; + } else if (get_script_instance() != NULL) { + if (get_script_instance()->has_method("_is_tile_bound")) { + Variant ret = get_script_instance()->call("_is_tile_bound", p_drawn_id, p_neighbor_id); + if (ret.get_type() == Variant::BOOL) { + return ret; + } + } + } + return false; +} + void TileSet::remove_tile(int p_id) { ERR_FAIL_COND(!tile_map.has(p_id)); @@ -523,6 +893,8 @@ void TileSet::clear() { void TileSet::_bind_methods() { ClassDB::bind_method(D_METHOD("create_tile", "id"), &TileSet::create_tile); + ClassDB::bind_method(D_METHOD("autotile_set_bitmask_mode", "mode"), &TileSet::autotile_set_bitmask_mode); + ClassDB::bind_method(D_METHOD("autotile_get_bitmask_mode"), &TileSet::autotile_get_bitmask_mode); ClassDB::bind_method(D_METHOD("tile_set_name", "id", "name"), &TileSet::tile_set_name); ClassDB::bind_method(D_METHOD("tile_get_name", "id"), &TileSet::tile_get_name); ClassDB::bind_method(D_METHOD("tile_set_texture", "id", "texture"), &TileSet::tile_set_texture); @@ -559,6 +931,21 @@ void TileSet::_bind_methods() { ClassDB::bind_method(D_METHOD("get_last_unused_tile_id"), &TileSet::get_last_unused_tile_id); ClassDB::bind_method(D_METHOD("find_tile_by_name", "name"), &TileSet::find_tile_by_name); ClassDB::bind_method(D_METHOD("get_tiles_ids"), &TileSet::_get_tiles_ids); + + BIND_VMETHOD(MethodInfo("_is_tile_bound", PropertyInfo(Variant::INT, "drawn_id"), PropertyInfo(Variant::INT, "neighbor_id"))); + BIND_VMETHOD(MethodInfo("_forward_subtile_selection", PropertyInfo(Variant::INT, "autotile_id"), PropertyInfo(Variant::INT, "bitmask"), PropertyInfo(Variant::OBJECT, "tilemap", PROPERTY_HINT_NONE, "TileMap"), PropertyInfo(Variant::VECTOR2, "tile_location"))); + + BIND_ENUM_CONSTANT(BITMASK_2X2); + BIND_ENUM_CONSTANT(BITMASK_3X3); + + BIND_ENUM_CONSTANT(BIND_TOPLEFT); + BIND_ENUM_CONSTANT(BIND_TOP); + BIND_ENUM_CONSTANT(BIND_TOPRIGHT); + BIND_ENUM_CONSTANT(BIND_LEFT); + BIND_ENUM_CONSTANT(BIND_RIGHT); + BIND_ENUM_CONSTANT(BIND_BOTTOMLEFT); + BIND_ENUM_CONSTANT(BIND_BOTTOM); + BIND_ENUM_CONSTANT(BIND_BOTTOMRIGHT); } TileSet::TileSet() { diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 3ef3f00cef..18b62c778d 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -30,6 +30,7 @@ #ifndef TILE_SET_H #define TILE_SET_H +#include "core/array.h" #include "resource.h" #include "scene/2d/light_occluder_2d.h" #include "scene/2d/navigation_polygon.h" @@ -44,6 +45,7 @@ public: struct ShapeData { Ref<Shape2D> shape; Transform2D shape_transform; + Vector2 autotile_coord; bool one_way_collision; ShapeData() { @@ -51,6 +53,40 @@ public: } }; + enum BitmaskMode { + BITMASK_2X2, + BITMASK_3X3 + }; + + enum AutotileBindings { + BIND_TOPLEFT = 1, + BIND_TOP = 2, + BIND_TOPRIGHT = 4, + BIND_LEFT = 8, + BIND_CENTER = 16, + BIND_RIGHT = 32, + BIND_BOTTOMLEFT = 64, + BIND_BOTTOM = 128, + BIND_BOTTOMRIGHT = 256 + }; + + struct AutotileData { + BitmaskMode bitmask_mode; + int spacing; + Size2 size; + Vector2 icon_coord; + Map<Vector2, uint16_t> flags; + Map<Vector2, Ref<OccluderPolygon2D> > ocludder_map; + Map<Vector2, Ref<NavigationPolygon> > navpoly_map; + Map<Vector2, int> priority_map; + + // Default size to prevent invalid value + explicit AutotileData() + : size(64, 64), icon_coord(0, 0) { + bitmask_mode = BITMASK_2X2; + } + }; + private: struct TileData { @@ -66,10 +102,12 @@ private: Ref<NavigationPolygon> navigation_polygon; Ref<ShaderMaterial> material; Color modulate; + bool is_autotile; + AutotileData autotile_data; // Default modulate for back-compat explicit TileData() - : modulate(1, 1, 1) {} + : modulate(1, 1, 1), is_autotile(false) {} }; Map<int, TileData> tile_map; @@ -87,6 +125,9 @@ protected: public: void create_tile(int p_id); + void autotile_set_bitmask_mode(int p_id, BitmaskMode p_mode); + BitmaskMode autotile_get_bitmask_mode(int p_id) const; + void tile_set_name(int p_id, const String &p_name); String tile_get_name(int p_id) const; @@ -102,6 +143,28 @@ public: void tile_set_region(int p_id, const Rect2 &p_region); Rect2 tile_get_region(int p_id) const; + void tile_set_is_autotile(int p_id, bool p_is_autotile); + bool tile_get_is_autotile(int p_id) const; + + void autotile_set_icon_coordinate(int p_id, Vector2 coord); + Vector2 autotile_get_icon_coordinate(int p_id) const; + + void autotile_set_spacing(int p_id, int p_spacing); + int autotile_get_spacing(int p_id) const; + + void autotile_set_size(int p_id, Size2 p_size); + Size2 autotile_get_size(int p_id) const; + + void autotile_clear_bitmask_map(int p_id); + void autotile_set_subtile_priority(int p_id, const Vector2 &p_coord, int p_priority); + int autotile_get_subtile_priority(int p_id, const Vector2 &p_coord); + const Map<Vector2, int> &autotile_get_priority_map(int p_id) const; + + void autotile_set_bitmask(int p_id, Vector2 p_coord, uint16_t p_flag); + uint16_t autotile_get_bitmask(int p_id, Vector2 p_coord); + const Map<Vector2, uint16_t> &autotile_get_bitmask_map(int p_id); + Vector2 autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node = NULL, const Vector2 &p_tile_location = Vector2()); + void tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape); Ref<Shape2D> tile_get_shape(int p_id, int p_shape_id) const; @@ -115,7 +178,7 @@ public: bool tile_get_shape_one_way(int p_id, int p_shape_id) const; void tile_clear_shapes(int p_id); - void tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way = false); + void tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way = false, const Vector2 &p_autotile_coord = Vector2()); int tile_get_shape_count(int p_id) const; void tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes); @@ -133,16 +196,26 @@ public: void tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder); Ref<OccluderPolygon2D> tile_get_light_occluder(int p_id) const; + void autotile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder, const Vector2 &p_coord); + Ref<OccluderPolygon2D> autotile_get_light_occluder(int p_id, const Vector2 &p_coord) const; + const Map<Vector2, Ref<OccluderPolygon2D> > &autotile_get_light_oclusion_map(int p_id) const; + void tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset); Vector2 tile_get_navigation_polygon_offset(int p_id) const; void tile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon); Ref<NavigationPolygon> tile_get_navigation_polygon(int p_id) const; + void autotile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon, const Vector2 &p_coord); + Ref<NavigationPolygon> autotile_get_navigation_polygon(int p_id, const Vector2 &p_coord) const; + const Map<Vector2, Ref<NavigationPolygon> > &autotile_get_navigation_map(int p_id) const; + void remove_tile(int p_id); bool has_tile(int p_id) const; + bool is_tile_bound(int p_drawn_id, int p_neighbor_id); + int find_tile_by_name(const String &p_name) const; void get_tile_list(List<int> *p_tiles) const; @@ -153,4 +226,7 @@ public: TileSet(); }; +VARIANT_ENUM_CAST(TileSet::AutotileBindings); +VARIANT_ENUM_CAST(TileSet::BitmaskMode); + #endif // TILE_SET_H |
