Peoplemon  0.1.0
Peoplemon 3 game source documentation
ItemDB.hpp
Go to the documentation of this file.
1 #ifndef CORE_FILES_ITEMDB_HPP
2 #define CORE_FILES_ITEMDB_HPP
3 
4 #include <BLIB/Resources.hpp>
5 #include <BLIB/Serialization.hpp>
6 #include <BLIB/Util/NonCopyable.hpp>
8 #include <Core/Items/Id.hpp>
9 #include <Core/Items/Type.hpp>
10 #include <cstdint>
11 #include <string>
12 #include <unordered_map>
13 
14 namespace core
15 {
16 namespace file
17 {
24 struct ItemDB : private bl::util::NonCopyable {
30  bool load();
31 
38  bool loadDev(std::istream& input);
39 
46  bool loadProd(bl::serial::binary::InputStream& input);
47 
53  bool save() const;
54 
62  bool saveBundle(bl::serial::binary::OutputStream& output,
63  bl::resource::bundle::FileHandlerContext& ctx) const;
64 
65  std::unordered_map<item::Id, std::string> names;
66  std::unordered_map<item::Id, std::string> descriptions;
67  std::unordered_map<item::Id, std::int32_t> values;
68 };
69 
70 } // namespace file
71 } // namespace core
72 
73 namespace bl
74 {
75 namespace serial
76 {
77 template<>
78 struct SerializableObject<core::file::ItemDB> : public SerializableObjectBase {
79  using Id = core::item::Id;
81 
82  SerializableField<1, DB, std::unordered_map<Id, std::string>> names;
83  SerializableField<2, DB, std::unordered_map<Id, std::string>> descriptions;
84  SerializableField<3, DB, std::unordered_map<Id, std::int32_t>> values;
85 
87  : SerializableObjectBase("ItemDB")
88  , names("names", *this, &DB::names, SerializableFieldBase::Required{})
89  , descriptions("descriptions", *this, &DB::descriptions, SerializableFieldBase::Required{})
90  , values("values", *this, &DB::values, SerializableFieldBase::Required{}) {}
91 };
92 
93 } // namespace serial
94 } // namespace bl
95 
96 #endif
Id
Represents an item in its simplist form.
Definition: Id.hpp:24
Core classes and functionality for both the editor and game.
Loads and stores metadata surrounding items in the game.
Definition: ItemDB.hpp:24
bool loadProd(bl::serial::binary::InputStream &input)
Loads the database from its json format.
Definition: ItemDB.cpp:19
bool save() const
Writes the item metadata to the data file.
Definition: ItemDB.cpp:23
bool saveBundle(bl::serial::binary::OutputStream &output, bl::resource::bundle::FileHandlerContext &ctx) const
Saves the data from this object to the given bundle and registers depency files if any.
Definition: ItemDB.cpp:28
std::unordered_map< item::Id, std::string > names
Definition: ItemDB.hpp:65
std::unordered_map< item::Id, std::string > descriptions
Definition: ItemDB.hpp:66
std::unordered_map< item::Id, std::int32_t > values
Definition: ItemDB.hpp:67
bool loadDev(std::istream &input)
Loads the database from its json format.
Definition: ItemDB.cpp:15
bool load()
Loads the item metadata from the data file.
Definition: ItemDB.cpp:11
SerializableField< 3, DB, std::unordered_map< Id, std::int32_t > > values
Definition: ItemDB.hpp:84
SerializableField< 2, DB, std::unordered_map< Id, std::string > > descriptions
Definition: ItemDB.hpp:83
SerializableField< 1, DB, std::unordered_map< Id, std::string > > names
Definition: ItemDB.hpp:82