Peoplemon  0.1.0
Peoplemon 3 game source documentation
RunWalkAnimations.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/FileUtil.hpp>
4 
5 namespace core
6 {
7 namespace res
8 {
9 bool RunWalkAnimations::loadFromDirectory(const std::string& path) {
10  using AnimationManager = bl::resource::ResourceManager<bl::gfx::a2d::AnimationData>;
12 
13  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Walk/up.anim"), *this)) {
14  return false;
15  }
16  maxLen = getLength();
17 
18  prepareForStates(8);
19  bl::gfx::a2d::AnimationData temp;
20  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Walk/right.anim"), temp)) {
21  return false;
22  }
23  maxLen = std::max(maxLen, temp.getLength());
24  addState(1, temp);
25 
26  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Walk/down.anim"), temp)) {
27  return false;
28  }
29  maxLen = std::max(maxLen, temp.getLength());
30  addState(2, temp);
31 
32  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Walk/left.anim"), temp)) {
33  return false;
34  }
35  maxLen = std::max(maxLen, temp.getLength());
36  addState(3, temp);
37 
38  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Run/up.anim"), temp)) {
39  return false;
40  }
41  maxLen = std::max(maxLen, temp.getLength());
42  addState(4, temp);
43 
44  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Run/right.anim"), temp)) {
45  return false;
46  }
47  maxLen = std::max(maxLen, temp.getLength());
48  addState(5, temp);
49 
50  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Run/down.anim"), temp)) {
51  return false;
52  }
53  maxLen = std::max(maxLen, temp.getLength());
54  addState(6, temp);
55 
56  if (!AnimationManager::initializeExisting(FileUtil::joinPath(path, "Run/left.anim"), temp)) {
57  return false;
58  }
59  maxLen = std::max(maxLen, temp.getLength());
60  addState(7, temp);
61 
62  return true;
63 }
64 
65 bool RunWalkAnimationLoader::load(const std::string& path, const char*, std::size_t, std::istream&,
66  RunWalkAnimations& result) {
67  return result.loadFromDirectory(path);
68 }
69 
70 } // namespace res
71 } // namespace core
bl::resource::ResourceManager< bl::gfx::a2d::AnimationData > AnimationManager
Definition: Resources.hpp:20
Core classes and functionality for both the editor and game.
bl::util::FileUtil FileUtil
Extension of animation data that loads and combines the animations for each movement direction into a...
bool loadFromDirectory(const std::string &path)
Loads the walking animations from the given directory.
virtual bool load(const std::string &path, const char *, std::size_t, std::istream &, RunWalkAnimations &result) override
Loads the walking animations from the given path.