Got apply verb working correctly
This commit is contained in:
parent
829fdd7c39
commit
0c06151b0b
@ -45,7 +45,7 @@
|
||||
{
|
||||
"directoryIndex" : 0,
|
||||
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-ALL_BUILD-Debug-cbc59f6476b9b25d8f24.json",
|
||||
"jsonFile" : "target-ALL_BUILD-Debug-86a97d3bececc473eb01.json",
|
||||
"name" : "ALL_BUILD",
|
||||
"projectIndex" : 0
|
||||
},
|
||||
@ -116,7 +116,7 @@
|
||||
{
|
||||
"directoryIndex" : 0,
|
||||
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-ALL_BUILD-Release-cbc59f6476b9b25d8f24.json",
|
||||
"jsonFile" : "target-ALL_BUILD-Release-86a97d3bececc473eb01.json",
|
||||
"name" : "ALL_BUILD",
|
||||
"projectIndex" : 0
|
||||
},
|
||||
@ -187,7 +187,7 @@
|
||||
{
|
||||
"directoryIndex" : 0,
|
||||
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-ALL_BUILD-MinSizeRel-cbc59f6476b9b25d8f24.json",
|
||||
"jsonFile" : "target-ALL_BUILD-MinSizeRel-86a97d3bececc473eb01.json",
|
||||
"name" : "ALL_BUILD",
|
||||
"projectIndex" : 0
|
||||
},
|
||||
@ -258,7 +258,7 @@
|
||||
{
|
||||
"directoryIndex" : 0,
|
||||
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
|
||||
"jsonFile" : "target-ALL_BUILD-RelWithDebInfo-cbc59f6476b9b25d8f24.json",
|
||||
"jsonFile" : "target-ALL_BUILD-RelWithDebInfo-86a97d3bececc473eb01.json",
|
||||
"name" : "ALL_BUILD",
|
||||
"projectIndex" : 0
|
||||
},
|
||||
@ -27,7 +27,7 @@
|
||||
"objects" :
|
||||
[
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-ffaaca604fe32ea15b03.json",
|
||||
"jsonFile" : "codemodel-v2-417377ecfa385c483b0f.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
||||
@ -100,7 +100,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"jsonFile" : "codemodel-v2-ffaaca604fe32ea15b03.json",
|
||||
"jsonFile" : "codemodel-v2-417377ecfa385c483b0f.json",
|
||||
"kind" : "codemodel",
|
||||
"version" :
|
||||
{
|
||||
@ -16,14 +16,14 @@
|
||||
},
|
||||
"dependencies" :
|
||||
[
|
||||
{
|
||||
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ISXMr::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
|
||||
}
|
||||
],
|
||||
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
|
||||
@ -16,14 +16,14 @@
|
||||
},
|
||||
"dependencies" :
|
||||
[
|
||||
{
|
||||
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ISXMr::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
|
||||
}
|
||||
],
|
||||
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
|
||||
@ -16,14 +16,14 @@
|
||||
},
|
||||
"dependencies" :
|
||||
[
|
||||
{
|
||||
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ISXMr::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
|
||||
}
|
||||
],
|
||||
"id" : "ALL_BUILD::@6890427a1f51a3e7e1df",
|
||||
@ -16,14 +16,14 @@
|
||||
},
|
||||
"dependencies" :
|
||||
[
|
||||
{
|
||||
"id" : "ZERO_CHECK::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "GenerateHeaders::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ISXMr::@6890427a1f51a3e7e1df"
|
||||
},
|
||||
{
|
||||
"id" : "ZERO_CHECK::@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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -39,6 +39,17 @@ bool MrBotApiType::ToText(LSOBJECTDATA ObjectData, char *buf, unsigned int bufle
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
const std::string &name = args[0];
|
||||
log << "MrBotApiType::ClickActorByName " << name << std::endl;
|
||||
const auto actor = ExtensionTLOs::Actor().GetActorByName(name);
|
||||
if (!actor.has_value())
|
||||
const auto actorId = GetActorIdByName(args[0]);
|
||||
if (actorId == -1)
|
||||
{
|
||||
logw << "MrBotApiType::ClickActorByName: Actor not found: " << name << std::endl;
|
||||
logw << "MrBotApiType::ClickActorByName: Actor not found: " << args[0] << std::endl;
|
||||
return false;
|
||||
}
|
||||
// actor->DoubleClick();
|
||||
return true;
|
||||
|
||||
return ClickActorById({std::to_string(actorId)});
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include <ISXDK.h>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include "../isxeq2/ExtensionTLOs.h"
|
||||
|
||||
#define ADD_MEMBER_TO_MAP(EnumType, memberName, expectedArgc) \
|
||||
@ -43,7 +44,8 @@ public:
|
||||
enum class MrBotApiTypeMethods
|
||||
{
|
||||
ClickActorByName,
|
||||
ClickActorById
|
||||
ClickActorById,
|
||||
ApplyVerb
|
||||
};
|
||||
|
||||
MrBotApiType() : LSTypeDefinition(const_cast<char *>("mrbotapi"))
|
||||
@ -51,6 +53,7 @@ public:
|
||||
ADD_MEMBER_TO_MAP(MrBotApiTypeMembers, Version, 0);
|
||||
ADD_METHOD_TO_MAP(MrBotApiTypeMethods, ClickActorByName, 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);
|
||||
@ -86,11 +89,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// Helpers
|
||||
unsigned long GetActorIdByName(const std::string &actorName, bool exactMatch = false);
|
||||
// Members
|
||||
bool Version(const std::vector<std::string> &args, LSOBJECT &dest);
|
||||
// Methods
|
||||
bool ClickActorByName(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;
|
||||
using MethodFunc = std::function<bool(int argc, char *argv[])>;
|
||||
|
||||
@ -24,17 +24,18 @@ optional<Actor> ActorTLO::GetActorById(unsigned long id) const
|
||||
// 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;
|
||||
// log << "ActorTLO::GetActorByName: " << name << std::endl;
|
||||
// return nullopt;
|
||||
// const auto actor = this->lsObject->GetMember("Actor", "Name =- " + name);
|
||||
// if (!actor.has_value())
|
||||
// {
|
||||
// logw << "ActorTLO::GetActorByName: Actor not found: " << name << std::endl;
|
||||
// return nullopt;
|
||||
// }
|
||||
stringstream query;
|
||||
query << "Actor[query, Name " << (exactMatch ? "==" : "=-") << " \"" << name << "\"]";
|
||||
const string command = query.str();
|
||||
log << "ActorTLO::GetActorByName: " << command << std::endl;
|
||||
|
||||
// return Actor(make_shared<LSObject>(actor));
|
||||
const auto actor = LSObject::FromDataParse(command);
|
||||
if (actor.has_value())
|
||||
{
|
||||
return Actor(actor.value());
|
||||
}
|
||||
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ public:
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
private:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user