FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_animation.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_ANIMATION_HPP_INCLUDED
18#define _FGE_C_ANIMATION_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_rect.hpp"
22#include "FastEngine/manager/C_baseManager.hpp"
23#include "FastEngine/manager/anim_manager.hpp"
24
25namespace fge
26{
27
33class FGE_API Animation : public manager::BaseDataAccessor<
34 manager::GlobalDataAccessorManagerInfo<anim::AnimationManager, &anim::gManager>,
35 manager::DataAccessorOptions::BLOCKPOINTER_ONLY>
36{
37public:
38 using BaseDataAccessor::operator=;
39 using Index = uint16_t;
40
41 Animation() = default;
51 Animation(std::string_view name, Index frame = 0);
62 Animation(std::string_view name, std::string_view group, Index frame = 0);
63 Animation(char const name[], Index frame = 0);
64 Animation(char const name[], char const group[], Index frame = 0);
65 Animation(SharedDataType data, Index frame = 0);
66 Animation(SharedDataType data, std::string_view group, Index frame = 0);
67 Animation(SharedDataType data, char const group[], Index frame = 0);
68
72 void clear() override;
73
79 [[nodiscard]] anim::AnimationType getType() const;
80
87 bool setGroup(std::string_view group);
94 bool setGroup(Index groupIndex);
95
101 [[nodiscard]] anim::AnimationGroup const* getGroup() const;
102 [[nodiscard]] anim::AnimationGroup* getGroup();
109 [[nodiscard]] anim::AnimationGroup const* getGroup(std::string_view group) const;
110 [[nodiscard]] anim::AnimationGroup* getGroup(std::string_view group);
117 [[nodiscard]] anim::AnimationGroup const* getGroup(Index groupIndex) const;
118 [[nodiscard]] anim::AnimationGroup* getGroup(Index groupIndex);
119
125 [[nodiscard]] bool isGroupValid() const;
126
132 Index nextFrame();
138 void setFrame(Index frame);
139
145 [[nodiscard]] Index getFrameIndex() const;
151 [[nodiscard]] Index getGroupIndex() const;
152
158 [[nodiscard]] fge::anim::AnimationFrame const* getFrame() const;
159 [[nodiscard]] fge::anim::AnimationFrame* getFrame();
165 [[nodiscard]] fge::anim::AnimationFrame const* getFrame(Index frameIndex) const;
166 [[nodiscard]] fge::anim::AnimationFrame* getFrame(Index frameIndex);
167
173 [[nodiscard]] bool isFrameValid() const;
174
180 void setLoop(bool active);
186 [[nodiscard]] bool isLoop() const;
187
193 void setReverse(bool active);
199 [[nodiscard]] bool isReverse() const;
200
206 void setHorizontalFlip(bool active);
212 [[nodiscard]] bool isHorizontalFlipped() const;
213
219 [[nodiscard]] std::shared_ptr<fge::TextureType> const& retrieveTexture() const;
220
226 [[nodiscard]] fge::RectInt retrieveTextureRect() const;
227
228private:
229 Index g_groupIndex{0};
230 Index g_frameIndex{0};
231
232 bool g_loop{false};
233 bool g_reverse{false};
234 bool g_flipHorizontal{false};
235};
236
237FGE_API fge::net::Packet const& operator>>(fge::net::Packet const& pck, fge::Animation& data);
238FGE_API fge::net::Packet& operator<<(fge::net::Packet& pck, fge::Animation const& data);
239
240FGE_API void to_json(nlohmann::json& j, fge::Animation const& p);
241FGE_API void from_json(nlohmann::json const& j, fge::Animation& p);
242
243} // namespace fge
244
245#endif // _FGE_C_ANIMATION_HPP_INCLUDED
Class that represent/handle an animation.
Definition C_animation.hpp:36
Index getGroupIndex() const
Get the actual group index of the animation.
Animation(std::string_view name, Index frame=0)
Constructor that takes the name of the animation.
Animation(std::string_view name, std::string_view group, Index frame=0)
Constructor that takes the name of the animation and the group name.
void setLoop(bool active)
Set the loop mode of the animation.
anim::AnimationGroup const * getGroup(std::string_view group) const
Get the group of the animation by its name.
bool isHorizontalFlipped() const
Check if the horizontal flip mode is active.
bool isGroupValid() const
Check if the actual group is valid.
bool isReverse() const
Check if the reverse mode is active.
anim::AnimationType getType() const
Get the type of the loaded animation.
bool setGroup(std::string_view group)
Set the group of the animation by its name.
bool isFrameValid() const
Check if the actual frame is valid.
void setHorizontalFlip(bool active)
Set the horizontal flip mode of the animation.
fge::anim::AnimationFrame const * getFrame() const
Get the actual frame of the animation.
void setReverse(bool active)
Set the reverse mode of the animation.
anim::AnimationGroup const * getGroup(Index groupIndex) const
Get the group of the animation by its index.
bool setGroup(Index groupIndex)
Set the group of the animation by its index.
anim::AnimationGroup const * getGroup() const
Get the actual group of the animation.
Index getFrameIndex() const
Get the actual frame index of the animation.
bool isLoop() const
Check if the loop mode is active.
fge::anim::AnimationFrame const * getFrame(Index frameIndex) const
Get the frame of the animation by its index.
std::shared_ptr< fge::TextureType > const & retrieveTexture() const
Retrieve the texture of the actual frame.
void setFrame(Index frame)
Set the frame of the animation.
Index nextFrame()
Go to the next frame of the animation.
fge::RectInt retrieveTextureRect() const
Get the texture rectangle if the type of the animation is fge::anim::ANIM_TYPE_TILESET of the actual ...
void clear() override
Clear the animation.
Definition C_baseManager.hpp:182
Definition C_packet.hpp:70
AnimationType
Enum that represent different way of loading an animation.
Definition anim_manager.hpp:40
Structure that contains the information of a frame of an animation.
Definition anim_manager.hpp:51
Structure that contains the information of a group of frames of an animation.
Definition anim_manager.hpp:65