From 634ffce5f8531a71ded0aab8b25a30ac6887813a Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 17 May 2022 20:28:20 +0200 Subject: [PATCH] Adds Item registry to WASM. --- .../Library/WASMItemRegistry.cpp | 22 +++++++++++++++++++ .../Library/WASMItemRegistry.hpp | 13 +++++++++++ .../Library/WASMMoveDataRegistry.cpp | 1 - .../WASM/InterfaceMethods/TypeRegistry.hpp | 2 ++ .../WASM/InterfaceMethods/pkmn_lib.wit | 14 +++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.cpp create mode 100644 src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.hpp diff --git a/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.cpp b/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.cpp new file mode 100644 index 0000000..68c1aea --- /dev/null +++ b/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.cpp @@ -0,0 +1,22 @@ +#include "WASMItemRegistry.hpp" +#include "../../../../Battling/Library/BattleLibrary.hpp" +#include "../../WebAssemblyScriptResolver.hpp" +#include "../WASMHelperFile.hpp" +#include "wasm.h" + +using namespace CreatureLib::Library; + +wasm_func_t* Item_HasFlagByHash(WebAssemblyScriptResolver* resolver) { + return WasmHelpers::CreateFunc( + resolver, {[](WebAssemblyScriptResolver*, Item* item, u32 flag) -> bool { return item->HasFlag(flag); }}); +} + +void WASMItemRegistry::Register(ArbUt::Dictionary& externs, + WebAssemblyScriptResolver* resolver) { + REGISTER_GETTER("item_get_name", Item, GetName, resolver) + REGISTER_GETTER("item_get_category", Item, GetCategory, resolver) + REGISTER_GETTER("item_get_battle_category", Item, GetBattleCategory, resolver) + REGISTER_GETTER("item_get_price", Item, GetPrice, resolver) + REGISTER_GETTER("item_get_fling_power", PkmnLib::Library::Item, GetFlingPower, resolver) + externs.Insert("item_has_flag_by_hash", Item_HasFlagByHash(resolver)); +} diff --git a/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.hpp b/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.hpp new file mode 100644 index 0000000..293d451 --- /dev/null +++ b/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMItemRegistry.hpp @@ -0,0 +1,13 @@ +#ifndef PKMNLIB_WASMITEMREGISTRY_H +#define PKMNLIB_WASMITEMREGISTRY_H +#include +#include + +class WebAssemblyScriptResolver; +class WASMItemRegistry { +public: + static void Register(ArbUt::Dictionary& externs, + WebAssemblyScriptResolver* resolver); +}; + +#endif // PKMNLIB_WASMITEMREGISTRY_H diff --git a/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMMoveDataRegistry.cpp b/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMMoveDataRegistry.cpp index b3cf725..deab09a 100644 --- a/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMMoveDataRegistry.cpp +++ b/src/ScriptResolving/WASM/InterfaceMethods/Library/WASMMoveDataRegistry.cpp @@ -1,5 +1,4 @@ #include "WASMMoveDataRegistry.hpp" -#include #include "../../../../Battling/Library/BattleLibrary.hpp" #include "../../WebAssemblyScriptResolver.hpp" #include "../WASMHelperFile.hpp" diff --git a/src/ScriptResolving/WASM/InterfaceMethods/TypeRegistry.hpp b/src/ScriptResolving/WASM/InterfaceMethods/TypeRegistry.hpp index bb9833f..a2a551b 100644 --- a/src/ScriptResolving/WASM/InterfaceMethods/TypeRegistry.hpp +++ b/src/ScriptResolving/WASM/InterfaceMethods/TypeRegistry.hpp @@ -6,6 +6,7 @@ #include "Arbutils/Collections/Dictionary.hpp" #include "Library/LibraryMethods.hpp" #include "Library/WASMMoveDataRegistry.hpp" +#include "Library/WASMItemRegistry.hpp" #include "WASMCoreMethods.hpp" #include "WASMStringView.hpp" @@ -16,6 +17,7 @@ public: WASMStringView::Register(externs, resolver); LibraryMethods::Register(externs, resolver); WASMMoveDataRegistry::Register(externs, resolver); + WASMItemRegistry::Register(externs, resolver); } }; diff --git a/src/ScriptResolving/WASM/InterfaceMethods/pkmn_lib.wit b/src/ScriptResolving/WASM/InterfaceMethods/pkmn_lib.wit index cc5eaf7..80d3ffd 100644 --- a/src/ScriptResolving/WASM/InterfaceMethods/pkmn_lib.wit +++ b/src/ScriptResolving/WASM/InterfaceMethods/pkmn_lib.wit @@ -108,4 +108,16 @@ move_data_get_priority: function(move) -> s8 move_data_has_secondary_effect: function(move) -> bool move_data_has_flag_by_hash: function(move, u32 hash) -> bool - +// Item class +enum ItemCategory { + Misc, Pokeball, Medicine, Berry, MoveLearner, FormeChanger, KeyItem, Mail +} +enum ItemBattleCategory { + None, Healing, StatusHealing, Pokeball, MiscBattleItem +} +item_get_name: function(item) -> const_string +item_get_category: function(item) -> ItemCategory +item_get_battle_category: function(item) -> ItemBattleCategory +item_get_price: function(item) -> s32 +item_get_fling_power: function(item) -> u8 +item_has_flag_by_hash: function(item, u32 hash) -> bool \ No newline at end of file