1 /*
2  * Copyright (c) 2024 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_track_component.h>
17 
18 #include "ComponentTools/base_manager.h"
19 #include "ComponentTools/base_manager.inl"
20 
21 #define IMPLEMENT_MANAGER
22 #include "PropertyTools/property_macros.h"
23 
24 CORE_BEGIN_NAMESPACE()
25 using CORE3D_NS::AnimationTrackComponent;
26 DECLARE_PROPERTY_TYPE(AnimationTrackComponent::Interpolation);
27 
28 BEGIN_ENUM(AnimationInterpolationMetaData, AnimationTrackComponent::Interpolation)
29 DECL_ENUM(AnimationTrackComponent::Interpolation, STEP, "Step")
30 DECL_ENUM(AnimationTrackComponent::Interpolation, LINEAR, "Linear")
31 DECL_ENUM(AnimationTrackComponent::Interpolation, SPLINE, "Spline")
32 END_ENUM(AnimationInterpolationMetaData, AnimationTrackComponent::Interpolation)
33 CORE_END_NAMESPACE()
34 
35 CORE3D_BEGIN_NAMESPACE()
36 using BASE_NS::array_view;
37 using BASE_NS::countof;
38 
39 using CORE_NS::BaseManager;
40 using CORE_NS::IComponentManager;
41 using CORE_NS::IEcs;
42 using CORE_NS::Property;
43 
44 class AnimationTrackComponentManager final
45     : public BaseManager<AnimationTrackComponent, IAnimationTrackComponentManager> {
46     BEGIN_PROPERTY(AnimationTrackComponent, ComponentMetadata)
47 #include <3d/ecs/components/animation_track_component.h>
48     END_PROPERTY();
49     const array_view<const Property> ComponentMetaData { ComponentMetadata, countof(ComponentMetadata) };
50 
51 public:
AnimationTrackComponentManager(IEcs & ecs)52     explicit AnimationTrackComponentManager(IEcs& ecs)
53         : BaseManager<AnimationTrackComponent, IAnimationTrackComponentManager>(
54               ecs, CORE_NS::GetName<AnimationTrackComponent>())
55     {}
56 
57     ~AnimationTrackComponentManager() = default;
58 
PropertyCount() const59     size_t PropertyCount() const override
60     {
61         return ComponentMetaData.size();
62     }
63 
MetaData(size_t index) const64     const Property* MetaData(size_t index) const override
65     {
66         if (index < ComponentMetaData.size()) {
67             return &ComponentMetaData[index];
68         }
69         return nullptr;
70     }
71 
MetaData() const72     array_view<const Property> MetaData() const override
73     {
74         return ComponentMetaData;
75     }
76 };
77 
IAnimationTrackComponentManagerInstance(IEcs & ecs)78 IComponentManager* IAnimationTrackComponentManagerInstance(IEcs& ecs)
79 {
80     return new AnimationTrackComponentManager(ecs);
81 }
82 
IAnimationTrackComponentManagerDestroy(IComponentManager * instance)83 void IAnimationTrackComponentManagerDestroy(IComponentManager* instance)
84 {
85     delete static_cast<AnimationTrackComponentManager*>(instance);
86 }
87 CORE3D_END_NAMESPACE()
88