2019-05-01 02:49:06 +02:00
|
|
|
#include "character_skeleton.h"
|
|
|
|
|
|
|
|
|
2019-05-13 13:25:03 +02:00
|
|
|
NodePath CharacterSkeleton::get_bone_path(int index) {
|
2019-05-30 00:26:02 +02:00
|
|
|
ERR_FAIL_INDEX_V(index, EntityEnums::SKELETON_POINTS_MAX, NodePath());
|
2019-05-13 13:25:03 +02:00
|
|
|
|
|
|
|
return _bone_paths[index];
|
2019-05-01 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
2019-05-13 13:25:03 +02:00
|
|
|
void CharacterSkeleton::set_bone_path(int index, NodePath path) {
|
2019-05-30 00:26:02 +02:00
|
|
|
ERR_FAIL_INDEX(index, EntityEnums::SKELETON_POINTS_MAX);
|
2019-05-13 13:25:03 +02:00
|
|
|
|
|
|
|
_bone_paths[index] = path;
|
2019-05-01 02:49:06 +02:00
|
|
|
|
2019-05-13 13:25:03 +02:00
|
|
|
_bone_nodes[index] = get_node_or_null(path);
|
2019-05-01 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
2019-05-30 00:26:02 +02:00
|
|
|
Node *CharacterSkeleton::get_bone_node(EntityEnums::CharacterSkeletonPoints node_id) {
|
2019-05-13 13:25:03 +02:00
|
|
|
return _bone_nodes[node_id];
|
2019-05-01 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NodePath CharacterSkeleton::get_animation_player_path() {
|
|
|
|
return _animation_player_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharacterSkeleton::set_animation_player_path(NodePath path) {
|
|
|
|
_animation_player_path = path;
|
|
|
|
|
|
|
|
Node *node = get_node_or_null(_animation_player_path);
|
|
|
|
|
|
|
|
if (node != NULL) {
|
|
|
|
_animation_player = Object::cast_to<AnimationPlayer>(node);
|
|
|
|
} else {
|
|
|
|
_animation_player = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationPlayer *CharacterSkeleton::get_animation_player() {
|
|
|
|
return _animation_player;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodePath CharacterSkeleton::get_animation_tree_path() {
|
|
|
|
return _animation_tree_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharacterSkeleton::set_animation_tree_path(NodePath path) {
|
|
|
|
_animation_tree_path = path;
|
|
|
|
|
|
|
|
Node *node = get_node_or_null(_animation_tree_path);
|
|
|
|
|
|
|
|
if (node != NULL) {
|
|
|
|
_animation_tree = Object::cast_to<AnimationTree>(node);
|
|
|
|
} else {
|
|
|
|
_animation_tree = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationTree *CharacterSkeleton::get_animation_tree() {
|
|
|
|
return _animation_tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharacterSkeleton::update_nodes() {
|
2019-05-30 00:26:02 +02:00
|
|
|
for (int i = 0; i < EntityEnums::SKELETON_POINTS_MAX; ++i) {
|
2019-05-13 13:25:03 +02:00
|
|
|
_bone_nodes[i] = get_node_or_null(_bone_paths[i]);
|
|
|
|
}
|
2019-05-01 02:49:06 +02:00
|
|
|
|
|
|
|
set_animation_player_path(_animation_player_path);
|
|
|
|
set_animation_tree_path(_animation_tree_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
CharacterSkeleton::CharacterSkeleton() {
|
2019-05-30 00:26:02 +02:00
|
|
|
for (int i = 0; i < EntityEnums::SKELETON_POINTS_MAX; ++i) {
|
2019-05-13 13:25:03 +02:00
|
|
|
_bone_nodes[i] = NULL;
|
2019-05-01 02:49:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_animation_player = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharacterSkeleton::_notification(int p_what) {
|
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
update_nodes();
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharacterSkeleton::_bind_methods() {
|
2019-05-13 13:25:03 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_bone_path", "index"), &CharacterSkeleton::get_bone_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bone_path", "index", "path"), &CharacterSkeleton::set_bone_path);
|
2019-05-01 02:49:06 +02:00
|
|
|
|
2019-05-13 13:25:03 +02:00
|
|
|
ADD_GROUP("Bone Paths", "bone_path_");
|
2019-05-30 00:26:02 +02:00
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_hip"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_HIP);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_left_hand"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_LEFT_HAND);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_right_hand"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_RIGHT_HAND);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_weapon"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_WEAPON);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_base"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_BASE);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_body"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_BODY);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_head"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_HEAD);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_right_eye"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_RIGHT_EYE);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "bone_path_left_eye"), "set_bone_path", "get_bone_path", EntityEnums::SKELETON_POINT_LEFT_EYE);
|
2019-05-01 02:49:06 +02:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bone_node", "bone_idx"), &CharacterSkeleton::get_bone_node);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_animation_player_path"), &CharacterSkeleton::get_animation_player_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_animation_player_path", "path"), &CharacterSkeleton::set_animation_player_path);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "animation_player_path"), "set_animation_player_path", "get_animation_player_path");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_animation_tree_path"), &CharacterSkeleton::get_animation_tree_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_animation_tree_path", "path"), &CharacterSkeleton::set_animation_tree_path);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "animation_tree_path"), "set_animation_tree_path", "get_animation_tree_path");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_animation_player"), &CharacterSkeleton::get_animation_player);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_animation_tree"), &CharacterSkeleton::get_animation_tree);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("update_nodes"), &CharacterSkeleton::update_nodes);
|
|
|
|
}
|