From 2a39467899d4af26869c54f2118465b0e6e788fa Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 9 Jan 2020 17:03:34 +0100 Subject: [PATCH] Initial layout work for allowing multiple script providers, but defaulting to AngelScript. --- CMakeLists.txt | 26 ++++++++++++++++--- src/AngelScript/AngelScriptScript.cpp | 1 + src/AngelScript/AngelScriptScript.hpp | 6 +++++ src/AngelScript/PokemonScriptResolver.cpp | 11 ++++++++ .../Library/PokemonScriptResolver.hpp | 15 +++++++++++ tests/TestLibrary/TestLibrary.hpp | 8 ++++-- 6 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/AngelScript/AngelScriptScript.cpp create mode 100644 src/AngelScript/AngelScriptScript.hpp create mode 100644 src/AngelScript/PokemonScriptResolver.cpp create mode 100644 src/Battling/Library/PokemonScriptResolver.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f3c1941..66ccd9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,11 @@ project(pkmnLib) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (NOT SCRIPT_PROVIDER) + message(WARNING "Script provider was not set, using angelscript as default.") + set(SCRIPT_PROVIDER "angelscript") +endif() + if (WINDOWS) SET(CMAKE_SYSTEM_NAME Windows) ADD_DEFINITIONS(-D WINDOWS=1) @@ -22,6 +27,8 @@ message(STATUS "Using: \t CXX ABI ${CMAKE_CXX_COMPILER_ABI} \t C++ Version ${CMAKE_CXX_STANDARD}") +message(STATUS "Script Provider: ${SCRIPT_PROVIDER}") + if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.") string(REPLACE "." ";" VERSION_LIST "${CMAKE_C_COMPILER_VERSION}") @@ -47,11 +54,22 @@ foreach (_conanLib ${CONAN_LIBS}) endforeach() # Create Core library with files in src/Core -file(GLOB_RECURSE CORE_SRC_FILES "src/*.cpp" "src/*.hpp") +file(GLOB_RECURSE CORE_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "src/Library/*.cpp" "src/Library/*.hpp") add_library(pkmnLib SHARED ${CORE_SRC_FILES}) -SET(_LINKS ${CONAN_LIBS}) -SET(_TESTLINKS pkmnLib ${CONAN_LIBS}) +SET(_LINKS CreatureLibCore CreatureLibLibrary CreatureLibBattling) +SET(_TESTLINKS pkmnLib CreatureLibCore CreatureLibLibrary CreatureLibBattling) + +if (SCRIPT_PROVIDER STREQUAL "angelscript") + message(STATUS "Creating angelscript implementation.") + file(GLOB_RECURSE ANGELSCRIPT_SRC_FILES "src/AngelScript/*.cpp" "src/AngelScript/*.hpp") + add_library(pkmnLib-angelscript SHARED ${ANGELSCRIPT_SRC_FILES}) + SET(SCRIPT_PROVIDER_LIB_NAME "pkmnLib-angelscript") + + target_link_libraries(pkmnLib-angelscript PUBLIC ${_LINKS} angelscript) +endif() + + if (WINDOWS) message(STATUS "Using Windows build.") @@ -69,7 +87,7 @@ if (NOT DEFINED CONAN_EXPORTED) # Create Test executable file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp") add_executable(pkmnLibTests ${TEST_FILES} extern/catch.hpp) - target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS}) + target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS} ${SCRIPT_PROVIDER_LIB_NAME}) # Add a definition for the test library target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD) diff --git a/src/AngelScript/AngelScriptScript.cpp b/src/AngelScript/AngelScriptScript.cpp new file mode 100644 index 0000000..97d92e6 --- /dev/null +++ b/src/AngelScript/AngelScriptScript.cpp @@ -0,0 +1 @@ +#include "AngelScriptScript.hpp" diff --git a/src/AngelScript/AngelScriptScript.hpp b/src/AngelScript/AngelScriptScript.hpp new file mode 100644 index 0000000..f2b5a88 --- /dev/null +++ b/src/AngelScript/AngelScriptScript.hpp @@ -0,0 +1,6 @@ +#ifndef PKMNLIB_ANGELSCRIPTSCRIPT_HPP +#define PKMNLIB_ANGELSCRIPTSCRIPT_HPP + +class AngelScriptScript {}; + +#endif // PKMNLIB_ANGELSCRIPTSCRIPT_HPP diff --git a/src/AngelScript/PokemonScriptResolver.cpp b/src/AngelScript/PokemonScriptResolver.cpp new file mode 100644 index 0000000..77080ef --- /dev/null +++ b/src/AngelScript/PokemonScriptResolver.cpp @@ -0,0 +1,11 @@ +#include "../Battling/Library/PokemonScriptResolver.hpp" +using namespace PkmnLib::Battling; + +void PokemonScriptResolver::Initialize(const PkmnLib::Battling::BattleLibrary* library){ + +} + +CreatureLib::Battling::Script* PokemonScriptResolver::LoadScript(ScriptCategory category, const std::string& scriptName){ + return nullptr; +} + diff --git a/src/Battling/Library/PokemonScriptResolver.hpp b/src/Battling/Library/PokemonScriptResolver.hpp new file mode 100644 index 0000000..cda9ecb --- /dev/null +++ b/src/Battling/Library/PokemonScriptResolver.hpp @@ -0,0 +1,15 @@ +#ifndef PKMNLIB_POKEMONSCRIPTRESOLVER_HPP +#define PKMNLIB_POKEMONSCRIPTRESOLVER_HPP + +#include +#include "../../Battling/Library/BattleLibrary.hpp" +namespace PkmnLib::Battling { + class PokemonScriptResolver : public CreatureLib::Battling::ScriptResolver { + public: + ~PokemonScriptResolver() override = default; + void Initialize(const PkmnLib::Battling::BattleLibrary* library); + CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const std::string& scriptName) override; + }; +} + +#endif // PKMNLIB_POKEMONSCRIPTRESOLVER_HPP diff --git a/tests/TestLibrary/TestLibrary.hpp b/tests/TestLibrary/TestLibrary.hpp index 27aae12..f4504d1 100644 --- a/tests/TestLibrary/TestLibrary.hpp +++ b/tests/TestLibrary/TestLibrary.hpp @@ -3,6 +3,7 @@ #include #include "../../src/Battling/Library/BattleLibrary.hpp" +#include "../../src/Battling/Library/PokemonScriptResolver.hpp" #include "../../src/Library/Moves/MoveLibrary.hpp" #include "../../src/Library/PokemonLibrary.hpp" #include "../../src/Library/Statistic.hpp" @@ -20,10 +21,13 @@ public: static PkmnLib::Battling::BattleLibrary* BuildLibrary() { auto statCalc = new PkmnLib::Battling::StatCalculator(); - return new PkmnLib::Battling::BattleLibrary( + auto scriptResolver = new PkmnLib::Battling::PokemonScriptResolver(); + auto lib = new PkmnLib::Battling::BattleLibrary( BuildStaticLibrary(), statCalc, new CreatureLib::Battling::DamageLibrary(), - new CreatureLib::Battling::ExperienceLibrary(), new CreatureLib::Battling::ScriptResolver(), + new CreatureLib::Battling::ExperienceLibrary(), scriptResolver, new CreatureLib::Battling::MiscLibrary()); + scriptResolver->Initialize(lib); + return lib; } static PkmnLib::Library::PokemonLibrary* BuildStaticLibrary() {