11 std::ofstream output(file.c_str());
12 return bl::serial::json::Serializer<NPC>::serializeStream(output, *
this, 4, 0);
16 bl::resource::bundle::FileHandlerContext& ctx)
const {
17 if (!bl::serial::binary::Serializer<NPC>::serialize(output, *
this))
return false;
19 const std::array<std::string, 4> Suffixes{
"up.anim",
"right.anim",
"down.anim",
"left.anim"};
20 const std::string ap =
22 for (
const std::string& s : Suffixes) {
23 const std::string p = bl::util::FileUtil::joinPath(ap, s);
24 if (bl::util::FileUtil::exists(p)) { ctx.addDependencyFile(p); }
25 else { BL_LOG_WARN <<
"NPC " << nameField <<
" is missing anim: " << p; }
30 if (bl::util::FileUtil::exists(c)) { ctx.addDependencyFile(c); }
31 else { BL_LOG_WARN <<
"NPC " << nameField <<
" is missing conversation " << conversationField; }
36 bool NPC::load(
const std::string& file, bl::tmap::Direction spawnDir) {
37 if (!NpcManager::initializeExisting(file, *
this))
return false;
43 return bl::serial::json::Serializer<NPC>::deserializeStream(input, *
this);
47 return bl::serial::binary::Serializer<NPC>::deserialize(input, *
this);
52 const std::string&
NPC::name()
const {
return nameField; }
Core classes and functionality for both the editor and game.
Set of behaviors for NPCs and trainers.
Standing & standing()
The data for standing still.
@ StandStill
The character will stand and face a given direction.
bl::tmap::Direction facedir
The direction to face.
bool loadDev(std::istream &input)
Loads the NPC from the json stream.
bool save(const std::string &file) const
Saves the NPC data to the given file.
std::string & conversation()
The conversation file of the NPC.
Behavior & behavior()
The behavior of the NPC.
std::string & name()
The name of the NPC.
bool load(const std::string &file, bl::tmap::Direction spawnDir=bl::tmap::Direction::Up)
Loads the NPC data from the given file.
bool loadProd(bl::serial::binary::InputStream &input)
Loads the NPC from it's binary format.
std::string & animation()
The directory of the movement animations.
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.
static const std::string & ConversationPath()
static const std::string & CharacterAnimationPath()