Support for new version of CreatureLib.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "PokemonForme.hpp"
|
||||
PkmnLib::Library::PokemonForme::PokemonForme(std::string name, float height, float weight, uint32_t baseExperience,
|
||||
PkmnLib::Library::PokemonForme::PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience,
|
||||
std::vector<uint8_t> types,
|
||||
CreatureLib::Core::StatisticSet<uint16_t> baseStats,
|
||||
std::vector<std::string> talents, std::vector<std::string> secretTalents,
|
||||
std::vector<ConstString> talents, std::vector<ConstString> secretTalents,
|
||||
const CreatureLib::Library::LearnableAttacks* attacks)
|
||||
: SpeciesVariant(name, height, weight, baseExperience, types, baseStats, talents, secretTalents, attacks) {}
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
namespace PkmnLib::Library {
|
||||
class PokemonForme : public CreatureLib::Library::SpeciesVariant {
|
||||
public:
|
||||
PokemonForme(std::string name, float height, float weight, uint32_t baseExperience, std::vector<uint8_t> types,
|
||||
CreatureLib::Core::StatisticSet<uint16_t> baseStats, std::vector<std::string> talents,
|
||||
std::vector<std::string> secretTalents, const CreatureLib::Library::LearnableAttacks* attacks);
|
||||
PokemonForme(ConstString name, float height, float weight, uint32_t baseExperience, std::vector<uint8_t> types,
|
||||
CreatureLib::Core::StatisticSet<uint16_t> baseStats, std::vector<ConstString> talents,
|
||||
std::vector<ConstString> secretTalents, const CreatureLib::Library::LearnableAttacks* attacks);
|
||||
|
||||
private:
|
||||
public:
|
||||
inline const std::string& GetAbility(int index) const { return GetTalent(index); }
|
||||
inline const ConstString& GetAbility(int index) const { return GetTalent(index); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -85,18 +85,18 @@ void AngelScripResolver::RegisterTypes() {
|
||||
BasicScriptClass::Register(_engine);
|
||||
}
|
||||
|
||||
AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const std::string& name, const std::string& decl) {
|
||||
auto find = _types.find(decl);
|
||||
AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const ConstString& name, const std::string& decl) {
|
||||
auto find = _types.find(name);
|
||||
if (find != _types.end()) {
|
||||
return find->second;
|
||||
}
|
||||
auto type = _mainModule->GetTypeInfoByDecl(decl.c_str());
|
||||
if (type == nullptr) {
|
||||
_types.insert({decl, nullptr});
|
||||
_types.insert({name, nullptr});
|
||||
return nullptr;
|
||||
}
|
||||
auto typeinfo = new AngelScriptTypeInfo(name, type);
|
||||
_types.insert({decl, typeinfo});
|
||||
_types.insert({name, typeinfo});
|
||||
return typeinfo;
|
||||
}
|
||||
void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) {
|
||||
@@ -120,9 +120,9 @@ static constexpr const char* GetCategoryNamespace(ScriptCategory category) {
|
||||
}
|
||||
}
|
||||
|
||||
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) {
|
||||
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const ConstString& scriptName) {
|
||||
std::stringstream decl;
|
||||
decl << GetCategoryNamespace(category) << "::" << scriptName;
|
||||
decl << GetCategoryNamespace(category) << "::" << scriptName.c_str();
|
||||
auto typeInfo = GetTypeInfo(scriptName, decl.str());
|
||||
if (typeInfo == nullptr)
|
||||
return nullptr;
|
||||
|
||||
@@ -17,11 +17,11 @@ private:
|
||||
asIScriptModule* _mainModule = nullptr;
|
||||
ContextPool* _contextPool = nullptr;
|
||||
CScriptBuilder _builder;
|
||||
std::unordered_map<std::string, AngelScriptTypeInfo*> _types;
|
||||
std::unordered_map<ConstString, AngelScriptTypeInfo*> _types;
|
||||
|
||||
static void MessageCallback(const asSMessageInfo* msg, void* param);
|
||||
static void Print(const std::string& str) { std::cout << str << std::endl; }
|
||||
AngelScriptTypeInfo* GetTypeInfo(const std::string& name, const std::string& decl);
|
||||
AngelScriptTypeInfo* GetTypeInfo(const ConstString& name, const std::string& decl);
|
||||
|
||||
void RegisterTypes();
|
||||
|
||||
@@ -40,6 +40,6 @@ public:
|
||||
|
||||
void FinalizeModule();
|
||||
|
||||
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const std::string& scriptName) override;
|
||||
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const ConstString& scriptName) override;
|
||||
};
|
||||
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
~AngelScriptScript() override { _obj->Release(); }
|
||||
|
||||
[[nodiscard]] const std::string& GetName() const override { return _type->GetName(); }
|
||||
[[nodiscard]] const ConstString& GetName() const override { return _type->GetName(); }
|
||||
|
||||
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) {
|
||||
auto func = _type->GetFunction(name);
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
if (scriptResult != asEXECUTION_FINISHED) { \
|
||||
if (scriptResult == asEXECUTION_EXCEPTION) { \
|
||||
std::stringstream err; \
|
||||
err << "Script exception in script '" << GetName() << "', line " << ctx->GetExceptionLineNumber() \
|
||||
err << "Script exception in script '" << GetName().c_str() << "', line " << ctx->GetExceptionLineNumber() \
|
||||
<< ". Message: '" << ctx->GetExceptionString() << "'."; \
|
||||
throw CreatureException(err.str()); \
|
||||
} \
|
||||
|
||||
@@ -2,17 +2,20 @@
|
||||
#define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP
|
||||
|
||||
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <CreatureLib/Core/Exceptions/CreatureException.hpp>
|
||||
#include <angelscript.h>
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
|
||||
class AngelScriptTypeInfo {
|
||||
private:
|
||||
asITypeInfo* _type = nullptr;
|
||||
std::unordered_map<std::string, asIScriptFunction*> _functions;
|
||||
std::string _name;
|
||||
ConstString _name;
|
||||
|
||||
struct FunctionInfo {
|
||||
bool Exists = false;
|
||||
@@ -31,7 +34,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
explicit AngelScriptTypeInfo(std::string name, asITypeInfo* type) : _type(type), _name(std::move(name)) {}
|
||||
explicit AngelScriptTypeInfo(const ConstString& name, asITypeInfo* type) : _type(type), _name(name) {}
|
||||
~AngelScriptTypeInfo() {
|
||||
for (const auto& f : _functions) {
|
||||
f.second->Release();
|
||||
@@ -39,7 +42,7 @@ public:
|
||||
_functions.clear();
|
||||
}
|
||||
|
||||
const std::string& GetName() const{
|
||||
const ConstString& GetName() const{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,10 +62,10 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Battle", "void AddVolatile(const string &in name) const",
|
||||
asMETHODPR(CreatureLib::Battling::Battle, AddVolatileScript, (const std::string&), void), asCALL_THISCALL);
|
||||
asMETHODPR(CreatureLib::Battling::Battle, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Battle", "void RemoveVolatile(const string &in name) const",
|
||||
asMETHODPR(CreatureLib::Battling::Battle, RemoveVolatileScript, (const std::string&), void), asCALL_THISCALL);
|
||||
asMETHODPR(CreatureLib::Battling::Battle, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
@@ -179,10 +179,10 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Pokemon", "void AddVolatile(const string &in name) const",
|
||||
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const std::string&), void), asCALL_THISCALL);
|
||||
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ConstString&), void), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Pokemon", "void RemoveVolatile(const string &in name) const",
|
||||
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const std::string&), void), asCALL_THISCALL);
|
||||
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ConstString&), void), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
}
|
||||
Reference in New Issue
Block a user