38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#ifndef CREATURELIB_SCRIPTWRAPPER_HPP
|
|
#define CREATURELIB_SCRIPTWRAPPER_HPP
|
|
|
|
#include "Script.hpp"
|
|
#include "ScriptSet.hpp"
|
|
|
|
namespace CreatureLib::Battling {
|
|
class ScriptWrapper {
|
|
bool _isSet;
|
|
|
|
union {
|
|
std::unique_ptr<Script> const* _script;
|
|
const ScriptSet* _scriptSet;
|
|
};
|
|
|
|
ScriptWrapper(std::unique_ptr<Script>* s, bool isSet) : _isSet(isSet), _script(s){};
|
|
ScriptWrapper(ScriptSet* s, bool isSet) : _isSet(isSet), _scriptSet(s){};
|
|
|
|
public:
|
|
static inline ScriptWrapper FromScript(std::unique_ptr<Script>* s) { return ScriptWrapper(s, false); }
|
|
static inline ScriptWrapper FromSet(ScriptSet* s) { return ScriptWrapper(s, true); }
|
|
|
|
inline bool IsSet() const noexcept { return _isSet; }
|
|
|
|
inline const std::unique_ptr<Script>* GetScript() const noexcept { return _script; }
|
|
inline const ScriptSet* GetScriptSet() const noexcept { return _scriptSet; }
|
|
|
|
inline bool HasValue() const noexcept {
|
|
if (_isSet)
|
|
return _scriptSet->Count() > 0;
|
|
else
|
|
return *_script != nullptr;
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // CREATURELIB_SCRIPTWRAPPER_HPP
|