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

Make Skeleton3D::add_bone return the new bone index #88791

Merged
merged 1 commit into from
Feb 26, 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
5 changes: 3 additions & 2 deletions doc/classes/Skeleton3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
</tutorials>
<methods>
<method name="add_bone">
<return type="void" />
<return type="int" />
<param index="0" name="name" type="String" />
<description>
Adds a bone, with name [param name]. [method get_bone_count] will become the bone index.
Adds a new bone with the given name. Returns the new bone's index, or [code]-1[/code] if this method fails.
MajorMcDoom marked this conversation as resolved.
Show resolved Hide resolved
[b]Note:[/b] Bone names should be unique, non empty, and cannot include the [code]:[/code] and [code]/[/code] characters.
</description>
</method>
<method name="clear_bones">
Expand Down
9 changes: 9 additions & 0 deletions misc/extension_api_validation/4.2-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,12 @@ Renamed to EditorSceneFormatImporterFBX2GLTF.
The compat breakage was deemed necessary as this is a class most users wouldn't
use directly, and the name needs to be disambiguated with the new
EditorSceneFormatImporterUFBX.


GH-88791
--------
Validate extension JSON: JSON file: Field was added in a way that breaks compatibility 'classes/Skeleton3D/methods/add_bone': return_value

Added a return value for add_bone.
Should not affect existing regular use - the return value would just be unused.
Compatibility method registered.
41 changes: 41 additions & 0 deletions scene/3d/skeleton_3d.compat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**************************************************************************/
/* skeleton_3d.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

void Skeleton3D::_add_bone_bind_compat_88791(const String &p_name) {
add_bone(p_name);
}

void Skeleton3D::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("add_bone", "p_name"), &Skeleton3D::_add_bone_bind_compat_88791);
}

#endif // DISABLE_DEPRECATED
10 changes: 7 additions & 3 deletions scene/3d/skeleton_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "skeleton_3d.h"
#include "skeleton_3d.compat.inc"

#include "core/variant/type_info.h"
#include "scene/3d/physics_body_3d.h"
Expand Down Expand Up @@ -409,18 +410,21 @@ uint64_t Skeleton3D::get_version() const {
return version;
}

void Skeleton3D::add_bone(const String &p_name) {
ERR_FAIL_COND(p_name.is_empty() || p_name.contains(":") || p_name.contains("/") || name_to_bone_index.has(p_name));
int Skeleton3D::add_bone(const String &p_name) {
ERR_FAIL_COND_V_MSG(p_name.is_empty() || p_name.contains(":") || p_name.contains("/"), -1, vformat("Bone name cannot be empty or contain ':' or '/'.", p_name));
ERR_FAIL_COND_V_MSG(name_to_bone_index.has(p_name), -1, vformat("Skeleton3D \"%s\" already has a bone with name \"%s\".", to_string(), p_name));

Bone b;
b.name = p_name;
bones.push_back(b);
name_to_bone_index.insert(p_name, bones.size() - 1);
int new_idx = bones.size() - 1;
name_to_bone_index.insert(p_name, new_idx);
process_order_dirty = true;
version++;
rest_dirty = true;
_make_dirty();
update_gizmos();
return new_idx;
}

int Skeleton3D::find_bone(const String &p_name) const {
Expand Down
8 changes: 7 additions & 1 deletion scene/3d/skeleton_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class Skeleton3D : public Node3D {

void _update_process_order();

#ifndef DISABLE_DEPRECATED
void _add_bone_bind_compat_88791(const String &p_name);

static void _bind_compatibility_methods();
#endif // DISABLE_DEPRECATED

protected:
bool _get(const StringName &p_path, Variant &r_ret) const;
bool _set(const StringName &p_path, const Variant &p_value);
Expand All @@ -153,7 +159,7 @@ class Skeleton3D : public Node3D {

// skeleton creation api
uint64_t get_version() const;
void add_bone(const String &p_name);
int add_bone(const String &p_name);
int find_bone(const String &p_name) const;
String get_bone_name(int p_bone) const;
void set_bone_name(int p_bone, const String &p_name);
Expand Down
Loading