Peoplemon  0.1.0
Peoplemon 3 game source documentation
Loaders.hpp
Go to the documentation of this file.
1 #ifndef CORE_RESOURCES_LOADERS_HPP
2 #define CORE_RESOURCES_LOADERS_HPP
3 
4 #include <BLIB/Resources.hpp>
6 #include <Core/Files/ItemDB.hpp>
7 #include <Core/Files/MoveDB.hpp>
8 #include <Core/Files/NPC.hpp>
10 #include <Core/Files/Trainer.hpp>
11 #include <Core/Maps/Map.hpp>
12 #include <Core/Maps/Tileset.hpp>
13 
14 namespace core
15 {
16 namespace res
17 {
18 enum Mode { Dev, Prod };
19 
28 template<typename T, Mode mode>
29 struct PeoplemonLoader : public bl::resource::LoaderBase<T> {
30  using Ref = typename bl::resource::Ref<T>;
31 
32  virtual bool load(const std::string& path, const char* buffer, std::size_t len, std::istream&,
33  T& result) override {
34  if constexpr (mode == Dev) {
35  // worldmap exceeds git size limit in json so load in binary in dev mode
36  if (path == "Resources/Maps/Maps/WorldMap.map") {
37  bl::serial::MemoryInputBuffer wrapper(buffer, len);
38  bl::serial::binary::InputStream is(wrapper);
39  if (!result.loadProd(is)) {
40  BL_LOG_ERROR << "Failed to load resource: " << path;
41  return false;
42  }
43  }
44  else {
45  bl::util::BufferIstreamBuf buf(const_cast<char*>(buffer), len);
46  std::istream is(&buf);
47  if (!result.loadDev(is)) {
48  BL_LOG_ERROR << "Failed to load resource: " << path;
49  return false;
50  }
51  }
52  }
53  else {
54  bl::serial::MemoryInputBuffer wrapper(buffer, len);
55  bl::serial::binary::InputStream is(wrapper);
56  if (!result.loadProd(is)) {
57  BL_LOG_ERROR << "Failed to load resource: " << path;
58  return false;
59  }
60  }
61  return true;
62  }
63 };
64 
67 
70 
73 
76 
79 
82 
85 
88 
89 } // namespace res
90 } // namespace core
91 
92 #endif
Core classes and functionality for both the editor and game.
Generic resource loader for conforming Peoplemon resource types. Resource types must be default const...
Definition: Loaders.hpp:29
typename bl::resource::Ref< T > Ref
Definition: Loaders.hpp:30
virtual bool load(const std::string &path, const char *buffer, std::size_t len, std::istream &, T &result) override
Definition: Loaders.hpp:32