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_component.h>
17
18 #include "ComponentTools/base_manager.h"
19 #include "ComponentTools/base_manager.inl"
20
21 #define IMPLEMENT_MANAGER
22 #include <core/property_tools/property_macros.h>
23
24 CORE_BEGIN_NAMESPACE()
25 using CORE3D_NS::AnimationComponent;
26 DECLARE_PROPERTY_TYPE(AnimationComponent::PlaybackState);
27
28 ENUM_TYPE_METADATA(
29 AnimationComponent::PlaybackState, ENUM_VALUE(STOP, "Stop"), ENUM_VALUE(PLAY, "Play"), ENUM_VALUE(PAUSE, "Pause"))
30 CORE_END_NAMESPACE()
31
32 CORE3D_BEGIN_NAMESPACE()
33 using BASE_NS::array_view;
34 using BASE_NS::countof;
35
36 using CORE_NS::BaseManager;
37 using CORE_NS::IComponentManager;
38 using CORE_NS::IEcs;
39 using CORE_NS::Property;
40
41 class AnimationComponentManager final : public BaseManager<AnimationComponent, IAnimationComponentManager> {
42 BEGIN_PROPERTY(AnimationComponent, componentMetaData_)
43 #include <3d/ecs/components/animation_component.h>
44 END_PROPERTY();
45
46 public:
AnimationComponentManager(IEcs & ecs)47 explicit AnimationComponentManager(IEcs& ecs)
48 : BaseManager<AnimationComponent, IAnimationComponentManager>(ecs, CORE_NS::GetName<AnimationComponent>(), 0U)
49 {}
50
51 ~AnimationComponentManager() = default;
52
PropertyCount() const53 size_t PropertyCount() const override
54 {
55 return BASE_NS::countof(componentMetaData_);
56 }
57
MetaData(size_t index) const58 const Property* MetaData(size_t index) const override
59 {
60 if (index < BASE_NS::countof(componentMetaData_)) {
61 return &componentMetaData_[index];
62 }
63 return nullptr;
64 }
65
MetaData() const66 array_view<const Property> MetaData() const override
67 {
68 return componentMetaData_;
69 }
70 };
71
IAnimationComponentManagerInstance(IEcs & ecs)72 IComponentManager* IAnimationComponentManagerInstance(IEcs& ecs)
73 {
74 return new AnimationComponentManager(ecs);
75 }
76
IAnimationComponentManagerDestroy(IComponentManager * instance)77 void IAnimationComponentManagerDestroy(IComponentManager* instance)
78 {
79 delete static_cast<AnimationComponentManager*>(instance);
80 }
81 CORE3D_END_NAMESPACE()
82