Adds Pokemon class registry for WASM
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
bc975aba53
commit
66fb9f5bd6
|
@ -62,7 +62,7 @@ CreatureLib::Battling::Creature* PkmnLib::Battling::Pokemon::Clone() const {
|
||||||
c->_status = _status.GetValue()->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 = ArbUt::List<u8>(_types);
|
||||||
c->_friendship = _friendship;
|
c->_friendship = _friendship;
|
||||||
c->RecalculateFlatStats();
|
c->RecalculateFlatStats();
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ static const ArbUt::StringView& GetActiveAbilityWrapper(PkmnLib::Battling::Pokem
|
||||||
return p->GetActiveTalent()->GetName();
|
return p->GetActiveTalent()->GetName();
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t GetTypesLengthWrapper(PkmnLib::Battling::Pokemon* p) { return p->GetTypes().size(); }
|
static size_t GetTypesLengthWrapper(PkmnLib::Battling::Pokemon* p) { return p->GetTypes().Count(); }
|
||||||
static uint8_t GetTypeWrapper(PkmnLib::Battling::Pokemon* p, size_t index) { return p->GetTypes()[index]; }
|
static uint8_t GetTypeWrapper(PkmnLib::Battling::Pokemon* p, size_t index) { return p->GetTypes()[index]; }
|
||||||
|
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
|
|
@ -0,0 +1,232 @@
|
||||||
|
#include "WASMPokemonRegistry.hpp"
|
||||||
|
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
||||||
|
#include "../WASMHelperFile.hpp"
|
||||||
|
#include "wasm.h"
|
||||||
|
using namespace CreatureLib::Battling;
|
||||||
|
using namespace PkmnLib::Battling;
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_ChangeForme(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, const CreatureLib::Library::SpeciesVariant*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, const CreatureLib::Library::SpeciesVariant* forme) {
|
||||||
|
pokemon->ChangeVariant(forme);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_HasHeldItemByHash(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<bool, Pokemon*, u32>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, u32 itemHash) -> bool {
|
||||||
|
return pokemon->HasHeldItem(itemHash);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_SetHeldItemByHash(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, u32>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, u32 itemHash) {
|
||||||
|
return pokemon->SetHeldItemByHash(itemHash);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_ConsumeHeldItem(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<bool, Pokemon*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon) -> bool { return pokemon->ConsumeHeldItem(); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_GetNickname(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<u32, Pokemon*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver* res, Pokemon* pokemon) -> u32 {
|
||||||
|
const auto& nickname_opt = pokemon->GetNickname();
|
||||||
|
if (!nickname_opt.has_value()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Allocate a string in wasm memory, and copy the nickname to it.
|
||||||
|
const auto& nickname = nickname_opt.value();
|
||||||
|
auto ptrs = res->AllocateMemory(sizeof(char) * nickname.length(), alignof(char));
|
||||||
|
strncpy((char*)ptrs.first, nickname.data(), nickname.length());
|
||||||
|
ptrs.first[nickname.length()] = 0;
|
||||||
|
return ptrs.second;
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_GetRealAbility(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<const ArbUt::BorrowedPtr<const CreatureLib::Library::Talent>&, Pokemon*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*,
|
||||||
|
Pokemon* pokemon) -> const ArbUt::BorrowedPtr<const CreatureLib::Library::Talent>& {
|
||||||
|
return pokemon->GetForme()->GetAbility(pokemon->GetRealTalent());
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_HasType(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<bool, Pokemon*, u8>(
|
||||||
|
resolver,
|
||||||
|
{[](WebAssemblyScriptResolver*, Pokemon* pokemon, u8 typeId) -> bool { return pokemon->HasType(typeId); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_SetType(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, u8, u8>(
|
||||||
|
resolver,
|
||||||
|
{[](WebAssemblyScriptResolver*, Pokemon* pokemon, u8 index, u8 typeId) { pokemon->SetType(index, typeId); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_Damage(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, u32, DamageSource>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, u32 damage, DamageSource source) {
|
||||||
|
pokemon->Damage(damage, source);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_Heal(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, u32, bool>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, u32 amount, bool canRevive) {
|
||||||
|
pokemon->Heal(amount, canRevive);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_RestoreAllPP(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon) { pokemon->RestoreAllAttackUses(); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_OverrideActiveAbility(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, const char*, size_t>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, const char* abilityName, size_t abilityNameLength) {
|
||||||
|
auto sv = ArbUt::StringView(abilityName, abilityNameLength);
|
||||||
|
pokemon->OverrideActiveTalent(sv);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_AddVolatileScript(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<BattleScript*, Pokemon*, const char*, size_t>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, const char* scriptName, size_t scriptNameLength) {
|
||||||
|
auto sv = ArbUt::StringView(scriptName, scriptNameLength);
|
||||||
|
return pokemon->AddVolatileScript(sv);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_RemoveVolatileScriptByHash(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, u32>(
|
||||||
|
resolver,
|
||||||
|
{[](WebAssemblyScriptResolver*, Pokemon* pokemon, u32 hash) { pokemon->RemoveVolatileScriptByHash(hash); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_HasMoveByHash(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<bool, Pokemon*, u32>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, u32 hash) -> bool {
|
||||||
|
return pokemon->HasAttackByHash(hash);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_SetStatus(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, const char*, size_t>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, const char* statusName, size_t statusNameLength) {
|
||||||
|
auto sv = ArbUt::StringView(statusName, statusNameLength);
|
||||||
|
pokemon->SetStatus(sv);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_ClearStatus(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon) { pokemon->ClearStatus(); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_SetDisplaySpecies(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, CreatureLib::Library::CreatureSpecies*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, CreatureLib::Library::CreatureSpecies* species) {
|
||||||
|
pokemon->SetDisplaySpecies(species);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_SetDisplayForme(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, CreatureLib::Library::SpeciesVariant*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, CreatureLib::Library::SpeciesVariant* variant) {
|
||||||
|
pokemon->SetDisplayVariant(variant);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* Pokemon_ChangeStatBoost(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void, Pokemon*, CreatureLib::Library::Statistic, i8, bool>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, Pokemon* pokemon, CreatureLib::Library::Statistic stat, i8 diffAmount,
|
||||||
|
bool selfInflicted) { pokemon->ChangeStatBoost(stat, diffAmount, selfInflicted); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
void WASMPokemonRegistry::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||||
|
WebAssemblyScriptResolver* resolver) {
|
||||||
|
REGISTER_GETTER("pokemon_get_library", Creature, GetLibrary, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_species", Creature, GetSpecies, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_display_species", Creature, GetDisplaySpecies, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_forme", Creature, GetVariant, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_display_forme", Creature, GetDisplayVariant, resolver)
|
||||||
|
externs.Insert("pokemon_set_display_species", Pokemon_SetDisplaySpecies(resolver));
|
||||||
|
externs.Insert("pokemon_set_display_forme", Pokemon_SetDisplayForme(resolver));
|
||||||
|
REGISTER_GETTER("pokemon_get_level", Creature, GetLevel, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_experience", Creature, GetExperience, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_unique_identifier", Creature, GetUniqueIdentifier, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_gender", Creature, GetGender, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_coloring", Creature, GetColoring, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_held_item", Creature, GetHeldItem, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_current_health", Creature, GetCurrentHealth, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_weight", Creature, GetWeight, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_height", Creature, GetHeight, resolver)
|
||||||
|
externs.Insert("pokemon_get_nickname", Pokemon_GetNickname(resolver));
|
||||||
|
externs.Insert("pokemon_get_real_ability", Pokemon_GetRealAbility(resolver));
|
||||||
|
REGISTER_GETTER("pokemon_get_active_ability", Creature, GetActiveTalent, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_is_useable", Creature, IsUsable, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_is_fainted", Creature, IsFainted, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_types", Creature, GetTypes, resolver)
|
||||||
|
externs.Insert("pokemon_has_type", Pokemon_HasType(resolver));
|
||||||
|
externs.Insert("pokemon_set_type", Pokemon_SetType(resolver));
|
||||||
|
REGISTER_GETTER("pokemon_get_max_health", Creature, GetMaxHealth, resolver)
|
||||||
|
externs.Insert("pokemon_damage", Pokemon_Damage(resolver));
|
||||||
|
externs.Insert("pokemon_heal", Pokemon_Heal(resolver));
|
||||||
|
externs.Insert("pokemon_restore_all_pp", Pokemon_RestoreAllPP(resolver));
|
||||||
|
externs.Insert("pokemon_override_active_ability", Pokemon_OverrideActiveAbility(resolver));
|
||||||
|
externs.Insert("pokemon_add_volatile_script", Pokemon_AddVolatileScript(resolver));
|
||||||
|
externs.Insert("pokemon_remove_volatile_script_by_hash", Pokemon_RemoveVolatileScriptByHash(resolver));
|
||||||
|
externs.Insert("pokemon_has_move_by_hash", Pokemon_HasMoveByHash(resolver));
|
||||||
|
REGISTER_GETTER("pokemon_get_moves", Creature, GetAttacks, resolver)
|
||||||
|
externs.Insert("pokemon_set_status", Pokemon_SetStatus(resolver));
|
||||||
|
externs.Insert("pokemon_clear_status", Pokemon_ClearStatus(resolver));
|
||||||
|
REGISTER_GETTER("pokemon_get_status_name", Creature, GetStatusName, resolver)
|
||||||
|
|
||||||
|
externs.Insert("pokemon_change_forme", Pokemon_ChangeForme(resolver));
|
||||||
|
externs.Insert("pokemon_has_held_item_by_hash", Pokemon_HasHeldItemByHash(resolver));
|
||||||
|
externs.Insert("pokemon_set_held_item_by_hash", Pokemon_SetHeldItemByHash(resolver));
|
||||||
|
externs.Insert("pokemon_consume_held_item", Pokemon_ConsumeHeldItem(resolver));
|
||||||
|
externs.Insert("pokemon_change_stat_boost", Pokemon_ChangeStatBoost(resolver));
|
||||||
|
|
||||||
|
REGISTER_GETTER("pokemon_get_flat_health", Creature, GetFlatStat<CreatureLib::Library::Statistic::Health>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_flat_attack", Creature, GetFlatStat<CreatureLib::Library::Statistic::PhysicalAttack>,
|
||||||
|
resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_flat_defense", Creature, GetFlatStat<CreatureLib::Library::Statistic::PhysicalDefense>,
|
||||||
|
resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_flat_special_attack", Creature,
|
||||||
|
GetFlatStat<CreatureLib::Library::Statistic::MagicalAttack>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_flat_special_defense", Creature,
|
||||||
|
GetFlatStat<CreatureLib::Library::Statistic::MagicalDefense>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_flat_speed", Creature, GetFlatStat<CreatureLib::Library::Statistic::Speed>, resolver)
|
||||||
|
|
||||||
|
REGISTER_GETTER("pokemon_get_boosted_health", Creature, GetBoostedStat<CreatureLib::Library::Statistic::Health>,
|
||||||
|
resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_boosted_attack", Creature,
|
||||||
|
GetBoostedStat<CreatureLib::Library::Statistic::PhysicalAttack>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_boosted_defense", Creature,
|
||||||
|
GetBoostedStat<CreatureLib::Library::Statistic::PhysicalDefense>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_boosted_special_attack", Creature,
|
||||||
|
GetBoostedStat<CreatureLib::Library::Statistic::MagicalAttack>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_boosted_special_defense", Creature,
|
||||||
|
GetBoostedStat<CreatureLib::Library::Statistic::MagicalDefense>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_boosted_speed", Creature, GetBoostedStat<CreatureLib::Library::Statistic::Speed>,
|
||||||
|
resolver)
|
||||||
|
|
||||||
|
REGISTER_GETTER("pokemon_get_stat_boost_health", Creature, GetStatBoost<CreatureLib::Library::Statistic::Health>,
|
||||||
|
resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_stat_boost_attack", Creature,
|
||||||
|
GetStatBoost<CreatureLib::Library::Statistic::PhysicalAttack>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_stat_boost_defense", Creature,
|
||||||
|
GetStatBoost<CreatureLib::Library::Statistic::PhysicalDefense>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_stat_boost_special_attack", Creature,
|
||||||
|
GetStatBoost<CreatureLib::Library::Statistic::MagicalAttack>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_stat_boost_special_defense", Creature,
|
||||||
|
GetStatBoost<CreatureLib::Library::Statistic::MagicalDefense>, resolver)
|
||||||
|
REGISTER_GETTER("pokemon_get_stat_boost_speed", Creature, GetStatBoost<CreatureLib::Library::Statistic::Speed>,
|
||||||
|
resolver)
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef PKMNLIB_WASMPOKEMONREGISTRY_HPP
|
||||||
|
#define PKMNLIB_WASMPOKEMONREGISTRY_HPP
|
||||||
|
#include "../../WebAssemblyScriptResolver.hpp"
|
||||||
|
|
||||||
|
class WASMPokemonRegistry {
|
||||||
|
public:
|
||||||
|
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs, WebAssemblyScriptResolver* resolver);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PKMNLIB_WASMPOKEMONREGISTRY_HPP
|
|
@ -4,6 +4,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../WebAssemblyScriptResolver.hpp"
|
#include "../WebAssemblyScriptResolver.hpp"
|
||||||
#include "Arbutils/Collections/Dictionary.hpp"
|
#include "Arbutils/Collections/Dictionary.hpp"
|
||||||
|
#include "Battling/WASMPokemonRegistry.hpp"
|
||||||
#include "Library/LibraryMethods.hpp"
|
#include "Library/LibraryMethods.hpp"
|
||||||
#include "Library/WASMAbilityRegistry.hpp"
|
#include "Library/WASMAbilityRegistry.hpp"
|
||||||
#include "Library/WASMEffectParameter.hpp"
|
#include "Library/WASMEffectParameter.hpp"
|
||||||
|
@ -29,6 +30,8 @@ public:
|
||||||
WASMSpeciesRegistry::Register(externs, resolver);
|
WASMSpeciesRegistry::Register(externs, resolver);
|
||||||
WASMFormeRegistry::Register(externs, resolver);
|
WASMFormeRegistry::Register(externs, resolver);
|
||||||
WASMAbilityRegistry::Register(externs, resolver);
|
WASMAbilityRegistry::Register(externs, resolver);
|
||||||
|
|
||||||
|
WASMPokemonRegistry::Register(externs, resolver);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef PKMNLIB_HELPERFILE_H
|
#ifndef PKMNLIB_HELPERFILE_H
|
||||||
#define PKMNLIB_HELPERFILE_H
|
#define PKMNLIB_HELPERFILE_H
|
||||||
#include <Arbutils/Memory/Memory.hpp>
|
#include <Arbutils/Memory/Memory.hpp>
|
||||||
#include <cxxabi.h>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -125,17 +124,27 @@ private:
|
||||||
return wasm_valtype_new_i64();
|
return wasm_valtype_new_i64();
|
||||||
} else if constexpr (is_specialization<T, ArbUt::List>()) {
|
} else if constexpr (is_specialization<T, ArbUt::List>()) {
|
||||||
return wasm_valtype_new_i64();
|
return wasm_valtype_new_i64();
|
||||||
|
} else if constexpr (is_specialization<T, ArbUt::OptionalUniquePtrList>()) {
|
||||||
|
return wasm_valtype_new_i64();
|
||||||
|
} else {
|
||||||
|
static_assert(always_false<T>::value, "Unhandled value type");
|
||||||
}
|
}
|
||||||
THROW("Unhandled value type: ", std::string(abi::__cxa_demangle(typeid(T).name(), 0, 0, 0)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T> struct always_false {
|
||||||
|
enum { value = false };
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T> inline static wasm_val_t ToVal(const T& val) {
|
template <typename T> inline static wasm_val_t ToVal(const T& val) {
|
||||||
if constexpr (std::is_pointer<T>()) {
|
if constexpr (std::is_pointer<T>()) {
|
||||||
return WASM_I64_VAL(reinterpret_cast<i64>(val));
|
return WASM_I64_VAL(reinterpret_cast<i64>(val));
|
||||||
} else if constexpr (is_specialization<T, ArbUt::BorrowedPtr>::value) {
|
} else if constexpr (is_specialization<T, ArbUt::BorrowedPtr>::value) {
|
||||||
return WASM_I64_VAL(reinterpret_cast<i64>(val.GetRaw()));
|
return WASM_I64_VAL(reinterpret_cast<i64>(val.GetRaw()));
|
||||||
} else if constexpr (is_specialization<T, ArbUt::OptionalBorrowedPtr>::value) {
|
} else if constexpr (is_specialization<T, ArbUt::OptionalBorrowedPtr>::value) {
|
||||||
return WASM_I64_VAL(reinterpret_cast<i64>(val.GetRaw()));
|
if (val.HasValue()) {
|
||||||
|
return WASM_I64_VAL(reinterpret_cast<i64>(val.GetValue()));
|
||||||
|
}
|
||||||
|
return WASM_I64_VAL(0);
|
||||||
} else if constexpr (is_specialization<T, std::unique_ptr>::value) {
|
} else if constexpr (is_specialization<T, std::unique_ptr>::value) {
|
||||||
return WASM_I64_VAL(reinterpret_cast<i64>(val.get()));
|
return WASM_I64_VAL(reinterpret_cast<i64>(val.get()));
|
||||||
} else if constexpr (std::is_enum<T>() || std::is_integral<T>()) {
|
} else if constexpr (std::is_enum<T>() || std::is_integral<T>()) {
|
||||||
|
@ -156,8 +165,12 @@ private:
|
||||||
} else if constexpr (is_specialization<T, ArbUt::List>()) {
|
} else if constexpr (is_specialization<T, ArbUt::List>()) {
|
||||||
auto v = &val;
|
auto v = &val;
|
||||||
return WASM_I64_VAL(reinterpret_cast<i64>(v));
|
return WASM_I64_VAL(reinterpret_cast<i64>(v));
|
||||||
|
} else if constexpr (is_specialization<T, ArbUt::OptionalUniquePtrList>()) {
|
||||||
|
auto v = &val;
|
||||||
|
return WASM_I64_VAL(reinterpret_cast<i64>(v));
|
||||||
|
} else {
|
||||||
|
static_assert(always_false<T>::value, "Unhandled value type");
|
||||||
}
|
}
|
||||||
THROW("Unhandled value type: ", typeid(T).name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline static T FromVal(const wasm_val_t& val) {
|
template <typename T> inline static T FromVal(const wasm_val_t& val) {
|
||||||
|
@ -181,8 +194,9 @@ private:
|
||||||
} else {
|
} else {
|
||||||
return static_cast<T>(val.of.f32);
|
return static_cast<T>(val.of.f32);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
static_assert(always_false<T>::value, "Unhandled value type");
|
||||||
}
|
}
|
||||||
THROW("Unhandled value type: ", typeid(T).name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t I, class... Args> inline static void AppendArgument(wasm_valtype_t* array[]) {
|
template <size_t I, class... Args> inline static void AppendArgument(wasm_valtype_t* array[]) {
|
||||||
|
|
|
@ -1,20 +1,48 @@
|
||||||
#include "WASMListRegistry.hpp"
|
#include "WASMListRegistry.hpp"
|
||||||
#include "WASMHelperFile.hpp"
|
#include "WASMHelperFile.hpp"
|
||||||
|
|
||||||
wasm_func_t* List_GetLength(WebAssemblyScriptResolver* resolver) {
|
wasm_func_t* PtrList_GetLength(WebAssemblyScriptResolver* resolver) {
|
||||||
return WasmHelpers::CreateFunc<size_t, const ArbUt::List<void*>*>(
|
return WasmHelpers::CreateFunc<size_t, const ArbUt::List<void*>*>(
|
||||||
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::List<void*>* list) -> size_t { return list->Count(); }});
|
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::List<void*>* list) -> size_t { return list->Count(); }});
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_func_t* List_GetValue(WebAssemblyScriptResolver* resolver) {
|
wasm_func_t* PtrList_GetValue(WebAssemblyScriptResolver* resolver) {
|
||||||
return WasmHelpers::CreateFunc<void*, const ArbUt::List<void*>*, size_t>(
|
return WasmHelpers::CreateFunc<void*, const ArbUt::List<void*>*, size_t>(
|
||||||
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::List<void*>* list, size_t index) -> void* {
|
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::List<void*>* list, size_t index) -> void* {
|
||||||
return list->At(index);
|
return list->At(index);
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wasm_func_t* ByteList_GetLength(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<size_t, const ArbUt::List<u8>*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::List<u8>* list) -> size_t { return list->Count(); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* ByteList_GetValue(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<u8, const ArbUt::List<u8>*, size_t>(
|
||||||
|
resolver,
|
||||||
|
{[](WebAssemblyScriptResolver*, const ArbUt::List<u8>* list, size_t index) -> u8 { return list->At(index); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* OptionalUniquePtrList_GetLength(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<size_t, const ArbUt::OptionalUniquePtrList<void>*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::OptionalUniquePtrList<void>* list) -> size_t {
|
||||||
|
return list->Count();
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* OptionalUniquePtrList_GetValue(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void*, const ArbUt::OptionalUniquePtrList<void>*, size_t>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::OptionalUniquePtrList<void>* list,
|
||||||
|
size_t index) -> void* { return list->At(index); }});
|
||||||
|
}
|
||||||
|
|
||||||
void WASMListRegistry::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
void WASMListRegistry::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||||
WebAssemblyScriptResolver* resolver) {
|
WebAssemblyScriptResolver* resolver) {
|
||||||
externs.Insert("list_get_length", List_GetLength(resolver));
|
externs.Insert("pointer_list_get_length", PtrList_GetLength(resolver));
|
||||||
externs.Insert("list_get_at", List_GetValue(resolver));
|
externs.Insert("pointer_list_get_at", PtrList_GetValue(resolver));
|
||||||
|
externs.Insert("byte_list_get_length", ByteList_GetLength(resolver));
|
||||||
|
externs.Insert("byte_list_get_at", ByteList_GetValue(resolver));
|
||||||
|
externs.Insert("optional_unique_ptr_list_get_length", OptionalUniquePtrList_GetLength(resolver));
|
||||||
|
externs.Insert("optional_unique_ptr_get_at", OptionalUniquePtrList_GetValue(resolver));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,10 @@ const_string_get_str: function(const_string ptr) -> s32
|
||||||
|
|
||||||
// List class
|
// List class
|
||||||
type list = u64
|
type list = u64
|
||||||
list_get_length: function(list) -> u64
|
pointer_list_get_length: function(list) -> u64
|
||||||
list_get_at: function(list, u64) -> u64
|
pointer_list_get_at: function(list, u64) -> u64
|
||||||
|
byte_list_get_length: function(list) -> u8
|
||||||
|
byte_list_get_at: function(list, u64) -> u8
|
||||||
|
|
||||||
// Library types
|
// Library types
|
||||||
type pokemon_library = u64
|
type pokemon_library = u64
|
||||||
|
@ -35,6 +37,7 @@ type nature_library = u64
|
||||||
|
|
||||||
type level_int = u8
|
type level_int = u8
|
||||||
|
|
||||||
|
type effect_parameter = u64
|
||||||
type species = u64
|
type species = u64
|
||||||
type move = u64
|
type move = u64
|
||||||
type item = u64
|
type item = u64
|
||||||
|
@ -43,14 +46,19 @@ type forme = u64
|
||||||
type ability = u64
|
type ability = u64
|
||||||
|
|
||||||
enum Statistic {
|
enum Statistic {
|
||||||
Health,
|
Health, Attack, Defense, SpecialAttack, SpecialDefense, Speed,
|
||||||
Attack,
|
|
||||||
Defense
|
|
||||||
SpecialAttack,
|
|
||||||
SpecialDefense,
|
|
||||||
Speed,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EffectParameter class
|
||||||
|
enum EffectParameterType {
|
||||||
|
None, Bool, Int, Float, String
|
||||||
|
}
|
||||||
|
effect_parameter_get_type: function(effect_parameter) -> EffectParameterType
|
||||||
|
effect_parameter_as_bool: function(effect_parameter) -> bool
|
||||||
|
effect_parameter_as_int: function(effect_parameter) -> s64
|
||||||
|
effect_parameter_as_float: function(effect_parameter) -> f32
|
||||||
|
effect_parameter_as_string: function(effect_parameter) -> const_string
|
||||||
|
|
||||||
// PokemonLibrary class
|
// PokemonLibrary class
|
||||||
data_library_get_settings: function(pokemon_library ptr) -> library_settings
|
data_library_get_settings: function(pokemon_library ptr) -> library_settings
|
||||||
data_library_get_species_library: function(pokemon_library ptr) -> species_library
|
data_library_get_species_library: function(pokemon_library ptr) -> species_library
|
||||||
|
@ -156,3 +164,6 @@ forme_get_ability: function(forme, bool hidden, u8 index) -> ability
|
||||||
forme_has_flag_by_hash: function(forme, u32) -> bool
|
forme_has_flag_by_hash: function(forme, u32) -> bool
|
||||||
|
|
||||||
// Ability class
|
// Ability class
|
||||||
|
ability_get_name: function(ability) -> const_string
|
||||||
|
ability_get_effect: function(ability) -> const_string
|
||||||
|
ability_get_parameters: function(ability) -> list
|
Loading…
Reference in New Issue