From 73f48eab7a8c224b03d1c16f3a234961a0d30b63 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 14 Aug 2020 17:24:12 +0200 Subject: [PATCH] C Interface for History. Signed-off-by: Deukhoofd --- CInterface/Battling/Battle.cpp | 3 ++- CInterface/Battling/HistoryHandler.cpp | 20 +++++++++++++++++++ .../HistoryElements/AttackUseHistory.hpp | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 CInterface/Battling/HistoryHandler.cpp diff --git a/CInterface/Battling/Battle.cpp b/CInterface/Battling/Battle.cpp index 3b16707..460504a 100644 --- a/CInterface/Battling/Battle.cpp +++ b/CInterface/Battling/Battle.cpp @@ -77,4 +77,5 @@ export bool CreatureLib_Battle_HasVolatileScript(Battle* p, const char* key) { export uint8_t CreatureLib_Battle_RegisterEventListener(Battle* p, void (*func)(const EventData*)) { Try(p->RegisterEventListener(func);) -} \ No newline at end of file +} +export const HistoryHolder* CreatureLib_Battle_GetHistory(Battle* p) { return &p->GetHistory(); } \ No newline at end of file diff --git a/CInterface/Battling/HistoryHandler.cpp b/CInterface/Battling/HistoryHandler.cpp new file mode 100644 index 0000000..4826157 --- /dev/null +++ b/CInterface/Battling/HistoryHandler.cpp @@ -0,0 +1,20 @@ +#include "../../src/Battling/History/HistoryElements/AttackUseHistory.hpp" +#include "../../src/Battling/History/HistoryHolder.hpp" +#include "../Core.hpp" +using namespace CreatureLib::Battling; + +export const HistoryElement* CreatureLib_HistoryHandler_GetTopElement(const HistoryHolder* p) { + return p->GetTopElement().GetRaw(); +} +export const HistoryElement* CreatureLib_HistoryHandler_GetLastUsedAttack(const HistoryHolder* p) { + return p->GetLastUsedAttack().GetRaw(); +} + +export HistoryElementKind CreatureLib_HistoryElement_GetKind(const HistoryElement* p) { return p->GetKind(); } +export const HistoryElement* CreatureLib_HistoryElement_GetPrevious(const HistoryElement* p) { + return p->GetPrevious().GetRaw(); +} + +export const ExecutingAttack* CreatureLib_AttackUseHistory_GetAttack(const AttackUseHistory* p) { + return p->GetAttack().GetRaw(); +} \ No newline at end of file diff --git a/src/Battling/History/HistoryElements/AttackUseHistory.hpp b/src/Battling/History/HistoryElements/AttackUseHistory.hpp index 00ae204..31f7121 100644 --- a/src/Battling/History/HistoryElements/AttackUseHistory.hpp +++ b/src/Battling/History/HistoryElements/AttackUseHistory.hpp @@ -17,7 +17,7 @@ namespace CreatureLib::Battling { AttackUseHistory(const ExecutingAttack* attack) : _attack(attack) {} HistoryElementKind GetKind() const noexcept override { return HistoryElementKind::AttackUse; } - ArbUt::BorrowedPtr GetAttack() { return _attack; } + ArbUt::BorrowedPtr GetAttack() const noexcept { return _attack; } }; }