1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "3d/ecs/components/animation_state_component.h"
17 #include "ComponentTools/base_manager.h"
18 #include "ComponentTools/base_manager.inl"
19
20 #define IMPLEMENT_MANAGER
21 #include <core/property_tools/property_macros.h>
22
23 CORE_BEGIN_NAMESPACE()
24 using CORE3D_NS::AnimationComponent;
25 using CORE3D_NS::AnimationStateComponent;
26 DECLARE_PROPERTY_TYPE(AnimationStateComponent::TrackState);
27 DECLARE_PROPERTY_TYPE(BASE_NS::vector<AnimationStateComponent::TrackState>);
28
29 DECLARE_PROPERTY_TYPE(AnimationComponent::PlaybackState);
30
31 ENUM_TYPE_METADATA(
32 AnimationComponent::PlaybackState, ENUM_VALUE(STOP, "Stop"), ENUM_VALUE(PLAY, "Play"), ENUM_VALUE(PAUSE, "Pause"))
33
34 ENUM_TYPE_METADATA(AnimationStateComponent::FlagBits, ENUM_VALUE(MANUAL_PROGRESS, "Update Playback Time Manually."))
35 CORE_END_NAMESPACE()
36
37 CORE3D_BEGIN_NAMESPACE()
38 using BASE_NS::array_view;
39 using BASE_NS::countof;
40
41 using CORE_NS::BaseManager;
42 using CORE_NS::IComponentManager;
43 using CORE_NS::IEcs;
44 using CORE_NS::Property;
45
46 class AnimationStateComponentManager final
47 : public BaseManager<AnimationStateComponent, IAnimationStateComponentManager> {
48 BEGIN_PROPERTY(AnimationStateComponent, componentMetaData_)
49 #include "3d/ecs/components/animation_state_component.h"
50 END_PROPERTY();
51
52 public:
AnimationStateComponentManager(IEcs & ecs)53 explicit AnimationStateComponentManager(IEcs& ecs)
54 : BaseManager<AnimationStateComponent, IAnimationStateComponentManager>(
55 ecs, CORE_NS::GetName<AnimationStateComponent>())
56 {}
57
58 ~AnimationStateComponentManager() = default;
59
PropertyCount() const60 size_t PropertyCount() const override
61 {
62 return BASE_NS::countof(componentMetaData_);
63 }
64
MetaData(size_t index) const65 const Property* MetaData(size_t index) const override
66 {
67 if (index < BASE_NS::countof(componentMetaData_)) {
68 return &componentMetaData_[index];
69 }
70 return nullptr;
71 }
72
MetaData() const73 array_view<const Property> MetaData() const override
74 {
75 return componentMetaData_;
76 }
77 };
78
IAnimationStateComponentManagerInstance(IEcs & ecs)79 IComponentManager* IAnimationStateComponentManagerInstance(IEcs& ecs)
80 {
81 return new AnimationStateComponentManager(ecs);
82 }
83
IAnimationStateComponentManagerDestroy(IComponentManager * instance)84 void IAnimationStateComponentManagerDestroy(IComponentManager* instance)
85 {
86 delete static_cast<AnimationStateComponentManager*>(instance);
87 }
88 CORE3D_END_NAMESPACE()
89