100 lines
4.6 KiB
C++
100 lines
4.6 KiB
C++
#define CATCH_CONFIG_RUNNER
|
|
#include <PkmnLib/ScriptResolving/AngelScript/AngelScripResolver.hpp>
|
|
#include "../extern/catch.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;
|
|
|
|
static constexpr const char* GetCategoryPath(CreatureLib::Battling::ScriptResolver::ScriptCategory category){
|
|
switch (category){
|
|
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack: return "Moves";
|
|
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Talent: return "Abilities";
|
|
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Status: return "Status";
|
|
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Creature: return "Pokemon";
|
|
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Battle: return "Battle";
|
|
case CreatureLib::Battling::ScriptResolver::ScriptCategory::Side: return "Side";
|
|
}
|
|
}
|
|
|
|
|
|
static const char* LoadFunc(CreatureLib::Battling::ScriptResolver::ScriptCategory category, const char* scriptName){
|
|
auto categoryStr = GetCategoryPath(category);
|
|
char fullPath[strlen(ScriptsPath) + 1 + strlen(categoryStr) + 1 + strlen(scriptName) + 3];
|
|
strcpy(fullPath, ScriptsPath);
|
|
strcat(fullPath, "/");
|
|
strcat(fullPath, categoryStr);
|
|
strcat(fullPath, "/");
|
|
strcat(fullPath, scriptName);
|
|
strcat(fullPath, ".as");
|
|
std::ifstream in(fullPath);
|
|
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
|
char res[contents.size()];
|
|
return strcpy(res, contents.c_str());
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
Catch::Session session;
|
|
|
|
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";
|
|
|
|
using namespace Catch::clara;
|
|
auto cli = session.cli() | Opt(pokemonFile, "Species")["--species"]("Which species file to load.") |
|
|
Opt(typesFile, "Types")["--types"]("Which Types file to load.") |
|
|
Opt(naturesFile, "Natures")["--natures"]("Which Natures file to load.") |
|
|
Opt(moveFile, "Moves")["--moves"]("Which Moves file to load.") |
|
|
Opt(itemsFile, "Items")["--items"]("Which Items file to load.") |
|
|
Opt(growthRatesFile, "Growthrates")["--growthrates"]("Which Growthrates file to load.") |
|
|
Opt(scriptsPath, "Scripts")["--scripts"]("Which Scripts path to load scripts from.");
|
|
|
|
session.cli(cli);
|
|
|
|
int returnCode = session.applyCommandLine(argc, argv);
|
|
if (returnCode != 0) // Indicates a command line error
|
|
return returnCode;
|
|
|
|
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 CreatureLib::Battling::ExperienceLibrary(), scriptResolver, new CreatureLib::Battling::MiscLibrary());
|
|
|
|
scriptResolver->Initialize(battleLib);
|
|
|
|
auto asScriptResolver = dynamic_cast<AngelScripResolver*>(scriptResolver);
|
|
asScriptResolver->SetCreateFunction(LoadFunc);
|
|
asScriptResolver->CreateScript(CreatureLib::Battling::ScriptResolver::ScriptCategory::Attack, "absorb");
|
|
asScriptResolver->FinalizeModule();
|
|
|
|
Library::SetStaticLib(staticLibrary);
|
|
Library::SetLibrary(battleLib);
|
|
|
|
return session.run();
|
|
} |