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 "PropertyTools/property_macros.h"
23
24 CORE_BEGIN_NAMESPACE()
25 using CORE3D_NS::AnimationComponent;
26 DECLARE_PROPERTY_TYPE(AnimationComponent::PlaybackState);
27
28 BEGIN_ENUM(AnimationPlaybackStateMetaData, AnimationComponent::PlaybackState)
29 DECL_ENUM(AnimationComponent::PlaybackState, STOP, "Stop")
30 DECL_ENUM(AnimationComponent::PlaybackState, PLAY, "Play")
31 DECL_ENUM(AnimationComponent::PlaybackState, PAUSE, "Pause")
32 END_ENUM(AnimationPlaybackStateMetaData, AnimationComponent::PlaybackState)
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 AnimationComponentManager final : public BaseManager<AnimationComponent, IAnimationComponentManager> {
45 BEGIN_PROPERTY(AnimationComponent, ComponentMetadata)
46 #include <3d/ecs/components/animation_component.h>
47 END_PROPERTY();
48 const array_view<const Property> ComponentMetaData { ComponentMetadata, countof(ComponentMetadata) };
49
50 public:
AnimationComponentManager(IEcs & ecs)51 explicit AnimationComponentManager(IEcs& ecs)
52 : BaseManager<AnimationComponent, IAnimationComponentManager>(ecs, CORE_NS::GetName<AnimationComponent>())
53 {}
54
55 ~AnimationComponentManager() = default;
56
PropertyCount() const57 size_t PropertyCount() const override
58 {
59 return ComponentMetaData.size();
60 }
61
MetaData(size_t index) const62 const Property* MetaData(size_t index) const override
63 {
64 if (index < ComponentMetaData.size()) {
65 return &ComponentMetaData[index];
66 }
67 return nullptr;
68 }
69
MetaData() const70 array_view<const Property> MetaData() const override
71 {
72 return ComponentMetaData;
73 }
74 };
75
IAnimationComponentManagerInstance(IEcs & ecs)76 IComponentManager* IAnimationComponentManagerInstance(IEcs& ecs)
77 {
78 return new AnimationComponentManager(ecs);
79 }
80
IAnimationComponentManagerDestroy(IComponentManager * instance)81 void IAnimationComponentManagerDestroy(IComponentManager* instance)
82 {
83 delete static_cast<AnimationComponentManager*>(instance);
84 }
85 CORE3D_END_NAMESPACE()
86