This commit is contained in:
@@ -26,7 +26,7 @@ private:
|
||||
|
||||
void RegisterTypes();
|
||||
void InitializeByteCode(asIBinaryStream* stream,
|
||||
const Dictionary<ScriptCategory, Dictionary<ConstString, const char*>>& types);
|
||||
const Dictionary<ScriptCategory, Dictionary<ConstString, const char*>>& types);
|
||||
|
||||
public:
|
||||
~AngelScriptResolver() override {
|
||||
@@ -57,9 +57,9 @@ public:
|
||||
return _typeDatabase;
|
||||
}
|
||||
|
||||
asITypeInfo* GetBaseType(const ConstString& name){
|
||||
asITypeInfo* GetBaseType(const ConstString& name) {
|
||||
asITypeInfo* t = nullptr;
|
||||
if (!_baseTypes.TryGet(name, t)){
|
||||
if (!_baseTypes.TryGet(name, t)) {
|
||||
t = this->_engine->GetTypeInfoByDecl(name.c_str());
|
||||
_baseTypes.Insert(name, t);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ private:
|
||||
|
||||
asIScriptObject* _obj = nullptr;
|
||||
CScriptArray* GetEffectParameters(const List<CreatureLib::Library::EffectParameter*>& ls);
|
||||
|
||||
public:
|
||||
AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
|
||||
ContextPool* ctxPool)
|
||||
|
||||
@@ -82,8 +82,8 @@ public:
|
||||
SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const array<EffectParameter@> &in parameters)");
|
||||
SCRIPT_HOOK_FUNCTION(Stack, "void Stack()");
|
||||
SCRIPT_HOOK_FUNCTION(OnRemove, "void OnRemove()");
|
||||
SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)");
|
||||
SCRIPT_HOOK_FUNCTION(ChangeAttack, "void ChangeAttack(MoveTurnChoice@ choice, constString& changedMove)");
|
||||
SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)");
|
||||
SCRIPT_HOOK_FUNCTION(ChangeAttack, "void ChangeAttack(MoveTurnChoice@ choice, constString& changedMove)");
|
||||
|
||||
SCRIPT_HOOK_FUNCTION(PreventAttack, "void PreventAttack(ExecutingMove@ attack, bool& result)");
|
||||
SCRIPT_HOOK_FUNCTION(FailAttack, "void FailAttack(ExecutingMove@ attack, bool& result)");
|
||||
|
||||
@@ -13,7 +13,7 @@ private:
|
||||
#define MEM_STEPS 256
|
||||
|
||||
public:
|
||||
MemoryByteCodeStream() : _out((uint8_t*)malloc(MEM_STEPS * sizeof(uint8_t) )), _capacity(MEM_STEPS){};
|
||||
MemoryByteCodeStream() : _out((uint8_t*)malloc(MEM_STEPS * sizeof(uint8_t))), _capacity(MEM_STEPS){};
|
||||
MemoryByteCodeStream(uint8_t* in, size_t size) : _out(in), _size(size) {}
|
||||
|
||||
uint8_t* GetOut() const { return _out; }
|
||||
|
||||
@@ -11,8 +11,8 @@ class ContextPool {
|
||||
public:
|
||||
ContextPool(asIScriptEngine* engine) : _engine(engine) {}
|
||||
|
||||
~ContextPool(){
|
||||
for (auto ctx: _pool){
|
||||
~ContextPool() {
|
||||
for (auto ctx : _pool) {
|
||||
ctx->Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class RegisterBattleClass {
|
||||
static void RegisterChoiceQueue(asIScriptEngine* engine);
|
||||
static void RegisterBattle(asIScriptEngine* engine);
|
||||
static void RegisterBattleRandom(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
class RegisterBattleLibrary {
|
||||
static void RegisterDamageLibrary(asIScriptEngine* engine);
|
||||
static void RegisterLibrary(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "RegisterExecutingAttack.hpp"
|
||||
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <CreatureLib/Battling/Models/ExecutingAttack.hpp>
|
||||
|
||||
void RegisterExecutingAttack::Register(asIScriptEngine* engine) {
|
||||
RegisterHitData(engine);
|
||||
@@ -34,20 +34,16 @@ void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engin
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
Assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetHitData),
|
||||
asCALL_THISCALL);
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetHitData), asCALL_THISCALL);
|
||||
Assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget),
|
||||
asCALL_THISCALL);
|
||||
Assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetUser),
|
||||
asCALL_THISCALL);
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetUser), asCALL_THISCALL);
|
||||
Assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property",
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttack),
|
||||
asCALL_THISCALL);
|
||||
asMETHOD(CreatureLib::Battling::ExecutingAttack, GetAttack), asCALL_THISCALL);
|
||||
Assert(r >= 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
class RegisterExecutingAttack {
|
||||
static void RegisterHitData(asIScriptEngine* engine);
|
||||
static void RegisterExecutingAttackType(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "RegisterPokemonClass.hpp"
|
||||
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
|
||||
#include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
||||
#include "../../../../Battling/PkmnDamageSource.hpp"
|
||||
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
||||
|
||||
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
||||
#define ENUM__SIZE_WRAPPER(name, type, func) \
|
||||
@@ -19,13 +19,11 @@ void RegisterPokemonClass::Register(asIScriptEngine* engine) {
|
||||
void RegisterPokemonClass::RegisterDamageSource(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterEnum("DamageSource");
|
||||
Assert(r >= 0);
|
||||
for (auto v: CreatureLib::Battling::DamageSourceHelper::GetValues()){
|
||||
r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v),
|
||||
(int)v);
|
||||
for (auto v : CreatureLib::Battling::DamageSourceHelper::GetValues()) {
|
||||
r = engine->RegisterEnumValue("DamageSource", CreatureLib::Battling::DamageSourceHelper::ToString(v), (int)v);
|
||||
}
|
||||
for (auto v: PkmnDamageSourceHelper::GetValues()){
|
||||
r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v),
|
||||
(int)v);
|
||||
for (auto v : PkmnDamageSourceHelper::GetValues()) {
|
||||
r = engine->RegisterEnumValue("DamageSource", PkmnDamageSourceHelper::ToString(v), (int)v);
|
||||
}
|
||||
|
||||
Assert(r >= 0);
|
||||
@@ -94,7 +92,6 @@ static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString
|
||||
return obj->HasHeldItem(str.GetHash());
|
||||
}
|
||||
|
||||
|
||||
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
Assert(r >= 0);
|
||||
|
||||
@@ -7,6 +7,7 @@ class RegisterPokemonClass {
|
||||
static void RegisterMoveLearnMethod(asIScriptEngine* engine);
|
||||
static void RegisterLearnedAttack(asIScriptEngine* engine);
|
||||
static void RegisterPokemonType(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -73,7 +73,8 @@ void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) {
|
||||
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetUser), asCALL_THISCALL);
|
||||
Assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property",
|
||||
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature), asCALL_THISCALL);
|
||||
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature),
|
||||
asCALL_THISCALL);
|
||||
Assert(r >= 0);
|
||||
|
||||
r = engine->RegisterObjectMethod(
|
||||
|
||||
@@ -7,6 +7,7 @@ class RegisterTurnChoices {
|
||||
static void RegisterBaseTurnChoice(asIScriptEngine* engine);
|
||||
static void RegisterMoveTurnChoice(asIScriptEngine* engine);
|
||||
static void RegisterSwitchTurnChoice(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "ConstString.hpp"
|
||||
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||
|
||||
static void ConstructConstString(void* self) { new (self)ConstString(); }
|
||||
static void CopyConstructConstString(const ConstString& other, void* self) { new (self)ConstString(other); }
|
||||
static void DestructConstString(void* self) {
|
||||
((ConstString*)self)->~ConstString();
|
||||
}
|
||||
static void ConstructConstString(void* self) { new (self) ConstString(); }
|
||||
static void CopyConstructConstString(const ConstString& other, void* self) { new (self) ConstString(other); }
|
||||
static void DestructConstString(void* self) { ((ConstString*)self)->~ConstString(); }
|
||||
static bool ConstStringEquality(const ConstString& a, const ConstString& b) { return a == b; }
|
||||
static bool ConstStringStdStringEquality(const ConstString& a, const std::string& b) { return a == b; }
|
||||
static ConstString ImplStdStringConstStringConv(const std::string& s) { return ConstString(s); }
|
||||
|
||||
@@ -34,8 +34,8 @@ void RegisterGrowthRateTypes::RegisterGrowthRateLibrary(asIScriptEngine* engine)
|
||||
"uint8 CalculateLevel(const constString &in growthRate, uint experience) const",
|
||||
asFUNCTION(CalculateLevel), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("GrowthRateLibrary",
|
||||
"uint CalculateExperience(const constString &in growthRate, uint8 experience) const",
|
||||
asFUNCTION(CalculateExperience), asCALL_CDECL_OBJLAST);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"GrowthRateLibrary", "uint CalculateExperience(const constString &in growthRate, uint8 experience) const",
|
||||
asFUNCTION(CalculateExperience), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
class RegisterGrowthRateTypes {
|
||||
static void RegisterGrowthRateType(asIScriptEngine* engine);
|
||||
static void RegisterGrowthRateLibrary(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -23,7 +23,8 @@ void RegisterItemTypes::RegisterItemCategoryEnum(asIScriptEngine* engine) {
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "TM", (int)CreatureLib::Library::ItemCategory::MoveLearner);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("ItemCategory", "VariantChanger", (int)CreatureLib::Library::ItemCategory::VariantChanger);
|
||||
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);
|
||||
@@ -36,13 +37,17 @@ void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine)
|
||||
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);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "Healing",
|
||||
(int)CreatureLib::Library::BattleItemCategory::Healing);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "StatusHealing", (int)CreatureLib::Library::BattleItemCategory::StatusHealing);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "StatusHealing",
|
||||
(int)CreatureLib::Library::BattleItemCategory::StatusHealing);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "CaptureDevice", (int)CreatureLib::Library::BattleItemCategory::CaptureDevice);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "CaptureDevice",
|
||||
(int)CreatureLib::Library::BattleItemCategory::CaptureDevice);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "Misc", (int)CreatureLib::Library::BattleItemCategory::MiscBattleItem);
|
||||
r = engine->RegisterEnumValue("BattleItemCategory", "Misc",
|
||||
(int)CreatureLib::Library::BattleItemCategory::MiscBattleItem);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
@@ -57,7 +62,6 @@ static bool HasFlag(const PkmnLib::Library::Item* obj, const Arbutils::CaseInsen
|
||||
return obj->HasFlag(str);
|
||||
}
|
||||
|
||||
|
||||
void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
assert(r >= 0);
|
||||
@@ -73,11 +77,9 @@ void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
|
||||
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 constString &in flag) const",
|
||||
asFUNCTION(HasFlag), asCALL_CDECL_OBJLAST);
|
||||
r = engine->RegisterObjectMethod("Item", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
|
||||
|
||||
}
|
||||
void RegisterItemTypes::RegisterItemLibrary(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("ItemLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
|
||||
@@ -7,6 +7,7 @@ class RegisterItemTypes {
|
||||
static void RegisterBattleItemCategoryEnum(asIScriptEngine* engine);
|
||||
static void RegisterItemType(asIScriptEngine* engine);
|
||||
static void RegisterItemLibrary(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -77,8 +77,8 @@ void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
|
||||
asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const",
|
||||
asFUNCTION(HasFlag), asCALL_CDECL_OBJLAST);
|
||||
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
|
||||
asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
}
|
||||
void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) {
|
||||
|
||||
@@ -7,6 +7,7 @@ class RegisterMoveTypes {
|
||||
static void RegisterMoveTarget(asIScriptEngine* engine);
|
||||
static void RegisterMoveType(asIScriptEngine* engine);
|
||||
static void RegisterMoveLibrary(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -41,6 +41,4 @@ void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property",
|
||||
asMETHOD(PkmnLib::Library::PokemonLibrary, GetTypeLibrary), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
class RegisterStaticLibraryTypes {
|
||||
static void RegisterLibrarySettingsType(asIScriptEngine* engine);
|
||||
static void RegisterLibraryType(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
#include <CreatureLib/Library/TypeLibrary.hpp>
|
||||
#include <cassert>
|
||||
|
||||
void RegisterTypeLibrary::Register(asIScriptEngine* engine) {
|
||||
RegisterTypeLibraryType(engine);
|
||||
}
|
||||
void RegisterTypeLibrary::Register(asIScriptEngine* engine) { RegisterTypeLibraryType(engine); }
|
||||
|
||||
static bool GetTypeId(const CreatureLib::Library::TypeLibrary* obj, const Arbutils::CaseInsensitiveConstString& str) {
|
||||
return obj->GetTypeId(str);
|
||||
@@ -16,8 +14,9 @@ void RegisterTypeLibrary::RegisterTypeLibraryType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("TypeLibrary", "uint8 GetTypeId(const constString &in name) const",
|
||||
asFUNCTION(GetTypeId), asCALL_CDECL_OBJLAST);
|
||||
assert(r >= 0);
|
||||
r = engine->RegisterObjectMethod("TypeLibrary", "float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const",
|
||||
asMETHOD(CreatureLib::Library::TypeLibrary, GetSingleEffectiveness), asCALL_THISCALL);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"TypeLibrary", "float GetSingleEffectiveness(uint8 attacking, uint8 defensive) const",
|
||||
asMETHOD(CreatureLib::Library::TypeLibrary, GetSingleEffectiveness), asCALL_THISCALL);
|
||||
assert(r >= 0);
|
||||
//TODO: Register get full effectiveness method.
|
||||
// TODO: Register get full effectiveness method.
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
class RegisterTypeLibrary {
|
||||
static void RegisterTypeLibraryType(asIScriptEngine* engine);
|
||||
|
||||
public:
|
||||
static void Register(asIScriptEngine* engine);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#ifndef PKMNLIB_REFCAST_HPP
|
||||
#define PKMNLIB_REFCAST_HPP
|
||||
template<class A, class B>
|
||||
B* refCast(A* a)
|
||||
{
|
||||
if( !a ) return 0;
|
||||
template <class A, class B> B* refCast(A* a) {
|
||||
if (!a)
|
||||
return 0;
|
||||
B* b = dynamic_cast<B*>(a);
|
||||
return b;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user