Got apply verb working correctly

This commit is contained in:
Malcolm Roberts 2024-05-14 14:11:48 -05:00
parent 829fdd7c39
commit 0c06151b0b
21 changed files with 79 additions and 38 deletions

View File

@ -45,7 +45,7 @@
{ {
"directoryIndex" : 0, "directoryIndex" : 0,
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
"jsonFile" : "target-ALL_BUILD-Debug-cbc59f6476b9b25d8f24.json", "jsonFile" : "target-ALL_BUILD-Debug-86a97d3bececc473eb01.json",
"name" : "ALL_BUILD", "name" : "ALL_BUILD",
"projectIndex" : 0 "projectIndex" : 0
}, },
@ -116,7 +116,7 @@
{ {
"directoryIndex" : 0, "directoryIndex" : 0,
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
"jsonFile" : "target-ALL_BUILD-Release-cbc59f6476b9b25d8f24.json", "jsonFile" : "target-ALL_BUILD-Release-86a97d3bececc473eb01.json",
"name" : "ALL_BUILD", "name" : "ALL_BUILD",
"projectIndex" : 0 "projectIndex" : 0
}, },
@ -187,7 +187,7 @@
{ {
"directoryIndex" : 0, "directoryIndex" : 0,
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
"jsonFile" : "target-ALL_BUILD-MinSizeRel-cbc59f6476b9b25d8f24.json", "jsonFile" : "target-ALL_BUILD-MinSizeRel-86a97d3bececc473eb01.json",
"name" : "ALL_BUILD", "name" : "ALL_BUILD",
"projectIndex" : 0 "projectIndex" : 0
}, },
@ -258,7 +258,7 @@
{ {
"directoryIndex" : 0, "directoryIndex" : 0,
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
"jsonFile" : "target-ALL_BUILD-RelWithDebInfo-cbc59f6476b9b25d8f24.json", "jsonFile" : "target-ALL_BUILD-RelWithDebInfo-86a97d3bececc473eb01.json",
"name" : "ALL_BUILD", "name" : "ALL_BUILD",
"projectIndex" : 0 "projectIndex" : 0
}, },

View File

@ -27,7 +27,7 @@
"objects" : "objects" :
[ [
{ {
"jsonFile" : "codemodel-v2-ffaaca604fe32ea15b03.json", "jsonFile" : "codemodel-v2-417377ecfa385c483b0f.json",
"kind" : "codemodel", "kind" : "codemodel",
"version" : "version" :
{ {
@ -100,7 +100,7 @@
} }
}, },
{ {
"jsonFile" : "codemodel-v2-ffaaca604fe32ea15b03.json", "jsonFile" : "codemodel-v2-417377ecfa385c483b0f.json",
"kind" : "codemodel", "kind" : "codemodel",
"version" : "version" :
{ {

View File

@ -16,14 +16,14 @@
}, },
"dependencies" : "dependencies" :
[ [
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
},
{ {
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df" "id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
}, },
{ {
"id" : "ISXMr::@6890427a1f51a3e7e1df" "id" : "ISXMr::@6890427a1f51a3e7e1df"
},
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
} }
], ],
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",

View File

@ -16,14 +16,14 @@
}, },
"dependencies" : "dependencies" :
[ [
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
},
{ {
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df" "id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
}, },
{ {
"id" : "ISXMr::@6890427a1f51a3e7e1df" "id" : "ISXMr::@6890427a1f51a3e7e1df"
},
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
} }
], ],
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",

View File

@ -16,14 +16,14 @@
}, },
"dependencies" : "dependencies" :
[ [
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
},
{ {
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df" "id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
}, },
{ {
"id" : "ISXMr::@6890427a1f51a3e7e1df" "id" : "ISXMr::@6890427a1f51a3e7e1df"
},
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
} }
], ],
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",

View File

@ -16,14 +16,14 @@
}, },
"dependencies" : "dependencies" :
[ [
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
},
{ {
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df" "id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
}, },
{ {
"id" : "ISXMr::@6890427a1f51a3e7e1df" "id" : "ISXMr::@6890427a1f51a3e7e1df"
},
{
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
} }
], ],
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df", "id" : "ALL_BUILD::@6890427a1f51a3e7e1df",

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -39,6 +39,17 @@ bool MrBotApiType::ToText(LSOBJECTDATA ObjectData, char *buf, unsigned int bufle
return false; return false;
} }
unsigned long MrBotApiType::GetActorIdByName(const std::string &actorName, bool exactMatch)
{
const auto actor = ExtensionTLOs::Actor().GetActorByName(actorName, exactMatch);
if (actor.has_value())
{
return actor->Id();
}
return -1;
}
// Members // Members
bool MrBotApiType::Version(const std::vector<std::string> &args, LSOBJECT &dest) bool MrBotApiType::Version(const std::vector<std::string> &args, LSOBJECT &dest)
{ {
@ -56,16 +67,14 @@ bool MrBotApiType::ClickActorByName(const std::vector<std::string> &args)
return false; return false;
} }
const std::string &name = args[0]; const auto actorId = GetActorIdByName(args[0]);
log << "MrBotApiType::ClickActorByName " << name << std::endl; if (actorId == -1)
const auto actor = ExtensionTLOs::Actor().GetActorByName(name);
if (!actor.has_value())
{ {
logw << "MrBotApiType::ClickActorByName: Actor not found: " << name << std::endl; logw << "MrBotApiType::ClickActorByName: Actor not found: " << args[0] << std::endl;
return false; return false;
} }
// actor->DoubleClick();
return true; return ClickActorById({std::to_string(actorId)});
} }
bool MrBotApiType::ClickActorById(const std::vector<std::string> &args) bool MrBotApiType::ClickActorById(const std::vector<std::string> &args)
@ -88,4 +97,29 @@ bool MrBotApiType::ClickActorById(const std::vector<std::string> &args)
log << "MrBotApiType::ClickActorById: Actor found: " << actor->Name() << std::endl; log << "MrBotApiType::ClickActorById: Actor found: " << actor->Name() << std::endl;
actor->DoubleClick(); actor->DoubleClick();
return true;
}
bool MrBotApiType::ApplyVerb(const std::vector<std::string> &args)
{
if (args.size() != 2)
{
logw << "MrBotApiType::ApplyVerb: Expected 2 arguments, got " << args.size() << std::endl;
return false;
}
const auto actorId = GetActorIdByName(args[0]);
if (actorId == -1)
{
logw << "MrBotApiType::ApplyVerb: Actor not found: " << args[0] << std::endl;
return false;
}
const auto verb = args[1];
const auto command = "eq2execute apply_verb " + std::to_string(actorId) + " \"" + verb + "\"";
log << "MrBotApiType::ApplyVerb: " << command << std::endl;
const auto response = pISInterface->ExecuteCommand(command.c_str());
return response == 0;
} }

View File

@ -2,6 +2,7 @@
#include <ISXDK.h> #include <ISXDK.h>
#include <memory> #include <memory>
#include <sstream>
#include "../isxeq2/ExtensionTLOs.h" #include "../isxeq2/ExtensionTLOs.h"
#define ADD_MEMBER_TO_MAP(EnumType, memberName, expectedArgc) \ #define ADD_MEMBER_TO_MAP(EnumType, memberName, expectedArgc) \
@ -43,7 +44,8 @@ public:
enum class MrBotApiTypeMethods enum class MrBotApiTypeMethods
{ {
ClickActorByName, ClickActorByName,
ClickActorById ClickActorById,
ApplyVerb
}; };
MrBotApiType() : LSTypeDefinition(const_cast<char *>("mrbotapi")) MrBotApiType() : LSTypeDefinition(const_cast<char *>("mrbotapi"))
@ -51,6 +53,7 @@ public:
ADD_MEMBER_TO_MAP(MrBotApiTypeMembers, Version, 0); ADD_MEMBER_TO_MAP(MrBotApiTypeMembers, Version, 0);
ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ClickActorByName, 1); ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ClickActorByName, 1);
ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ClickActorById, 1); ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ClickActorById, 1);
ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ApplyVerb, 2);
} }
virtual bool GetMember(LSOBJECTDATA ObjectData, PLSTYPEMEMBER pMember, int argc, char *argv[], LSOBJECT &Dest); virtual bool GetMember(LSOBJECTDATA ObjectData, PLSTYPEMEMBER pMember, int argc, char *argv[], LSOBJECT &Dest);
@ -86,11 +89,14 @@ public:
} }
private: private:
// Helpers
unsigned long GetActorIdByName(const std::string &actorName, bool exactMatch = false);
// Members // Members
bool Version(const std::vector<std::string> &args, LSOBJECT &dest); bool Version(const std::vector<std::string> &args, LSOBJECT &dest);
// Methods // Methods
bool ClickActorByName(const std::vector<std::string> &args); bool ClickActorByName(const std::vector<std::string> &args);
bool ClickActorById(const std::vector<std::string> &args); bool ClickActorById(const std::vector<std::string> &args);
bool ApplyVerb(const std::vector<std::string> &args);
static unique_ptr<MrBotApiType> pMrBotApi; static unique_ptr<MrBotApiType> pMrBotApi;
using MethodFunc = std::function<bool(int argc, char *argv[])>; using MethodFunc = std::function<bool(int argc, char *argv[])>;

View File

@ -24,17 +24,18 @@ optional<Actor> ActorTLO::GetActorById(unsigned long id) const
// return Actor(make_shared<LSObject>(actor)); // return Actor(make_shared<LSObject>(actor));
} }
optional<Actor> ActorTLO::GetActorByName(const std::string &name) const optional<Actor> ActorTLO::GetActorByName(const std::string &name, const bool exactMatch) const
{ {
return nullopt; stringstream query;
// log << "ActorTLO::GetActorByName: " << name << std::endl; query << "Actor[query, Name " << (exactMatch ? "==" : "=-") << " \"" << name << "\"]";
// return nullopt; const string command = query.str();
// const auto actor = this->lsObject->GetMember("Actor", "Name =- " + name); log << "ActorTLO::GetActorByName: " << command << std::endl;
// if (!actor.has_value())
// {
// logw << "ActorTLO::GetActorByName: Actor not found: " << name << std::endl;
// return nullopt;
// }
// return Actor(make_shared<LSObject>(actor)); const auto actor = LSObject::FromDataParse(command);
if (actor.has_value())
{
return Actor(actor.value());
}
return nullopt;
} }

View File

@ -9,7 +9,7 @@ public:
} }
optional<Actor> GetActorById(unsigned long id) const; optional<Actor> GetActorById(unsigned long id) const;
optional<Actor> GetActorByName(const std::string &name) const; optional<Actor> GetActorByName(const std::string &name, const bool exactMatch = false) const;
optional<Actor> GetActorByQuery(const std::string &query) const; optional<Actor> GetActorByQuery(const std::string &query) const;
private: private: