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_state_component.h"
17 #include "ComponentTools/base_manager.h"
18 #include "ComponentTools/base_manager.inl"
19 
20 #define IMPLEMENT_MANAGER
21 #include "PropertyTools/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 BEGIN_ENUM(AnimationPlaybackStateMetaData, AnimationComponent::PlaybackState)
32 DECL_ENUM(AnimationComponent::PlaybackState, STOP, "Stop")
33 DECL_ENUM(AnimationComponent::PlaybackState, PLAY, "Play")
34 DECL_ENUM(AnimationComponent::PlaybackState, PAUSE, "Pause")
35 END_ENUM(AnimationPlaybackStateMetaData, AnimationComponent::PlaybackState)
36 
37 BEGIN_ENUM(AnimationStateFlagBitsMetaData, AnimationStateComponent::FlagBits)
38 DECL_ENUM(AnimationStateComponent::FlagBits, MANUAL_PROGRESS, "Update Playback Time Manually.")
39 END_ENUM(AnimationStateFlagBitsMetaData, AnimationStateComponent::FlagBits)
40 CORE_END_NAMESPACE()
41 
42 CORE3D_BEGIN_NAMESPACE()
43 using BASE_NS::array_view;
44 using BASE_NS::countof;
45 
46 using CORE_NS::BaseManager;
47 using CORE_NS::IComponentManager;
48 using CORE_NS::IEcs;
49 using CORE_NS::Property;
50 
51 class AnimationStateComponentManager final
52     : public BaseManager<AnimationStateComponent, IAnimationStateComponentManager> {
53     BEGIN_PROPERTY(AnimationStateComponent, ComponentMetadata)
54 #include "3d/ecs/components/animation_state_component.h"
55     END_PROPERTY();
56     const array_view<const Property> componentMetaData_ { ComponentMetadata, countof(ComponentMetadata) };
57 
58 public:
AnimationStateComponentManager(IEcs & ecs)59     explicit AnimationStateComponentManager(IEcs& ecs)
60         : BaseManager<AnimationStateComponent, IAnimationStateComponentManager>(
61               ecs, CORE_NS::GetName<AnimationStateComponent>())
62     {}
63 
64     ~AnimationStateComponentManager() = default;
65 
PropertyCount() const66     size_t PropertyCount() const override
67     {
68         return componentMetaData_.size();
69     }
70 
MetaData(size_t index) const71     const Property* MetaData(size_t index) const override
72     {
73         if (index < componentMetaData_.size()) {
74             return &componentMetaData_[index];
75         }
76         return nullptr;
77     }
78 
MetaData() const79     array_view<const Property> MetaData() const override
80     {
81         return componentMetaData_;
82     }
83 };
84 
IAnimationStateComponentManagerInstance(IEcs & ecs)85 IComponentManager* IAnimationStateComponentManagerInstance(IEcs& ecs)
86 {
87     return new AnimationStateComponentManager(ecs);
88 }
89 
IAnimationStateComponentManagerDestroy(IComponentManager * instance)90 void IAnimationStateComponentManagerDestroy(IComponentManager* instance)
91 {
92     delete static_cast<AnimationStateComponentManager*>(instance);
93 }
94 CORE3D_END_NAMESPACE()
95