From 0572346985eef45123a0f25cbd7c295e06bd9097 Mon Sep 17 00:00:00 2001 From: Josh Jones Date: Sat, 17 Dec 2022 20:07:10 -0800 Subject: Fix typo and ensure backwards compatibility for changed property names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes to the name of the `navmesh` and `navpoly` properties on `NavigationRegion` caused navigation data to be lost on load. This PR creates uses `_set`/`_get` to handle compatibility with the older names on load, preserving the data. Also fixes a typo on `get_vertices_per_polygon` in `NavigationMesh`, and renames the property to remove the `polygon_` prefix which doesn't match the setter/getter. Co-authored-by: RĂ©mi Verschelde --- scene/2d/navigation_region_2d.cpp | 19 +++++++++++++++++++ scene/2d/navigation_region_2d.h | 5 +++++ 2 files changed, 24 insertions(+) (limited to 'scene/2d') diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index e030628110..675ef7c780 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -309,6 +309,25 @@ void NavigationRegion2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "travel_cost"), "set_travel_cost", "get_travel_cost"); } +#ifndef DISABLE_DEPRECATED +// Compatibility with earlier 4.0 betas. +bool NavigationRegion2D::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "navpoly") { + set_navigation_polygon(p_value); + return true; + } + return false; +} + +bool NavigationRegion2D::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "navpoly") { + r_ret = get_navigation_polygon(); + return true; + } + return false; +} +#endif // DISABLE_DEPRECATED + NavigationRegion2D::NavigationRegion2D() { set_notify_transform(true); diff --git a/scene/2d/navigation_region_2d.h b/scene/2d/navigation_region_2d.h index 216e6088bc..45029fd95f 100644 --- a/scene/2d/navigation_region_2d.h +++ b/scene/2d/navigation_region_2d.h @@ -50,6 +50,11 @@ protected: void _notification(int p_what); static void _bind_methods(); +#ifndef DISABLE_DEPRECATED + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; +#endif // DISABLE_DEPRECATED + public: #ifdef TOOLS_ENABLED virtual Rect2 _edit_get_rect() const override; -- cgit v1.2.3