skeleton_modification_3d_stackholder.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*************************************************************************/
  2. /* skeleton_modification_3d_stackholder.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "scene/resources/skeleton_modification_3d_stackholder.h"
  31. #include "scene/3d/skeleton_3d.h"
  32. #include "scene/resources/skeleton_modification_3d.h"
  33. bool SkeletonModification3DStackHolder::_set(const StringName &p_path, const Variant &p_value) {
  34. String path = p_path;
  35. if (path == "held_modification_stack") {
  36. set_held_modification_stack(p_value);
  37. }
  38. return true;
  39. }
  40. bool SkeletonModification3DStackHolder::_get(const StringName &p_path, Variant &r_ret) const {
  41. String path = p_path;
  42. if (path == "held_modification_stack") {
  43. r_ret = get_held_modification_stack();
  44. }
  45. return true;
  46. }
  47. void SkeletonModification3DStackHolder::_get_property_list(List<PropertyInfo> *p_list) const {
  48. p_list->push_back(PropertyInfo(Variant::OBJECT, "held_modification_stack", PROPERTY_HINT_RESOURCE_TYPE, "SkeletonModificationStack3D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE));
  49. }
  50. void SkeletonModification3DStackHolder::_execute(real_t p_delta) {
  51. ERR_FAIL_COND_MSG(!stack || !is_setup || stack->skeleton == nullptr,
  52. "Modification is not setup and therefore cannot execute!");
  53. if (held_modification_stack.is_valid()) {
  54. held_modification_stack->execute(p_delta, execution_mode);
  55. }
  56. }
  57. void SkeletonModification3DStackHolder::_setup_modification(SkeletonModificationStack3D *p_stack) {
  58. stack = p_stack;
  59. if (stack != nullptr) {
  60. is_setup = true;
  61. if (held_modification_stack.is_valid()) {
  62. held_modification_stack->set_skeleton(stack->get_skeleton());
  63. held_modification_stack->setup();
  64. }
  65. }
  66. }
  67. void SkeletonModification3DStackHolder::set_held_modification_stack(Ref<SkeletonModificationStack3D> p_held_stack) {
  68. held_modification_stack = p_held_stack;
  69. if (is_setup && held_modification_stack.is_valid()) {
  70. held_modification_stack->set_skeleton(stack->get_skeleton());
  71. held_modification_stack->setup();
  72. }
  73. }
  74. Ref<SkeletonModificationStack3D> SkeletonModification3DStackHolder::get_held_modification_stack() const {
  75. return held_modification_stack;
  76. }
  77. void SkeletonModification3DStackHolder::_bind_methods() {
  78. ClassDB::bind_method(D_METHOD("set_held_modification_stack", "held_modification_stack"), &SkeletonModification3DStackHolder::set_held_modification_stack);
  79. ClassDB::bind_method(D_METHOD("get_held_modification_stack"), &SkeletonModification3DStackHolder::get_held_modification_stack);
  80. }
  81. SkeletonModification3DStackHolder::SkeletonModification3DStackHolder() {
  82. stack = nullptr;
  83. is_setup = false;
  84. enabled = true;
  85. }
  86. SkeletonModification3DStackHolder::~SkeletonModification3DStackHolder() {
  87. }