Adds mock functions for a bunch more data.

This commit is contained in:
Deukhoofd 2021-08-25 21:17:44 +02:00
parent 86fae313ba
commit d11722efdd
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 84 additions and 8 deletions

View File

@ -1,5 +1,5 @@
#ifndef POKEMONSCRIPTTESTER_BATTLEBUILDER_HPP
#define POKEMONSCRIPTTESTER_BATTLEBUILDER_HPP
#ifndef POKEMONSCRIPTTESTER_BATTLEFUNCTIONS_HPP
#define POKEMONSCRIPTTESTER_BATTLEFUNCTIONS_HPP
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
#include <CreatureLib/Battling/TurnChoices/PassTurnChoice.hpp>
@ -8,7 +8,7 @@
#include <angelscript.h>
#include "../TestEnvironment.hpp"
class BattleBuilder {
class BattleFunctions {
static PkmnLib::Battling::Battle* CreateSimpleBattle(u32 seed, const ArbUt::StringView& species1,
const ArbUt::StringView& species2, u8 level) {
auto* ctx = asGetActiveContext();
@ -33,7 +33,7 @@ class BattleBuilder {
.IsAllowedExperienceGain(false)
.Build();
auto p2 = new CreatureLib::Battling::CreatureParty(1);
p1->SwapInto(0, mon2);
p2->SwapInto(0, mon2);
auto battle = new PkmnLib::Battling::Battle(
lib,
@ -107,4 +107,4 @@ public:
}
};
#endif // POKEMONSCRIPTTESTER_BATTLEBUILDER_HPP
#endif // POKEMONSCRIPTTESTER_BATTLEFUNCTIONS_HPP

View 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

View File

@ -4,7 +4,8 @@
#include "../extern/args.hpp"
#include "BuildData/BuildLibrary.hpp"
#include "Globals.hpp"
#include "Tester/AngelScript/BattleBuilder.hpp"
#include "Tester/AngelScript/BattleFunctions.hpp"
#include "Tester/AngelScript/MiscMockFunctions.hpp"
#include "Tester/AngelScript/TestFunctions.hpp"
#include "Tester/TestRunner.hpp"
@ -41,9 +42,10 @@ int main(int argc, char** argv) {
std::function<void(PkmnLib::Battling::ScriptResolver*)> initialize =
[](PkmnLib::Battling::ScriptResolver* resolver) {
auto* scriptResolver = dynamic_cast<AngelScriptResolver*>(resolver);
scriptResolver->DefineWord("TEST");
scriptResolver->DefineWord("TESTS");
TestFunctions::Register(scriptResolver);
BattleBuilder::Register(scriptResolver);
BattleFunctions::Register(scriptResolver);
MiscMockFunctions::Register(scriptResolver);
};
Globals::Library = BuildLibrary::Build("", initialize);