Peoplemon  0.1.0
Peoplemon 3 game source documentation
NPC.hpp
Go to the documentation of this file.
1 #ifndef CORE_FILES_NPC_HPP
2 #define CORE_FILES_NPC_HPP
3 
4 #include <BLIB/Resources.hpp>
5 #include <BLIB/Serialization.hpp>
7 
15 namespace core
16 {
18 namespace file
19 {
26 class NPC {
27 public:
32  NPC() = default;
33 
40  bool save(const std::string& file) const;
41 
49  bool saveBundle(bl::serial::binary::OutputStream& output,
50  bl::resource::bundle::FileHandlerContext& ctx) const;
51 
59  bool load(const std::string& file, bl::tmap::Direction spawnDir = bl::tmap::Direction::Up);
60 
67  bool loadDev(std::istream& input);
68 
75  bool loadProd(bl::serial::binary::InputStream& input);
76 
81  std::string& name();
82 
87  const std::string& name() const;
88 
93  std::string& animation();
94 
99  const std::string& animation() const;
100 
105  std::string& conversation();
106 
111  const std::string& conversation() const;
112 
117  Behavior& behavior();
118 
123  Behavior behavior() const;
124 
125 private:
126  std::string nameField;
127  std::string animField;
128  std::string conversationField;
129  Behavior behaviorField;
130 
131  friend struct bl::serial::SerializableObject<NPC>;
132 };
133 
134 } // namespace file
135 } // namespace core
136 
137 namespace bl
138 {
139 namespace serial
140 {
141 template<>
142 struct SerializableObject<core::file::NPC> : public SerializableObjectBase {
144 
145  SerializableField<1, N, std::string> nameField;
146  SerializableField<2, N, std::string> animField;
147  SerializableField<3, N, std::string> conversationField;
148  SerializableField<4, N, core::file::Behavior> behaviorField;
149 
151  : SerializableObjectBase("NPC")
152  , nameField("name", *this, &N::nameField, SerializableFieldBase::Required{})
153  , animField("anim", *this, &N::animField, SerializableFieldBase::Required{})
154  , conversationField("conv", *this, &N::conversationField, SerializableFieldBase::Required{})
155  , behaviorField("behavior", *this, &N::behaviorField, SerializableFieldBase::Required{}) {}
156 };
157 
158 } // namespace serial
159 } // namespace bl
160 
161 #endif
Core classes and functionality for both the editor and game.
Set of behaviors for NPCs and trainers.
Definition: Behavior.hpp:19
File data for NPCs.
Definition: NPC.hpp:26
bool loadDev(std::istream &input)
Loads the NPC from the json stream.
Definition: NPC.cpp:42
bool save(const std::string &file) const
Saves the NPC data to the given file.
Definition: NPC.cpp:10
std::string & conversation()
The conversation file of the NPC.
Definition: NPC.cpp:58
Behavior & behavior()
The behavior of the NPC.
Definition: NPC.cpp:62
std::string & name()
The name of the NPC.
Definition: NPC.cpp:50
bool load(const std::string &file, bl::tmap::Direction spawnDir=bl::tmap::Direction::Up)
Loads the NPC data from the given file.
Definition: NPC.cpp:36
bool loadProd(bl::serial::binary::InputStream &input)
Loads the NPC from it's binary format.
Definition: NPC.cpp:46
NPC()=default
Construct a new NPC file.
std::string & animation()
The directory of the movement animations.
Definition: NPC.cpp:54
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: NPC.cpp:15
SerializableField< 3, N, std::string > conversationField
Definition: NPC.hpp:147
SerializableField< 2, N, std::string > animField
Definition: NPC.hpp:146
SerializableField< 1, N, std::string > nameField
Definition: NPC.hpp:145
SerializableField< 4, N, core::file::Behavior > behaviorField
Definition: NPC.hpp:148