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