Gen7Tests/src/main.cpp

137 lines
5.4 KiB
C++

#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptResolver.hpp>
#include <filesystem>
#include "../extern/args.hpp"
#define DOCTEST_CONFIG_IMPLEMENT
#include "../extern/doctest.hpp"
#include "BuildData/BuildItems.hpp"
#include "BuildData/BuildMoves.hpp"
#include "BuildData/BuildNatures.hpp"
#include "BuildData/BuildSpecies.hpp"
#include "BuildData/BuildTypes.hpp"
#include "BuildData/GrowthRatesBuilder.hpp"
#include "Library.hpp"
static const char* ScriptsPath = nullptr;
int main(int argc, char* argv[]) {
args::ArgumentParser parser("Gen 7 test set.", "");
args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
std::string workingDirectory;
std::string typesFile = "Types.csv";
std::string naturesFile = "Natures.csv";
std::string pokemonFile = "Pokemon.json";
std::string moveFile = "Moves.json";
std::string itemsFile = "Items.json";
std::string growthRatesFile = "GrowthRates.json";
std::string scriptsPath = "Scripts";
args::HelpFlag helpFlag(parser, "help", "Display this help menu", {'h', "help"});
args::ValueFlag<std::string> workingDirFlag(parser, "Working Directory", "Which work directory to use.",
{"workdir"});
args::ValueFlag<std::string> _(parser, "Reporters", "List of reporters to use (default is console)",
{'r', "reporters"});
args::ValueFlag<std::string> __(parser, "", "", {'t', ""});
try {
parser.ParseCLI(argc, argv);
} catch (args::Help) {
std::cout << parser;
return 0;
} catch (args::ParseError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
} catch (args::ValidationError e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
return 1;
}
if (workingDirFlag) {
workingDirectory = args::get(workingDirFlag);
}
if (!workingDirectory.empty()) {
chdir(workingDirectory.c_str());
}
auto typesLibrary = BuildTypes::Build(typesFile);
auto natureLibrary = BuildNatures::Build(naturesFile);
auto speciesLibrary = BuildSpecies::BuildLibrary(pokemonFile, typesLibrary);
auto movesLibrary = BuildMoves::Build(moveFile, typesLibrary);
auto itemsLibrary = BuildItems::Build(itemsFile);
auto growthRates = GrowthRatesBuilder::Build(growthRatesFile);
ScriptsPath = scriptsPath.c_str();
if (typesLibrary == nullptr || speciesLibrary == nullptr || natureLibrary == nullptr || movesLibrary == nullptr ||
itemsLibrary == nullptr || growthRates == nullptr)
return 1;
auto settings = new PkmnLib::Library::LibrarySettings(100, 4, 4096);
auto staticLibrary = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, movesLibrary, itemsLibrary,
growthRates, typesLibrary, natureLibrary);
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
auto battleLib = new PkmnLib::Battling::BattleLibrary(
staticLibrary, new PkmnLib::Battling::StatCalculator(), new PkmnLib::Battling::DamageLibrary(),
new PkmnLib::Battling::ExperienceLibrary(), scriptResolver, new PkmnLib::Battling::MiscLibrary());
scriptResolver->Initialize(battleLib);
auto asScriptResolver = dynamic_cast<AngelScriptResolver*>(scriptResolver);
for (const auto& dirEntry : std::filesystem::recursive_directory_iterator(ScriptsPath)) {
if (dirEntry.is_directory())
continue;
if (dirEntry.path().parent_path().stem() == "Interfaces")
continue;
if (dirEntry.path().extension() != ".as")
continue;
std::ifstream in(dirEntry.path());
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
asScriptResolver->CreateScript(dirEntry.path().c_str(), contents.c_str());
}
asScriptResolver->CreateScript("TriggerEffectChance", R"(
namespace Battle{
[Battle effect=TriggerEffectChance]
class TriggerEffectChance : PkmnScript {
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance) override{chance = 10000;} }
})");
asScriptResolver->CreateScript("BlockEffectChance", R"(
namespace Battle{
[Battle effect=BlockEffectChance]
class BlockEffectChance : PkmnScript {
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance) override{chance = -10000;} }
})");
asScriptResolver->CreateScript("SaveEffectChance", R"(
namespace Battle{
[Battle effect=SaveEffectChance]
class SaveEffectChance : PkmnScript {
float _chance = 0;
void ModifyEffectChance(ExecutingMove@ attack, Pokemon@ target, float& chance) override{_chance = chance;}
float GetChance() { return _chance; }
}
})");
asScriptResolver->FinalizeModule();
Library::SetStaticLib(staticLibrary);
Library::SetLibrary(battleLib);
doctest::Context context;
context.applyCommandLine(argc, argv);
int res = context.run(); // run
if (context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
return res; // propagate the result of the tests
int client_stuff_return_code = 0;
// your program - if the testing framework is integrated in your production code
return res + client_stuff_return_code; // the result from doctest is propagated here as well
}