1 #ifndef CORE_FILES_CONVERSATION_HPP
2 #define CORE_FILES_CONVERSATION_HPP
4 #include <BLIB/Resources.hpp>
5 #include <BLIB/Serialization.hpp>
137 std::vector<std::pair<std::string, std::uint32_t>>&
choices();
143 std::uint32_t&
money();
155 std::uint32_t&
next();
173 const std::string&
message()
const;
179 const std::string&
script()
const;
185 const std::string&
saveFlag()
const;
203 const std::vector<std::pair<std::string, std::uint32_t>>&
choices()
const;
209 unsigned int money()
const;
215 const Item&
item()
const;
221 std::uint32_t
next()
const;
236 using TData = std::variant<std::vector<std::pair<std::string, std::uint32_t>>, Item,
237 std::uint32_t,
bool>;
242 std::uint32_t jumps[2];
244 friend struct bl::serial::SerializableObject<
Node>;
260 bool
load(const std::string& file);
268 bool
loadDev(std::istream& input);
276 bool
loadProd(bl::serial::binary::InputStream& input);
284 bool
save(const std::string& file) const;
293 bool
saveBundle(bl::serial::binary::OutputStream& output,
294 bl::resource::bundle::FileHandlerContext& ctx) const;
300 const std::vector<Node>&
nodes() const;
323 void
setNode(unsigned int i, const Node& node);
339 static void
getNextJumps(const Node& node, std::vector<unsigned int>& jumps);
342 std::vector<Node> cnodes;
344 friend struct bl::serial::SerializableObject<Conversation>;
355 struct SerializableObject<
core::file::Conversation::Node::Item> :
public SerializableObjectBase {
359 SerializableField<1, Item, Id>
id;
364 : SerializableObjectBase(
"ConversationNodeItem")
365 , id(
"id", *this, &
Item::id, SerializableFieldBase::Required{})
366 , beforePrompt(
"beforePrompt", *this, &
Item::beforePrompt, SerializableFieldBase::Required{})
367 , afterPrompt(
"afterPrompt", *this, &
Item::afterPrompt, SerializableFieldBase::Required{}) {}
371 struct SerializableObject<
core::file::Conversation::Node> :
public SerializableObjectBase {
374 SerializableField<1, Node, Node::Type>
type;
375 SerializableField<2, Node, std::string>
prompt;
376 SerializableField<3, Node, Node::TData>
data;
377 SerializableField<4, Node, std::uint32_t[2]>
jumps;
380 : SerializableObjectBase(
"ConversationNode")
381 , type(
"type", *this, &
Node::type, SerializableFieldBase::Required{})
382 , prompt(
"prompt", *this, &
Node::prompt, SerializableFieldBase::Required{})
383 , data(
"data", *this, &
Node::data, SerializableFieldBase::Required{})
384 , jumps(
"jumps", *this, &
Node::jumps, SerializableFieldBase::Required{}) {}
388 struct SerializableObject<
core::file::Conversation> :
public SerializableObjectBase {
392 SerializableField<1, Conversation, std::vector<Node>>
nodes;
395 : SerializableObjectBase(
"Conversation")
396 ,
nodes(
"nodes", *this, &
Conversation::cnodes, SerializableFieldBase::Required{}) {}
Id
Represents an item in its simplist form.
Type
Represents a type that a move or Peoplemon can be. Types may be combined.
Core classes and functionality for both the editor and game.
Stores a conversation that an NPC or trainer can have with the player.
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 void getNextJumps(const Node &node, std::vector< unsigned int > &jumps)
Populates the jumps vector with the indices reachable from the given node.
bool load(const std::string &file)
Loads the conversation from the given file.
void deleteNode(unsigned int i)
Deletes the node at the given index. Jump indexes for other nodes are updated if affected....
void setNode(unsigned int i, const Node &node)
Updates the value of the node at the given index.
bool loadProd(bl::serial::binary::InputStream &input)
Loads the conversation from its binary format.
const std::vector< Node > & nodes() const
Returns the list of nodes in the conversation.
bool loadDev(std::istream &input)
Loads the conversation from its json format.
bool save(const std::string &file) const
Saves the conversation to the given file.
static Conversation makeLoadError(const std::string &filename)
Helper function to create a conversation that reports an error if in debug mode.
void appendNode(const Node &node)
Appends the given node to the list of nodes.
Building block of conversations. A conversation is a tree of nodes and each node is an action that ha...
std::string & script()
Returns the script file of this node.
static std::string typeToString(Type type)
Converts a node type to a human readable string.
std::string & message()
Returns the message or prompt for this node.
std::uint32_t & nextOnPass()
Returns the next node if a check passes (ie take item or money)
std::uint32_t & nextOnReject()
Returns the next node if a check is rejected (ie not taking money or item)
void setType(Type type)
Clears node data and updates to a new type.
std::uint32_t & money()
Returns the money requested or given, undefined behavior if not a money node.
Type getType() const
Returns the type of this node.
bool & runConcurrently()
Returns whether or not the launched script should be executed concurrently.
std::string & saveFlag()
Returns the save flag of this node.
Item & item()
Returns the item to give or take. Undefined behavior if not an item node.
std::uint32_t & next()
Returns the index of the next node in the case of a Talk, Give, and Script nodes.
std::vector< std::pair< std::string, std::uint32_t > > & choices()
Returns the choices if this is a prompt node. Undefined behavior if not.
Node()
Creates an empty talk node.
Type
Represents the different effects that nodes can have.
@ TakeMoney
This will ask the player for money. They may refuse or not have enough.
@ RunScript
This will run a script. Must be a file.
@ CheckInteracted
This will check if interacted with the talking NPC and jump accordingly.
@ Prompt
This will output a message then prompt the player for a choice.
@ Talk
This just outputs a message.
@ TakeItem
This will ask the player for an item. They may refuse or not have it.
@ GiveItem
This unconditionally gives the player an item.
@ SetSaveFlag
This will check if a flag exists and jump to the next node accordingly.
@ CheckSaveFlag
This will check if a flag exists and jump to the next node accordingly.
@ GiveMoney
This will unconditionally give money to the player.
SerializableField< 3, Item, bool > afterPrompt
SerializableField< 2, Item, bool > beforePrompt
SerializableField< 1, Item, Id > id
SerializableField< 3, Node, Node::TData > data
SerializableField< 2, Node, std::string > prompt
SerializableField< 1, Node, Node::Type > type
SerializableField< 4, Node, std::uint32_t[2]> jumps
SerializableField< 1, Conversation, std::vector< Node > > nodes