Update to latest CreatureLib
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-05-14 16:50:20 +02:00
parent 50c58a9fd3
commit cf34563a56
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
22 changed files with 58 additions and 54 deletions

View File

@ -15,7 +15,7 @@ export_func uint8_t PkmnLib_AngelScriptResolver_CreateScript(AngelScriptResolver
export_func uint8_t PkmnLib_AngelScriptResolver_FinalizeModule(AngelScriptResolver* p) { Try(p->FinalizeModule();) } export_func uint8_t PkmnLib_AngelScriptResolver_FinalizeModule(AngelScriptResolver* p) { Try(p->FinalizeModule();) }
export_func uint8_t PkmnLib_AngelScriptResolver_LoadScript(CreatureLib::Battling::BattleScript*& out, AngelScriptResolver* p, export_func uint8_t PkmnLib_AngelScriptResolver_LoadScript(CreatureLib::Battling::BattleScript*& out, AngelScriptResolver* p,
void* owner, ScriptCategory category, const char* scriptName) { void* owner, ScriptCategory category, const char* scriptName) {
Try(out = p->LoadScript(owner, category, ArbUt::StringView(scriptName));) Try(out = p->LoadScript(owner, category, ArbUt::StringView(scriptName)).TakeOwnership();)
} }
export_func uint8_t PkmnLib_AngelScriptResolver_LoadEvolutionScript(PkmnLib::Battling::EvolutionScript const*& out, export_func uint8_t PkmnLib_AngelScriptResolver_LoadEvolutionScript(PkmnLib::Battling::EvolutionScript const*& out,
AngelScriptResolver* p, const char* scriptName) { AngelScriptResolver* p, const char* scriptName) {

View File

@ -6,18 +6,18 @@ bool PkmnLib::Battling::Battle::SetWeather(const ArbUt::StringView& name) {
if (blockWeather) { if (blockWeather) {
return false; return false;
} }
if (_weatherScript != nullptr) { if (_weatherScript.HasValue()) {
_weatherScript->OnRemove(); _weatherScript.GetValue()->OnRemove();
} }
_weatherScript = std::unique_ptr<CreatureLib::Battling::BattleScript>( _weatherScript =
_library->LoadScript(this, static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name)); _library->LoadScript(this, static_cast<ScriptCategory>(PkmnScriptCategory::Weather), name).TakeOwnership();
_eventHook.Trigger<WeatherChangeEvent>(name); _eventHook.Trigger<WeatherChangeEvent>(name);
return true; return true;
} }
void PkmnLib::Battling::Battle::ClearWeather() { void PkmnLib::Battling::Battle::ClearWeather() {
if (_weatherScript == nullptr) if (!_weatherScript.HasValue())
return; return;
_weatherScript->OnRemove(); _weatherScript.GetValue()->OnRemove();
_weatherScript = nullptr; _weatherScript = nullptr;
_eventHook.Trigger<WeatherChangeEvent>(""_cnc); _eventHook.Trigger<WeatherChangeEvent>(""_cnc);
} }
@ -65,8 +65,8 @@ PkmnLib::Battling::Battle* PkmnLib::Battling::Battle::Clone() const {
battle->_battleResult = _battleResult; battle->_battleResult = _battleResult;
battle->_currentTurn = _currentTurn; battle->_currentTurn = _currentTurn;
_volatile.Clone(battle, battle->_volatile); _volatile.Clone(battle, battle->_volatile);
if (_weatherScript != nullptr) { if (_weatherScript.HasValue()) {
battle->_weatherScript = std::unique_ptr<CreatureLib::Battling::BattleScript>(_weatherScript->Clone(battle)); battle->_weatherScript = _weatherScript.GetValue()->Clone(battle);
} }
return battle; return battle;

View File

@ -10,7 +10,7 @@
namespace PkmnLib::Battling { namespace PkmnLib::Battling {
class Battle : public CreatureLib::Battling::Battle { class Battle : public CreatureLib::Battling::Battle {
private: private:
std::unique_ptr<CreatureLib::Battling::BattleScript> _weatherScript = nullptr; ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript> _weatherScript = nullptr;
public: public:
Battle(const BattleLibrary* non_null library, Battle(const BattleLibrary* non_null library,
@ -26,20 +26,21 @@ namespace PkmnLib::Battling {
bool SetWeather(const ArbUt::StringView& name); bool SetWeather(const ArbUt::StringView& name);
void ClearWeather(); void ClearWeather();
void SuppressWeather() { void SuppressWeather() {
if (_weatherScript != nullptr) { if (_weatherScript.HasValue()) {
_weatherScript->Suppress(); _weatherScript.GetValue()->Suppress();
} }
} }
void UnsuppressWeather() { void UnsuppressWeather() {
if (_weatherScript != nullptr) { if (_weatherScript.HasValue()) {
_weatherScript->Unsuppress(); _weatherScript.GetValue()->Unsuppress();
} }
} }
const ArbUt::StringView& GetWeatherName() noexcept { const ArbUt::StringView& GetWeatherName() noexcept {
if (_weatherScript == nullptr) if (!_weatherScript.HasValue()) {
return ArbUt::StringView::EmptyString(); return ArbUt::StringView::EmptyString();
return _weatherScript->GetName(); }
return _weatherScript.GetValue()->GetName();
} }
size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; } size_t ScriptCount() const override { return CreatureLib::Battling::Battle::ScriptCount() + 1; }

View File

@ -11,8 +11,8 @@ namespace PkmnLib::Battling {
auto rate = pokemon->GetSpecies()->GetCaptureRate(); auto rate = pokemon->GetSpecies()->GetCaptureRate();
u8 bonusBall = 1; u8 bonusBall = 1;
auto* itemScript = auto* itemScript = dynamic_cast<PkmnItemUseScript*>(
dynamic_cast<PkmnItemUseScript*>(pokemon->GetLibrary()->GetScriptResolver()->LoadItemScript(catchItem)); pokemon->GetLibrary()->GetScriptResolver()->LoadItemScript(catchItem).GetValue());
itemScript->ModifyPokeballCatchBonus(pokemon, &bonusBall); itemScript->ModifyPokeballCatchBonus(pokemon, &bonusBall);
u8 bonusStatus = 1; u8 bonusStatus = 1;

View File

@ -53,13 +53,13 @@ CreatureLib::Battling::Creature* PkmnLib::Battling::Pokemon::Clone() const {
c->_battleData.Side = _battleData.Side; c->_battleData.Side = _battleData.Side;
c->_battleData.OnBattleField = _battleData.OnBattleField; c->_battleData.OnBattleField = _battleData.OnBattleField;
c->_battleData.Index = _battleData.Index; c->_battleData.Index = _battleData.Index;
if (_activeTalent != nullptr) { if (_activeTalent.HasValue()) {
c->_activeTalent = std::unique_ptr<PkmnScript::BattleScript>(_activeTalent->Clone(c)); c->_activeTalent = _activeTalent.GetValue()->Clone(c);
} }
c->_hasOverridenTalent = _hasOverridenTalent; c->_hasOverridenTalent = _hasOverridenTalent;
c->_overridenTalent = _overridenTalent; c->_overridenTalent = _overridenTalent;
if (_status != nullptr) { if (_status.HasValue()) {
c->_status = std::unique_ptr<PkmnScript::BattleScript>(_status->Clone(c)); c->_status = _status.GetValue()->Clone(c);
} }
_volatile.Clone(c, c->_volatile); _volatile.Clone(c, c->_volatile);
c->_types = std::vector<u8>(_types); c->_types = std::vector<u8>(_types);

View File

@ -165,8 +165,8 @@ void AngelScriptResolver::MessageCallback(const asSMessageInfo* msg, void*) {
printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message); printf("%s (%d, %d) : %s : %s\n", msg->section, msg->row, msg->col, type, msg->message);
} }
CreatureLib::Battling::BattleScript* AngelScriptResolver::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript>
ScriptCategory category, AngelScriptResolver::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
const ArbUt::StringView& scriptName) { const ArbUt::StringView& scriptName) {
ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*> innerDb; ArbUt::Dictionary<ArbUt::StringView, AngelScriptTypeInfo*> innerDb;
auto v = _typeDatabase.TryGet(category); auto v = _typeDatabase.TryGet(category);
@ -193,10 +193,11 @@ CreatureLib::Battling::BattleScript* AngelScriptResolver::LoadScript(const ArbUt
return new AngelScriptScript(owner, ownerType, this, t.value(), obj, _contextPool); return new AngelScriptScript(owner, ownerType, this, t.value(), obj, _contextPool);
} }
PkmnLib::Battling::PkmnItemUseScript* AngelScriptResolver::LoadItemScript(const CreatureLib::Library::Item* item) { ArbUt::OptionalUniquePtr<CreatureLib::Battling::ItemUseScript>
AngelScriptResolver::LoadItemScript(const CreatureLib::Library::Item* item) {
auto v = this->_itemUseScripts.TryGet(item); auto v = this->_itemUseScripts.TryGet(item);
if (v.has_value()) { if (v.has_value()) {
return v.value(); return {v.value()};
} }
if (!item->GetEffect().HasValue()) { if (!item->GetEffect().HasValue()) {
return nullptr; return nullptr;

View File

@ -66,10 +66,11 @@ public:
void DefineWord(const std::string& word) { _builder.DefineWord(word.c_str()); } void DefineWord(const std::string& word) { _builder.DefineWord(word.c_str()); }
CreatureLib::Battling::BattleScript* LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript>
ScriptCategory category, LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
const ArbUt::StringView& scriptName) override; const ArbUt::StringView& scriptName) override;
PkmnLib::Battling::PkmnItemUseScript* LoadItemScript(const CreatureLib::Library::Item* item) override; ArbUt::OptionalUniquePtr<CreatureLib::Battling::ItemUseScript>
LoadItemScript(const CreatureLib::Library::Item* item) override;
ArbUt::OptionalBorrowedPtr<const PkmnLib::Battling::EvolutionScript> ArbUt::OptionalBorrowedPtr<const PkmnLib::Battling::EvolutionScript>
LoadEvolutionScript(const ArbUt::StringView& view) override; LoadEvolutionScript(const ArbUt::StringView& view) override;

View File

@ -11,7 +11,7 @@ class WebAssemblyFunctionCall {
public: public:
WebAssemblyFunctionCall(const ArbUt::BorrowedPtr<wasm_func_t>& func) : _func(func) {} WebAssemblyFunctionCall(const ArbUt::BorrowedPtr<wasm_func_t>& func) : _func(func) {}
NO_COPY_OR_MOVE(WebAssemblyFunctionCall) NO_COPY_OR_MOVE(WebAssemblyFunctionCall);
void Call() { void Call() {
wasm_val_vec_t args = {argsCount, _arguments.Data}; wasm_val_vec_t args = {argsCount, _arguments.Data};

View File

@ -132,7 +132,7 @@ void WebAssemblyScriptResolver::Finalize() {
} }
} }
CreatureLib::Battling::BattleScript* ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript>
WebAssemblyScriptResolver::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category, WebAssemblyScriptResolver::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
const ArbUt::StringView& scriptName) { const ArbUt::StringView& scriptName) {
auto loadScriptOpt = GetFunction<2, 1>("load_script"_cnc); auto loadScriptOpt = GetFunction<2, 1>("load_script"_cnc);

View File

@ -44,7 +44,7 @@ public:
[[nodiscard]] inline wasm_memory_t* GetMemory() const noexcept { return _memory; } [[nodiscard]] inline wasm_memory_t* GetMemory() const noexcept { return _memory; }
CreatureLib::Battling::BattleScript* LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript> LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner,
ScriptCategory category, ScriptCategory category,
const ArbUt::StringView& scriptName) nullable override; const ArbUt::StringView& scriptName) nullable override;

View File

@ -112,7 +112,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& scriptName) { static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& scriptName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, scriptName); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, scriptName).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -45,7 +45,7 @@ static AngelScriptItemUseScript* GetScript(PkmnLib::Battling::BattleLibrary* mai
new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {}); new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {});
auto s = lib->LoadItemScript(&item); auto s = lib->LoadItemScript(&item);
auto script = dynamic_cast<AngelScriptItemUseScript*>(s); auto script = dynamic_cast<AngelScriptItemUseScript*>(s.TakeOwnership());
REQUIRE(script != nullptr); REQUIRE(script != nullptr);
return script; return script;
} }

View File

@ -55,7 +55,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& scriptName, static AngelScriptScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& scriptName,
PkmnLib::Battling::Pokemon* owner) { PkmnLib::Battling::Pokemon* owner) {
auto* lib = GetScriptResolver(mainLib); auto* lib = GetScriptResolver(mainLib);
auto* s = lib->LoadScript(owner, ScriptCategory::Creature, scriptName); auto* s = lib->LoadScript(owner, ScriptCategory::Creature, scriptName).TakeOwnership();
auto* script = dynamic_cast<AngelScriptScript*>(s); auto* script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -1,8 +1,8 @@
#if TESTS_BUILD && ANGELSCRIPT #if TESTS_BUILD && ANGELSCRIPT
#include <doctest.h> #include <doctest.h>
#include "../../TestLibrary/TestLibrary.hpp"
#include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp" #include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp"
#include "../../src/ScriptResolving/AngelScript/ContextPool.hpp" #include "../../src/ScriptResolving/AngelScript/ContextPool.hpp"
#include "../../TestLibrary/TestLibrary.hpp"
static std::unordered_map<const char*, const char*> _scripts = static std::unordered_map<const char*, const char*> _scripts =
std::unordered_map<const char*, const char*>{{"testScript1", R"( std::unordered_map<const char*, const char*>{{"testScript1", R"(
@ -44,8 +44,7 @@ TEST_CASE("Build script resolver, then create object") {
lib->CreateScript("testScript1", _scripts["testScript1"]); lib->CreateScript("testScript1", _scripts["testScript1"]);
lib->FinalizeModule(); lib->FinalizeModule();
auto obj = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto obj = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
delete obj; delete obj;
delete lib; delete lib;
} }
@ -56,7 +55,8 @@ TEST_CASE("Build script resolver, create object, invoke addition method") {
lib->CreateScript("testScript1", _scripts["testScript1"]); lib->CreateScript("testScript1", _scripts["testScript1"]);
lib->FinalizeModule(); lib->FinalizeModule();
auto obj = dynamic_cast<AngelScriptScript*>(lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc)); auto obj = dynamic_cast<AngelScriptScript*>(
lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership());
REQUIRE(obj != nullptr); REQUIRE(obj != nullptr);
auto ctxPool = obj->GetContextPool(); auto ctxPool = obj->GetContextPool();
auto ctx = ctxPool->RequestContext(); auto ctx = ctxPool->RequestContext();
@ -86,8 +86,8 @@ TEST_CASE("Get a script resolver, save the byte code to memory, create new scrip
originLib->Initialize(TestLibrary::GetLibrary()); originLib->Initialize(TestLibrary::GetLibrary());
originLib->CreateScript("testScript1", _scripts["testScript1"]); originLib->CreateScript("testScript1", _scripts["testScript1"]);
originLib->FinalizeModule(); originLib->FinalizeModule();
auto obj = auto obj = dynamic_cast<AngelScriptScript*>(
dynamic_cast<AngelScriptScript*>(originLib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc)); originLib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership());
REQUIRE(obj != nullptr); REQUIRE(obj != nullptr);
REQUIRE(obj->GetType()->GetOnInitialize().Exists); REQUIRE(obj->GetType()->GetOnInitialize().Exists);
delete obj; delete obj;
@ -97,7 +97,8 @@ TEST_CASE("Get a script resolver, save the byte code to memory, create new scrip
auto newLib = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver()); auto newLib = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
newLib->Initialize(TestLibrary::GetLibrary()); newLib->Initialize(TestLibrary::GetLibrary());
newLib->LoadByteCodeFromMemory(byteCode, size); newLib->LoadByteCodeFromMemory(byteCode, size);
obj = dynamic_cast<AngelScriptScript*>(newLib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc)); obj = dynamic_cast<AngelScriptScript*>(
newLib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership());
REQUIRE(obj != nullptr); REQUIRE(obj != nullptr);
REQUIRE(obj->GetType()->GetOnInitialize().Exists); REQUIRE(obj->GetType()->GetOnInitialize().Exists);
delete obj; delete obj;
@ -115,8 +116,8 @@ TEST_CASE("Get a script resolver, save the byte code to file, create new script
auto newLib = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver()); auto newLib = dynamic_cast<AngelScriptResolver*>(PkmnLib::Battling::BattleLibrary::CreateScriptResolver());
newLib->Initialize(TestLibrary::GetLibrary()); newLib->Initialize(TestLibrary::GetLibrary());
newLib->LoadByteCodeFromFile("foo.bin"); newLib->LoadByteCodeFromFile("foo.bin");
auto obj = auto obj = dynamic_cast<AngelScriptScript*>(
dynamic_cast<AngelScriptScript*>(newLib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc)); newLib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership());
REQUIRE(obj != nullptr); REQUIRE(obj != nullptr);
delete obj; delete obj;
delete originLib; delete originLib;

View File

@ -44,7 +44,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -57,7 +57,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -45,7 +45,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -41,7 +41,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -45,7 +45,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -43,7 +43,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -44,7 +44,7 @@ static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary*
static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) { static ScriptData GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& funcName) {
auto lib = GetScriptResolver(mainLib); auto lib = GetScriptResolver(mainLib);
auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc); auto s = lib->LoadScript(nullptr, ScriptCategory::Creature, "testScript1"_cnc).TakeOwnership();
auto script = dynamic_cast<AngelScriptScript*>(s); auto script = dynamic_cast<AngelScriptScript*>(s);
REQUIRE(script != nullptr); REQUIRE(script != nullptr);

View File

@ -56,7 +56,7 @@ TEST_CASE("Get a script resolver, load a real wasm script, load test script") {
lib->Finalize(); lib->Finalize();
auto script = lib->LoadScript(nullptr, ScriptCategory::Attack, "test"_cnc); auto script = lib->LoadScript(nullptr, ScriptCategory::Attack, "test"_cnc);
EnsureNotNull(script); EnsureNotNull(script);
script->OnInitialize(TestLibrary::GetLibrary(), {}); script.GetValue()->OnInitialize(TestLibrary::GetLibrary(), {});
delete script; delete script;
} }