From 574776dbe0c9fb86daf6894eb0df177175f53f5b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 13 Jan 2020 19:21:41 +0100 Subject: [PATCH] Register Item types for AngelScript. --- CMakeLists.txt | 6 +- src/AngelScript/AngelScripResolver.cpp | 6 +- .../TypeRegistry/RegisterItemTypes.cpp | 67 +++++++++++++++++++ .../TypeRegistry/RegisterItemTypes.hpp | 13 ++++ 4 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 src/AngelScript/TypeRegistry/RegisterItemTypes.cpp create mode 100644 src/AngelScript/TypeRegistry/RegisterItemTypes.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7380e9e..ff44052 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,10 +60,8 @@ SET(FILE_SOURCE ) if (SCRIPT_PROVIDER STREQUAL "angelscript") SET(FILE_SOURCE ${FILE_SOURCE} - "src/AngelScript/AngelScripResolver.cpp" - "src/AngelScript/AngelScripResolver.hpp" - "src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp" - "src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp" + "src/AngelScript/*.cpp" + "src/AngelScript/*.hpp" "extern/angelscript_addons/*.cpp" "extern/angelscript_addons/*.h" ) diff --git a/src/AngelScript/AngelScripResolver.cpp b/src/AngelScript/AngelScripResolver.cpp index c804694..2d459b9 100644 --- a/src/AngelScript/AngelScripResolver.cpp +++ b/src/AngelScript/AngelScripResolver.cpp @@ -1,7 +1,8 @@ #include "AngelScripResolver.hpp" -#include "TypeRegistry/RegisterPokemonTypes.hpp" -#include "../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h" #include "../../extern/angelscript_addons/scripthelper/scripthelper.h" +#include "../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h" +#include "TypeRegistry/RegisterItemTypes.hpp" +#include "TypeRegistry/RegisterPokemonTypes.hpp" CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver(){ return new AngelScripResolver(); @@ -26,6 +27,7 @@ void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* librar RegisterExceptionRoutines(_engine); RegisterPokemonTypes::Register(_engine); + RegisterItemTypes::Register(_engine); _mainModule = _engine->GetModule("pkmn", asGM_ALWAYS_CREATE); diff --git a/src/AngelScript/TypeRegistry/RegisterItemTypes.cpp b/src/AngelScript/TypeRegistry/RegisterItemTypes.cpp new file mode 100644 index 0000000..7b59711 --- /dev/null +++ b/src/AngelScript/TypeRegistry/RegisterItemTypes.cpp @@ -0,0 +1,67 @@ +#include "RegisterItemTypes.hpp" +#include +#include "../../Library/Items/Item.hpp" + +void RegisterItemTypes::Register(asIScriptEngine* engine) { + RegisterItemCategoryEnum(engine); + RegisterBattleItemCategoryEnum(engine); + RegisterItemType(engine); +} + +void RegisterItemTypes::RegisterItemCategoryEnum(asIScriptEngine* engine) { + [[maybe_unused]] int r = engine->RegisterEnum("ItemCategory"); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "Misc", (int)CreatureLib::Library::ItemCategory::MiscItem); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "Pokeball", (int)CreatureLib::Library::ItemCategory::CaptureDevice); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "Medicine", (int)CreatureLib::Library::ItemCategory::Medicine); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "Berry", (int)CreatureLib::Library::ItemCategory::Berry); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "TM", (int)CreatureLib::Library::ItemCategory::TM); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "VariantChanger", (int)CreatureLib::Library::ItemCategory::VariantChanger); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "KeyItem", (int)CreatureLib::Library::ItemCategory::KeyItem); + assert(r >= 0); + r = engine->RegisterEnumValue("ItemCategory", "Mail", (int)CreatureLib::Library::ItemCategory::Mail); + assert(r >= 0); +} + +void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine) { + [[maybe_unused]] int r = engine->RegisterEnum("BattleItemCategory"); + assert(r >= 0); + r = engine->RegisterEnumValue("BattleItemCategory", "None", (int)CreatureLib::Library::BattleItemCategory::None); + assert(r >= 0); + r = engine->RegisterEnumValue("BattleItemCategory", "Healing", (int)CreatureLib::Library::BattleItemCategory::Healing); + assert(r >= 0); + r = engine->RegisterEnumValue("BattleItemCategory", "StatusHealing", (int)CreatureLib::Library::BattleItemCategory::StatusHealing); + assert(r >= 0); + r = engine->RegisterEnumValue("BattleItemCategory", "CaptureDevice", (int)CreatureLib::Library::BattleItemCategory::CaptureDevice); + assert(r >= 0); + r = engine->RegisterEnumValue("BattleItemCategory", "Misc", (int)CreatureLib::Library::BattleItemCategory::MiscBattleItem); + assert(r >= 0); +} + +void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) { + [[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT); + assert(r >= 0); + r = engine->RegisterObjectMethod("Item", "const string& get_Name() const property", + asMETHOD(PkmnLib::Library::Item, GetName), asCALL_THISCALL); + assert(r >= 0); + r = engine->RegisterObjectMethod("Item", "ItemCategory get_Category() const property", + asMETHOD(PkmnLib::Library::Item, GetCategory), asCALL_THISCALL); + assert(r >= 0); + r = engine->RegisterObjectMethod("Item", "BattleItemCategory get_BattleCategory() const property", + asMETHOD(PkmnLib::Library::Item, GetBattleCategory), asCALL_THISCALL); + assert(r >= 0); + r = engine->RegisterObjectMethod("Item", "int get_Price() const property", + asMETHOD(PkmnLib::Library::Item, GetPrice), asCALL_THISCALL); + assert(r >= 0); + r = engine->RegisterObjectMethod("Item", "bool HasFlag(const string &in flag) const", + asMETHOD(PkmnLib::Library::Item, HasFlag), asCALL_THISCALL); + assert(r >= 0); + + +} diff --git a/src/AngelScript/TypeRegistry/RegisterItemTypes.hpp b/src/AngelScript/TypeRegistry/RegisterItemTypes.hpp new file mode 100644 index 0000000..7b775da --- /dev/null +++ b/src/AngelScript/TypeRegistry/RegisterItemTypes.hpp @@ -0,0 +1,13 @@ +#ifndef PKMNLIB_REGISTERITEMTYPES_HPP +#define PKMNLIB_REGISTERITEMTYPES_HPP +#include + +class RegisterItemTypes { + static void RegisterItemCategoryEnum(asIScriptEngine* engine); + static void RegisterBattleItemCategoryEnum(asIScriptEngine* engine); + static void RegisterItemType(asIScriptEngine* engine); +public: + static void Register(asIScriptEngine* engine); +}; + +#endif // PKMNLIB_REGISTERITEMTYPES_HPP