Make ChatCommands archivable

This commit is contained in:
Jaidyn Ann 2021-06-15 22:03:11 -05:00
parent 66b8150eeb
commit a03746c034
2 changed files with 47 additions and 1 deletions

View File

@ -23,6 +23,46 @@ ChatCommand::ChatCommand(const char* name, BMessage msg, bool toProtocol,
} }
ChatCommand::ChatCommand(BMessage* data)
: BArchivable(data)
{
data->FindString("_name", &fName);
data->FindString("_desc", &fDescription);
data->FindBool("_proto", &fToProto);
data->FindMessage("_msg", &fMessage);
int32 argType, i = 0;
while (data->FindInt32("_argtype", i, &argType) == B_OK) {
fArgTypes.AddItem(argType);
i++;
}
}
status_t
ChatCommand::Archive(BMessage* data, bool deep)
{
status_t ret = BArchivable::Archive(data, deep);
data->AddString("_name", fName);
data->AddString("_desc", fDescription);
data->AddBool("_proto", fToProto);
data->AddMessage("_msg", new BMessage(fMessage));
for (int i = 0; i < fArgTypes.CountItems(); i++)
data->AddInt32("_argtype", fArgTypes.ItemAt(i));
return ret;
}
ChatCommand*
ChatCommand::Instantiate(BMessage* data)
{
if (!validate_instantiation(data, "ChatCommand"))
return NULL;
return new ChatCommand(data);
}
void void
ChatCommand::SetDesc(const char* description) ChatCommand::SetDesc(const char* description)
{ {

View File

@ -5,6 +5,7 @@
#ifndef CHAT_COMMAND_H #ifndef CHAT_COMMAND_H
#define CHAT_COMMAND_H #define CHAT_COMMAND_H
#include <Archivable.h>
#include <Message.h> #include <Message.h>
#include <String.h> #include <String.h>
@ -23,10 +24,15 @@ enum cmd_arg_type
}; };
class ChatCommand { class ChatCommand : public BArchivable {
public: public:
ChatCommand(const char* name, BMessage msg, bool toProtocol, ChatCommand(const char* name, BMessage msg, bool toProtocol,
List<int32> argTypes); List<int32> argTypes);
ChatCommand(BMessage* data);
status_t Archive(BMessage* data, bool deep=true);
ChatCommand* Instantiate(BMessage* data);
const char* GetName() { return fName.String(); } const char* GetName() { return fName.String(); }