mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-20 17:14:44 +01:00
Added a new CharacterSkeleton class.
This commit is contained in:
parent
d8c40b6b04
commit
3e89bc37c9
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@
|
||||
*.o
|
||||
*.meta
|
||||
*.obj
|
||||
*.pyc
|
||||
*.pyc
|
||||
*.bc
|
2
SCsub
2
SCsub
@ -60,3 +60,5 @@ module_env.add_source_files(env.modules_sources,"ui/unit_frame.cpp")
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"drag_and_drop/es_drag_and_drop.cpp")
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"skeleton/character_skeleton.cpp")
|
||||
|
||||
|
@ -5,6 +5,26 @@
|
||||
#include "../entities/auras/aura_data.h"
|
||||
#include "../pipelines/spell_damage_info.h"
|
||||
|
||||
NodePath Entity::get_character_skeleton_path() {
|
||||
return _character_skeleton_path;
|
||||
}
|
||||
|
||||
void Entity::set_character_skeleton_path(NodePath value) {
|
||||
_character_skeleton_path = value;
|
||||
|
||||
Node *node = get_node_or_null(_character_skeleton_path);
|
||||
|
||||
if (node != NULL) {
|
||||
_character_skeleton = Object::cast_to<CharacterSkeleton>(node);
|
||||
} else {
|
||||
_character_skeleton = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
CharacterSkeleton *Entity::get_character_skeleton() {
|
||||
return _character_skeleton;
|
||||
}
|
||||
|
||||
int Entity::getc_guid() {
|
||||
return _c_guid;
|
||||
}
|
||||
@ -3446,6 +3466,14 @@ void Entity::_notification(int p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (!Engine::get_singleton()->is_editor_hint())
|
||||
set_process(true);
|
||||
|
||||
Node *node = get_node_or_null(_character_skeleton_path);
|
||||
|
||||
if (node != NULL) {
|
||||
_character_skeleton = Object::cast_to<CharacterSkeleton>(node);
|
||||
} else {
|
||||
_character_skeleton = NULL;
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_PROCESS: {
|
||||
update(get_process_delta_time());
|
||||
@ -3488,6 +3516,10 @@ void Entity::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("ccast_finished", PropertyInfo(Variant::OBJECT, "spell_cast_info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
|
||||
ADD_SIGNAL(MethodInfo("ccast_interrupted", PropertyInfo(Variant::OBJECT, "spell_cast_info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_character_skeleton_path"), &Entity::get_character_skeleton_path);
|
||||
ClassDB::bind_method(D_METHOD("set_character_skeleton_path", "value"), &Entity::set_character_skeleton_path);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "character_skeleton_path"), "set_character_skeleton_path", "get_character_skeleton_path");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("gets_entity_type"), &Entity::gets_entity_type);
|
||||
ClassDB::bind_method(D_METHOD("sets_entity_type", "value"), &Entity::sets_entity_type);
|
||||
@ -3504,6 +3536,7 @@ void Entity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("getc_player_name"), &Entity::getc_player_name);
|
||||
ClassDB::bind_method(D_METHOD("setc_player_name", "value"), &Entity::setc_player_name);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "c_player_name"), "setc_player_name", "getc_player_name");
|
||||
|
||||
|
||||
ClassDB::bind_method(D_METHOD("gets_xp"), &Entity::gets_xp);
|
||||
ClassDB::bind_method(D_METHOD("sets_xp", "value"), &Entity::sets_xp);
|
||||
@ -3544,6 +3577,8 @@ void Entity::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_stat_enum", "index"), &Entity::get_stat_enum);
|
||||
ClassDB::bind_method(D_METHOD("set_stat_enum", "stat_id", "entry"), &Entity::set_stat_enum);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_character_skeleton"), &Entity::get_character_skeleton);
|
||||
|
||||
//// Targeting System ////
|
||||
|
||||
ClassDB::bind_method(D_METHOD("gets_target"), &Entity::gets_target);
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include "../spells/spell_cast_info.h"
|
||||
|
||||
#include "../skeleton/character_skeleton.h"
|
||||
|
||||
class CharacterClass;
|
||||
class AuraData;
|
||||
class Spell;
|
||||
@ -156,6 +158,12 @@ public:
|
||||
|
||||
//// Base ////
|
||||
|
||||
NodePath get_character_skeleton_path();
|
||||
void set_character_skeleton_path(NodePath value);
|
||||
|
||||
CharacterSkeleton *get_character_skeleton();
|
||||
|
||||
|
||||
int getc_guid();
|
||||
void setc_guid(int value);
|
||||
|
||||
@ -534,12 +542,18 @@ public:
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _notification(int p_notification);
|
||||
virtual void _notification(int p_what);
|
||||
virtual void update(float delta);
|
||||
|
||||
private:
|
||||
const float SAVE_BASE_SECONDS = 10.0;
|
||||
|
||||
//// Paths ////
|
||||
|
||||
NodePath _character_skeleton_path;
|
||||
CharacterSkeleton *_character_skeleton;
|
||||
|
||||
|
||||
//// PlayerData ////
|
||||
|
||||
int _s_guid;
|
||||
|
@ -48,6 +48,8 @@
|
||||
|
||||
#include "drag_and_drop/es_drag_and_drop.h"
|
||||
|
||||
#include "skeleton/character_skeleton.h"
|
||||
|
||||
void register_entity_spell_system_types() {
|
||||
|
||||
//data
|
||||
@ -110,6 +112,8 @@ void register_entity_spell_system_types() {
|
||||
ClassDB::register_class<UnitFrame>();
|
||||
|
||||
ClassDB::register_class<ESDragAndDrop>();
|
||||
|
||||
ClassDB::register_class<CharacterSkeleton>();
|
||||
}
|
||||
|
||||
void unregister_entity_spell_system_types() {
|
||||
|
142
skeleton/character_skeleton.cpp
Normal file
142
skeleton/character_skeleton.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
#include "character_skeleton.h"
|
||||
|
||||
const String CharacterSkeleton::BINDING_STRING_CHARCATER_SKELETON_BONE_ID = "Hip, Left Hand, Right Hand";
|
||||
|
||||
|
||||
NodePath CharacterSkeleton::get_hip_path() {
|
||||
return _hip_path;
|
||||
}
|
||||
|
||||
void CharacterSkeleton::set_hip_path(NodePath path) {
|
||||
_hip_path = path;
|
||||
|
||||
_nodes[BONE_ID_HIP] = get_node_or_null(_hip_path);
|
||||
}
|
||||
|
||||
NodePath CharacterSkeleton::get_left_hand_path() {
|
||||
return _left_hand_path;
|
||||
}
|
||||
|
||||
void CharacterSkeleton::set_left_hand_path(NodePath path) {
|
||||
_left_hand_path = path;
|
||||
|
||||
_nodes[BONE_ID_LEFT_HAND] = get_node_or_null(_left_hand_path);
|
||||
}
|
||||
|
||||
NodePath CharacterSkeleton::get_right_hand_path() {
|
||||
return _right_hand_path;
|
||||
}
|
||||
|
||||
void CharacterSkeleton::set_right_hand_path(NodePath path) {
|
||||
_right_hand_path = path;
|
||||
|
||||
_nodes[BONE_ID_RIGHT_HAND] = get_node_or_null(_right_hand_path);
|
||||
}
|
||||
|
||||
Node *CharacterSkeleton::get_bone_node(CharacterSkeletonBoneId node_id) {
|
||||
return _nodes[node_id];
|
||||
}
|
||||
|
||||
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() {
|
||||
_nodes[BONE_ID_HIP] = get_node_or_null(_hip_path);
|
||||
_nodes[BONE_ID_LEFT_HAND] = get_node_or_null(_left_hand_path);
|
||||
_nodes[BONE_ID_RIGHT_HAND] = get_node_or_null(_right_hand_path);
|
||||
|
||||
set_animation_player_path(_animation_player_path);
|
||||
set_animation_tree_path(_animation_tree_path);
|
||||
}
|
||||
|
||||
CharacterSkeleton::CharacterSkeleton() {
|
||||
for (int i = 0; i < MAX_BONE_ID; ++i) {
|
||||
_nodes[i] = NULL;
|
||||
}
|
||||
|
||||
_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() {
|
||||
ClassDB::bind_method(D_METHOD("get_hip_path"), &CharacterSkeleton::get_hip_path);
|
||||
ClassDB::bind_method(D_METHOD("set_hip_path", "path"), &CharacterSkeleton::set_hip_path);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "hip_path"), "set_hip_path", "get_hip_path");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_left_hand_path"), &CharacterSkeleton::get_left_hand_path);
|
||||
ClassDB::bind_method(D_METHOD("set_left_hand_path", "path"), &CharacterSkeleton::set_left_hand_path);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "left_hand_path"), "set_left_hand_path", "get_left_hand_path");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_right_hand_path"), &CharacterSkeleton::get_right_hand_path);
|
||||
ClassDB::bind_method(D_METHOD("set_right_hand_path", "path"), &CharacterSkeleton::set_right_hand_path);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "right_hand_path"), "set_right_hand_path", "get_right_hand_path");
|
||||
|
||||
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);
|
||||
|
||||
BIND_ENUM_CONSTANT(BONE_ID_HIP);
|
||||
BIND_ENUM_CONSTANT(BONE_ID_LEFT_HAND);
|
||||
BIND_ENUM_CONSTANT(BONE_ID_RIGHT_HAND);
|
||||
BIND_ENUM_CONSTANT(MAX_BONE_ID);
|
||||
}
|
82
skeleton/character_skeleton.h
Normal file
82
skeleton/character_skeleton.h
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef CHARACTER_SKELETON_H
|
||||
#define CHARACTER_SKELETON_H
|
||||
|
||||
#ifdef ENTITIES_2D
|
||||
#include "scene/2d/node_2d.h"
|
||||
#else
|
||||
#include "scene/3d/spatial.h"
|
||||
#endif
|
||||
|
||||
#include "core/node_path.h"
|
||||
#include "core/ustring.h"
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "scene/animation/animation_tree.h"
|
||||
|
||||
#ifdef ENTITIES_2D
|
||||
|
||||
class CharacterSkeleton : public Node2D {
|
||||
GDCLASS(CharacterSkeleton, Node2D);
|
||||
|
||||
#else
|
||||
|
||||
class CharacterSkeleton : public Spatial {
|
||||
GDCLASS(CharacterSkeleton, Spatial);
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
static const String BINDING_STRING_CHARCATER_SKELETON_BONE_ID;
|
||||
|
||||
enum CharacterSkeletonBoneId {
|
||||
BONE_ID_HIP = 0,
|
||||
BONE_ID_LEFT_HAND = 1,
|
||||
BONE_ID_RIGHT_HAND = 2,
|
||||
MAX_BONE_ID = 3,
|
||||
};
|
||||
|
||||
NodePath get_hip_path();
|
||||
void set_hip_path(NodePath path);
|
||||
|
||||
NodePath get_left_hand_path();
|
||||
void set_left_hand_path(NodePath path);
|
||||
|
||||
NodePath get_right_hand_path();
|
||||
void set_right_hand_path(NodePath path);
|
||||
|
||||
Node *get_bone_node(CharacterSkeletonBoneId node_id);
|
||||
|
||||
NodePath get_animation_player_path();
|
||||
void set_animation_player_path(NodePath path);
|
||||
|
||||
AnimationPlayer *get_animation_player();
|
||||
|
||||
NodePath get_animation_tree_path();
|
||||
void set_animation_tree_path(NodePath path);
|
||||
|
||||
AnimationTree *get_animation_tree();
|
||||
|
||||
void update_nodes();
|
||||
|
||||
CharacterSkeleton();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _notification(int p_notification);
|
||||
|
||||
private:
|
||||
NodePath _hip_path;
|
||||
NodePath _left_hand_path;
|
||||
NodePath _right_hand_path;
|
||||
|
||||
NodePath _animation_player_path;
|
||||
NodePath _animation_tree_path;
|
||||
|
||||
AnimationPlayer *_animation_player;
|
||||
AnimationTree *_animation_tree;
|
||||
|
||||
Node *_nodes[MAX_BONE_ID];
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CharacterSkeleton::CharacterSkeletonBoneId);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user