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 #ifndef CORE_ANIMATION_PLAYBACK_H
17 #define CORE_ANIMATION_PLAYBACK_H
18 
19 #include <3d/ecs/components/animation_component.h>
20 #include <3d/ecs/systems/intf_animation_system.h>
21 #include <base/containers/array_view.h>
22 #include <core/ecs/entity.h>
23 #include <core/namespace.h>
24 
25 CORE3D_BEGIN_NAMESPACE()
26 class IAnimationComponentManager;
27 class IAnimationStateComponentManager;
28 class INameComponentManager;
29 
30 class AnimationPlayback final : public IAnimationPlayback {
31 public:
32     AnimationPlayback(const CORE_NS::Entity animationEntity,
33         const BASE_NS::array_view<const CORE_NS::Entity> targetEntities, CORE_NS::IEcs& ecs);
34     ~AnimationPlayback() override;
35 
36     BASE_NS::string_view GetName() const override;
37 
38     void SetPlaybackState(AnimationComponent::PlaybackState state) override;
39     AnimationComponent::PlaybackState GetPlaybackState() const override;
40 
41     void SetRepeatCount(uint32_t repeatCount) override;
42     uint32_t GetRepeatCount() const override;
43 
44     void SetWeight(float weight) override;
45     float GetWeight() const override;
46 
47     void SetTimePosition(float timePosition) override;
48     float GetTimePosition() const override;
49 
50     float GetAnimationLength() const override;
51 
52     void SetStartOffset(float startOffset) override;
53     float GetStartOffset() const override;
54 
55     void SetDuration(float duration) override;
56     float GetDuration() const override;
57 
58     bool IsCompleted() const override;
59 
60     void SetSpeed(float speed) override;
61 
62     float GetSpeed() const override;
63 
64     CORE_NS::Entity GetEntity() const override;
65 
66 private:
67     // Animation resource.
68     CORE_NS::Entity animation_;
69 
70     CORE_NS::IEcs& ecs_;
71 
72     IAnimationComponentManager* animationManager_ { nullptr };
73     IAnimationStateComponentManager* animationStateManager_ { nullptr };
74     INameComponentManager* nameManager_ { nullptr };
75 };
76 CORE3D_END_NAMESPACE()
77 
78 #endif // CORE_ANIMATION_PLAYBACK_H
79