Adds support for scripts for item use handling.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2021-03-07 10:54:42 +01:00
parent 5178d5dcc0
commit d908efff9d
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#include "../../src/Battling/ScriptHandling/ItemUseScript.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Battling;
export void CreatureLib_ItemUseScript_Destruct(ItemUseScript* p) { delete p; }
export uint8_t CreatureLib_ItemUseScript_IsItemUsable(ItemUseScript* p, uint8_t& out) { Try(out = p->IsItemUsable()) }
export uint8_t CreatureLib_ItemUseScript_IsCreatureUseItem(ItemUseScript* p, uint8_t& out) {
Try(out = p->IsCreatureUseItem())
}
export uint8_t CreatureLib_ItemUseScript_IsUseValidForCreature(ItemUseScript* p, Creature* creature, uint8_t& out) {
Try(out = p->IsUseValidForCreature(creature))
}
export uint8_t CreatureLib_ItemUseScript_IsHoldable(ItemUseScript* p, uint8_t& out) { Try(out = p->IsHoldable()) }
export uint8_t CreatureLib_ItemUseScript_OnUse(ItemUseScript* p) { Try(p->OnUse()) }
export uint8_t CreatureLib_ItemUseScript_OnCreatureUse(ItemUseScript* p, Creature* creature) {
Try(p->OnCreatureUse(creature))
}

View File

@ -13,3 +13,8 @@ export uint8_t CreatureLib_ScriptResolver_LoadScript(BattleScript*& out, ScriptR
const char* scriptName) { const char* scriptName) {
Try(out = p->LoadScript(category, ArbUt::StringView(scriptName));) Try(out = p->LoadScript(category, ArbUt::StringView(scriptName));)
}; };
export uint8_t CreatureLib_ScriptResolver_LoadItemScript(ItemUseScript*& out, ScriptResolver* p,
const char* scriptName) {
Try(out = p->LoadItemScript(ArbUt::StringView(scriptName));)
};

View File

@ -0,0 +1,26 @@
#ifndef ITEMUSESCRIPT_HPP
#define ITEMUSESCRIPT_HPP
namespace CreatureLib::Battling {
class Creature;
class ItemUseScript {
public:
virtual ~ItemUseScript() = default;
/// @brief Is the item an item we are able to use?
[[nodiscard]] virtual bool IsItemUsable() const { return false; }
/// @brief Do we need to use the item on a creature?
[[nodiscard]] virtual bool IsCreatureUseItem() const { return false; }
/// @brief Can the item be used on the given creature.
[[nodiscard]] virtual bool IsUseValidForCreature([[maybe_unused]] Creature* creature) const { return false; }
/// @brief Can the item be held?
[[nodiscard]] virtual bool IsHoldable() const { return false; }
virtual void OnUse() const {}
virtual void OnCreatureUse([[maybe_unused]] Creature* creature) const {}
};
}
#endif // ITEMUSESCRIPT_HPP

View File

@ -2,6 +2,7 @@
#define CREATURELIB_SCRIPTRESOLVER_HPP #define CREATURELIB_SCRIPTRESOLVER_HPP
#include "BattleScript.hpp" #include "BattleScript.hpp"
#include "ItemUseScript.hpp"
#include "ScriptCategory.hpp" #include "ScriptCategory.hpp"
namespace CreatureLib::Battling { namespace CreatureLib::Battling {
@ -9,6 +10,9 @@ namespace CreatureLib::Battling {
class ScriptResolver { class ScriptResolver {
public: public:
ScriptResolver() {}
NO_COPY_OR_MOVE(ScriptResolver)
virtual ~ScriptResolver() = default; virtual ~ScriptResolver() = default;
virtual void Initialize([[maybe_unused]] BattleLibrary* library){}; virtual void Initialize([[maybe_unused]] BattleLibrary* library){};
@ -16,6 +20,8 @@ namespace CreatureLib::Battling {
[[maybe_unused]] const ArbUt::StringView& scriptName) { [[maybe_unused]] const ArbUt::StringView& scriptName) {
return nullptr; return nullptr;
}; };
virtual ItemUseScript* LoadItemScript([[maybe_unused]] const ArbUt::StringView& scriptName) { return nullptr; };
}; };
} }