#include "player.hpp" #include #include "godot_cpp/classes/animation_tree.hpp" #include "godot_cpp/classes/node3d.hpp" #include "godot_cpp/classes/skeleton3d.hpp" #include "godot_cpp/variant/utility_functions.hpp" #include "godot_macros.h" namespace godot { void Player::_bind_methods() { #define CLASSNAME Player #ifndef NDEBUG GDPROPERTY(selected, Variant::STRING); GDPROPERTY(index, Variant::INT); #endif } void Player::_enter_tree() { this->model = this->get_node("Model"); this->animTree = this->get_node("AnimationTree"); this->customization_init(); } void Player::_exit_tree() { for(std::pair>>& pair: this->customization) { for(Node3D *option: pair.second.second) { if(!option->is_inside_tree()) { option->queue_free(); } } } } void Player::_process(double deltaTime) {} void Player::_physics_process(double deltaTime) {} void Player::customization_init() { customizationParent = this->get_node("Model/RootNode/Skeleton3D"); if(!customizationParent) return; for(int i = 0; i < customizationParent->get_child_count(); ++i) { Node3D *child = Object::cast_to(customizationParent->get_child(i)); if(!child) continue; String name = child->get_name(); PackedStringArray slices = name.split("_", false); if(customization.find(slices[1]) != customization.end()) { auto &array = customization.at(slices[1]); array.second.push_back(child); customizationParent->remove_child(child); --i; } else { customization.insert({slices[1], {0, {child}}}); } } UtilityFunctions::print("customization categories:"); for(std::pair>>& pair: this->customization) { UtilityFunctions::print("- ", pair.first); } } void Player::select_customization(String key, int index) { std::pair> &pair = this->customization.at(key); if(index > pair.second.size()) return; if(index == pair.first) return; customizationParent->remove_child(pair.second[pair.first]); customizationParent->add_child(pair.second[index]); pair.first = index; } #ifndef NDEBUG void Player::set_selected(String value) { this->selected = value; } String Player::get_selected() const { return this->selected; } #endif } // namespace godot