This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver(){
|
||||
return new AngelScripResolver();
|
||||
}
|
||||
|
||||
void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* library) {
|
||||
_engine = asCreateScriptEngine();
|
||||
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
#include <Battling/ScriptHandling/ScriptResolver.hpp>
|
||||
#include "../Battling/Library/BattleLibrary.hpp"
|
||||
|
||||
#undef GetProperty
|
||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <angelscript.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include "AngelScriptScript.hpp"
|
||||
#include "AngelScriptTypeInfo.hpp"
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
#undef GetProperty
|
||||
#include "AngelScriptScript.hpp"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
||||
#define PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
||||
#include <Battling/ScriptHandling/Script.hpp>
|
||||
#undef GetProperty
|
||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <angelscript.h>
|
||||
#include "AngelScriptTypeInfo.hpp"
|
||||
#include "ContextPool.hpp"
|
||||
@@ -15,20 +15,20 @@ private:
|
||||
|
||||
public:
|
||||
AngelScriptScript(const std::string& name, AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool)
|
||||
: CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) {
|
||||
}
|
||||
: CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
||||
|
||||
~AngelScriptScript() override { _obj->Release(); }
|
||||
|
||||
void InvokeMethod(const char* name) {
|
||||
auto func = _type->GetFunction(name);
|
||||
if (func == nullptr) return;
|
||||
if (func == nullptr)
|
||||
return;
|
||||
auto ctx = _ctxPool->RequestContext();
|
||||
ctx->Prepare(func);
|
||||
ctx->SetObject(_obj);
|
||||
auto result = ctx->Execute();
|
||||
if (result != asEXECUTION_FINISHED){
|
||||
if (result == asEXECUTION_EXCEPTION){
|
||||
if (result != asEXECUTION_FINISHED) {
|
||||
if (result == asEXECUTION_EXCEPTION) {
|
||||
throw CreatureException(ctx->GetExceptionString());
|
||||
}
|
||||
throw CreatureException("Function failed.");
|
||||
@@ -36,20 +36,16 @@ public:
|
||||
_ctxPool->ReturnContextToPool(ctx);
|
||||
}
|
||||
|
||||
asIScriptObject* GetScriptObject(){
|
||||
return _obj;
|
||||
}
|
||||
asIScriptObject* GetScriptObject() { return _obj; }
|
||||
|
||||
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx){
|
||||
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) {
|
||||
auto func = _type->GetFunction(name);
|
||||
ctx->Prepare(func);
|
||||
ctx->SetObject(_obj);
|
||||
return func;
|
||||
}
|
||||
|
||||
ContextPool* GetContextPool(){
|
||||
return _ctxPool;
|
||||
}
|
||||
ContextPool* GetContextPool() { return _ctxPool; }
|
||||
};
|
||||
|
||||
#endif // PKMNLIB_ANGELSCRIPTSCRIPT_HPP
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
||||
#define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
||||
|
||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <angelscript.h>
|
||||
#include <unordered_map>
|
||||
#include <Core/Exceptions/CreatureException.hpp>
|
||||
|
||||
@@ -8,13 +8,14 @@ void RegisterPokemonTypes::Register(asIScriptEngine* engine) {
|
||||
}
|
||||
|
||||
void RegisterPokemonTypes::RegisterGenderEnum(asIScriptEngine* engine) {
|
||||
int r = engine->RegisterEnum("Gender"); assert(r >= 0);
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("Gender"); assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Gender", "Male", 0); assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Gender", "Female", 1); assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("Gender", "Genderless", 2); assert(r >= 0);
|
||||
}
|
||||
|
||||
void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]]
|
||||
int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("Species", "const string& get_Name() const property",
|
||||
@@ -32,5 +33,4 @@ void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("Species", "Gender GetRandomGender() const",
|
||||
asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "CreatePokemon.hpp"
|
||||
#include "../../Library/Statistic.hpp"
|
||||
|
||||
PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) {
|
||||
_ivHp = rand.Get(0, 32);
|
||||
_ivAttack = rand.Get(0, 32);
|
||||
|
||||
@@ -30,10 +30,10 @@ namespace PkmnLib::Battling {
|
||||
_individualValues(individualValues), _effortValues(effortValues), _nature(nature) {}
|
||||
|
||||
const Library::Nature& GetNature() const;
|
||||
const uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const {
|
||||
uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const {
|
||||
return _individualValues.GetStat(stat);
|
||||
}
|
||||
const uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); }
|
||||
uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user