Peoplemon  0.1.0
Peoplemon 3 game source documentation
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
core::file::Conversation Class Reference

Stores a conversation that an NPC or trainer can have with the player. More...

#include <Conversation.hpp>

Classes

class  Node
 Building block of conversations. A conversation is a tree of nodes and each node is an action that happens in the conversation. More...
 

Public Member Functions

 Conversation ()=default
 Creates an empty conversation. More...
 
bool load (const std::string &file)
 Loads the conversation from the given file. More...
 
bool loadDev (std::istream &input)
 Loads the conversation from its json format. More...
 
bool loadProd (bl::serial::binary::InputStream &input)
 Loads the conversation from its binary format. More...
 
bool save (const std::string &file) const
 Saves the conversation to the given file. More...
 
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. More...
 
const std::vector< Node > & nodes () const
 Returns the list of nodes in the conversation. More...
 
void deleteNode (unsigned int i)
 Deletes the node at the given index. Jump indexes for other nodes are updated if affected. Jumps to node i are invalidated and will terminate the conversation. More...
 
void appendNode (const Node &node)
 Appends the given node to the list of nodes. More...
 
void setNode (unsigned int i, const Node &node)
 Updates the value of the node at the given index. More...
 

Static Public Member Functions

static Conversation makeLoadError (const std::string &filename)
 Helper function to create a conversation that reports an error if in debug mode. More...
 
static void getNextJumps (const Node &node, std::vector< unsigned int > &jumps)
 Populates the jumps vector with the indices reachable from the given node. More...
 

Friends

struct bl::serial::SerializableObject< Conversation >
 

Detailed Description

Stores a conversation that an NPC or trainer can have with the player.

Definition at line 22 of file Conversation.hpp.

Constructor & Destructor Documentation

◆ Conversation()

core::file::Conversation::Conversation ( )
default

Creates an empty conversation.

Member Function Documentation

◆ appendNode()

void core::file::Conversation::appendNode ( const Node node)

Appends the given node to the list of nodes.

Parameters
nodeThe node to append

Definition at line 93 of file Conversation.cpp.

◆ deleteNode()

void core::file::Conversation::deleteNode ( unsigned int  i)

Deletes the node at the given index. Jump indexes for other nodes are updated if affected. Jumps to node i are invalidated and will terminate the conversation.

Parameters
iThe index to erase the node at

Definition at line 85 of file Conversation.cpp.

◆ getNextJumps()

void core::file::Conversation::getNextJumps ( const Node node,
std::vector< unsigned int > &  jumps 
)
static

Populates the jumps vector with the indices reachable from the given node.

Parameters
nodeThe node to get the jumps for
jumpsThe result vector to populate

Definition at line 263 of file Conversation.cpp.

◆ load()

bool core::file::Conversation::load ( const std::string &  file)

Loads the conversation from the given file.

Parameters
fileThe file to load from. This should be relative to the conversation path
Returns
True if loaded, false on error

Definition at line 61 of file Conversation.cpp.

◆ loadDev()

bool core::file::Conversation::loadDev ( std::istream &  input)

Loads the conversation from its json format.

Parameters
inputThe input stream to process
Returns
True if the conversation was loaded, false otherwise

Definition at line 65 of file Conversation.cpp.

◆ loadProd()

bool core::file::Conversation::loadProd ( bl::serial::binary::InputStream &  input)

Loads the conversation from its binary format.

Parameters
inputThe input stream to process
Returns
True if the conversation was loaded, false otherwise

Definition at line 69 of file Conversation.cpp.

◆ makeLoadError()

Conversation core::file::Conversation::makeLoadError ( const std::string &  filename)
static

Helper function to create a conversation that reports an error if in debug mode.

Parameters
filenameThe file that failed to load
Returns
Conversation The conversation that reports the error

Definition at line 222 of file Conversation.cpp.

◆ nodes()

const std::vector< Conversation::Node > & core::file::Conversation::nodes ( ) const

Returns the list of nodes in the conversation.

Definition at line 83 of file Conversation.cpp.

◆ save()

bool core::file::Conversation::save ( const std::string &  file) const

Saves the conversation to the given file.

Parameters
fileThe file to save to, relative to the conversation path
Returns
True if saved, false on error

Definition at line 73 of file Conversation.cpp.

◆ saveBundle()

bool core::file::Conversation::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.

Parameters
outputStream to output to
ctxContext to register dependencies with
Returns
True if serialization succeeded, false otherwise

Definition at line 78 of file Conversation.cpp.

◆ setNode()

void core::file::Conversation::setNode ( unsigned int  i,
const Node node 
)

Updates the value of the node at the given index.

Parameters
iThe index to update
nodeThe new node value

Definition at line 95 of file Conversation.cpp.

Friends And Related Function Documentation

◆ bl::serial::SerializableObject< Conversation >

friend struct bl::serial::SerializableObject< Conversation >
friend

Definition at line 342 of file Conversation.hpp.


The documentation for this class was generated from the following files: