Adds mock functions for a bunch more data.
This commit is contained in:
74
src/Tester/AngelScript/MiscMockFunctions.hpp
Normal file
74
src/Tester/AngelScript/MiscMockFunctions.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef POKEMONSCRIPTTESTER_MISCMOCKFUNCTIONS_HPP
|
||||
#define POKEMONSCRIPTTESTER_MISCMOCKFUNCTIONS_HPP
|
||||
|
||||
#include <PkmnLib/extern/angelscript_addons/scripthandle/scripthandle.h>
|
||||
|
||||
class MiscMockFunctions {
|
||||
static CScriptHandle CreateMoveScript(const ArbUt::StringView& name) {
|
||||
auto script = Globals::Library.GetValue()->GetScriptResolver()->LoadScript(ScriptCategory::Attack, name);
|
||||
if (script != nullptr) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
env->AddGarbage(script);
|
||||
}
|
||||
auto p = dynamic_cast<AngelScriptScript*>(script);
|
||||
EnsureNotNull(p);
|
||||
auto handle = CScriptHandle(p->GetRawAngelscriptObject(), p->GetRawAngelscriptObject()->GetObjectType());
|
||||
return handle;
|
||||
}
|
||||
|
||||
static CreatureLib::Battling::ExecutingAttack* CreateExecutingMove(const ArbUt::StringView& moveName,
|
||||
PkmnLib::Battling::Pokemon* user,
|
||||
PkmnLib::Battling::Pokemon* target) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
|
||||
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
|
||||
if (!move.has_value()) {
|
||||
return {};
|
||||
}
|
||||
auto learnedMove =
|
||||
new PkmnLib::Battling::LearnedMove(move.value(), CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||
env->AddGarbage(learnedMove);
|
||||
|
||||
auto executingMove = new CreatureLib::Battling::ExecutingAttack(
|
||||
{target}, 1, user, learnedMove, move.value().As<const CreatureLib::Library::AttackData>(), nullptr);
|
||||
env->AddGarbage(executingMove);
|
||||
return executingMove;
|
||||
}
|
||||
|
||||
static CreatureLib::Battling::AttackTurnChoice* CreateMoveTurnChoice(const ArbUt::StringView& moveName,
|
||||
PkmnLib::Battling::Pokemon* user,
|
||||
u8 targetSide, u8 target) {
|
||||
auto* ctx = asGetActiveContext();
|
||||
TestEnvironment* env = static_cast<TestEnvironment*>(ctx->GetUserData());
|
||||
|
||||
auto move = Globals::Library.GetValue()->GetMoveLibrary()->TryGet(moveName);
|
||||
if (!move.has_value()) {
|
||||
return {};
|
||||
}
|
||||
auto learnedMove =
|
||||
new PkmnLib::Battling::LearnedMove(move.value(), CreatureLib::Battling::AttackLearnMethod::Unknown);
|
||||
env->AddGarbage(learnedMove);
|
||||
|
||||
auto moveTurnChoice = new CreatureLib::Battling::AttackTurnChoice(
|
||||
user, learnedMove, CreatureLib::Battling::CreatureIndex(targetSide, target));
|
||||
env->AddGarbage(moveTurnChoice);
|
||||
return moveTurnChoice;
|
||||
}
|
||||
|
||||
public:
|
||||
static void Register(AngelScriptResolver* scriptResolver) {
|
||||
auto engine = scriptResolver->GetBuilder().GetEngine();
|
||||
Ensure(engine->RegisterGlobalFunction("ref@ CreateMoveScript(const constString&in name)",
|
||||
asFUNCTION(CreateMoveScript), asCALL_CDECL) >= 0);
|
||||
Ensure(engine->RegisterGlobalFunction(
|
||||
"ExecutingMove@ CreateExecutingMove(const constString&in moveName, Pokemon@ user, Pokemon@ target)",
|
||||
asFUNCTION(CreateExecutingMove), asCALL_CDECL) >= 0);
|
||||
Ensure(engine->RegisterGlobalFunction("MoveTurnChoice@ CreateMoveTurnChoice(const constString&in moveName, "
|
||||
"Pokemon@ user, uint8 targetSide, uint8 target)",
|
||||
asFUNCTION(CreateMoveTurnChoice), asCALL_CDECL) >= 0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // POKEMONSCRIPTTESTER_MISCMOCKFUNCTIONS_HPP
|
||||
Reference in New Issue
Block a user