Used ClangFormat style guide I'm happy with.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -6,43 +6,42 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
namespace CreatureLib::Battling {
|
||||
class BaseTurnChoice;
|
||||
class AttackTurnChoice;
|
||||
class ExecutingAttack;
|
||||
class Creature;
|
||||
|
||||
class Script{
|
||||
class Script {
|
||||
const std::string _name;
|
||||
|
||||
public:
|
||||
explicit Script(std::string name) :_name(std::move(name)){}
|
||||
explicit Script(std::string name) : _name(std::move(name)) {}
|
||||
virtual ~Script() = default;
|
||||
|
||||
virtual void Stack(){};
|
||||
|
||||
const std::string& GetName(){
|
||||
return _name;
|
||||
}
|
||||
const std::string& GetName() { return _name; }
|
||||
|
||||
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
|
||||
|
||||
virtual void ChangeAttack(AttackTurnChoice* choice, std::string& attack){};
|
||||
virtual void PreventAttack(ExecutingAttack* attack,bool& result){};
|
||||
virtual void PreventAttack(ExecutingAttack* attack, bool& result){};
|
||||
virtual void FailAttack(ExecutingAttack* attack, bool& failed){};
|
||||
virtual void StopBeforeAttack(ExecutingAttack* attack){};
|
||||
virtual void OnBeforeAttack(ExecutingAttack* attack){};
|
||||
|
||||
virtual void FailIncomingAttack(ExecutingAttack* attack, Creature* target, bool& result){};
|
||||
virtual void IsInvulnerable(ExecutingAttack* attack, Creature* target , bool& result){};
|
||||
virtual void IsInvulnerable(ExecutingAttack* attack, Creature* target, bool& result){};
|
||||
virtual void OnAttackMiss(ExecutingAttack* attack, Creature* target){};
|
||||
virtual void ChangeAttackType(ExecutingAttack* attack, Creature* target, uint8_t hitNumber, uint8_t& type){};
|
||||
virtual void OnStatusMove(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber){};
|
||||
virtual void PreventSecondaryEffects(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber, bool& result){};
|
||||
virtual void PreventSecondaryEffects(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber,
|
||||
bool& result){};
|
||||
virtual void OnSecondaryEffect(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber){};
|
||||
|
||||
virtual void OnAfterHits(const ExecutingAttack* attack, Creature* target){};
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SCRIPT_HPP
|
||||
#endif // CREATURELIB_SCRIPT_HPP
|
||||
|
||||
@@ -3,36 +3,34 @@
|
||||
|
||||
#include <any>
|
||||
#include <queue>
|
||||
#include "../../Core/Exceptions/NotReachableException.hpp"
|
||||
#include "Script.hpp"
|
||||
#include "ScriptSet.hpp"
|
||||
#include "../../Core/Exceptions/NotReachableException.hpp"
|
||||
#include "ScriptWrapper.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class ScriptAggregator{
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptAggregator {
|
||||
std::vector<ScriptWrapper> _scripts;
|
||||
int _index = 0;
|
||||
bool _isSetSet = false;
|
||||
const std::vector<Script*>* _setScripts;
|
||||
int _setIndex;
|
||||
|
||||
public:
|
||||
ScriptAggregator(std::vector<ScriptWrapper> scripts) : _scripts(std::move(scripts)){
|
||||
};
|
||||
ScriptAggregator(std::vector<ScriptWrapper> scripts) : _scripts(std::move(scripts)){};
|
||||
|
||||
bool HasNext(){
|
||||
return _index < _scripts.size() || (_isSetSet && _setIndex < _setScripts->size());
|
||||
}
|
||||
bool HasNext() { return _index < _scripts.size() || (_isSetSet && _setIndex < _setScripts->size()); }
|
||||
|
||||
Script* GetNext(){
|
||||
Script* GetNext() {
|
||||
// We can probably do this in a cleaner version once C++ 20 drops with Coroutine support.
|
||||
if (_isSetSet){
|
||||
if (_setIndex >= _setScripts->size()){
|
||||
if (_isSetSet) {
|
||||
if (_setIndex >= _setScripts->size()) {
|
||||
_isSetSet = false;
|
||||
return GetNext();
|
||||
}
|
||||
auto s = _setScripts->at(_setIndex);
|
||||
_setIndex++;
|
||||
if (_setIndex >= _setScripts->size()){
|
||||
if (_setIndex >= _setScripts->size()) {
|
||||
_isSetSet = false;
|
||||
}
|
||||
return s;
|
||||
@@ -41,13 +39,12 @@ namespace CreatureLib::Battling{
|
||||
return nullptr;
|
||||
auto next = _scripts[_index];
|
||||
_index++;
|
||||
if (!next.IsSet()){
|
||||
if (!next.IsSet()) {
|
||||
auto scriptPtr = next.GetScript();
|
||||
if (scriptPtr == nullptr)
|
||||
return GetNext();
|
||||
return *scriptPtr;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
auto set = next.GetScriptSet();
|
||||
if (set->Count() == 0)
|
||||
return GetNext();
|
||||
@@ -61,4 +58,4 @@ namespace CreatureLib::Battling{
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SCRIPTAGGREGATOR_HPP
|
||||
#endif // CREATURELIB_SCRIPTAGGREGATOR_HPP
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#define HOOK(hookName, source, ... ) \
|
||||
{ \
|
||||
auto aggregator = source -> GetScriptIterator(); \
|
||||
while (aggregator.HasNext()){ \
|
||||
auto next = aggregator.GetNext(); \
|
||||
if (next == nullptr) continue; \
|
||||
next->hookName(__VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define HOOK(hookName, source, ...) \
|
||||
{ \
|
||||
auto aggregator = source->GetScriptIterator(); \
|
||||
while (aggregator.HasNext()) { \
|
||||
auto next = aggregator.GetNext(); \
|
||||
if (next == nullptr) \
|
||||
continue; \
|
||||
next->hookName(__VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
|
||||
|
||||
#include "ScriptResolver.hpp"
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
#include <string>
|
||||
#include "Script.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptResolver {
|
||||
public:
|
||||
virtual ~ScriptResolver() = default;
|
||||
|
||||
enum class ScriptCategory{
|
||||
enum class ScriptCategory {
|
||||
Attack,
|
||||
Talent,
|
||||
Status,
|
||||
@@ -19,11 +19,8 @@ namespace CreatureLib::Battling{
|
||||
|
||||
};
|
||||
|
||||
virtual Script* LoadScript(ScriptCategory category, const std::string& scriptName){
|
||||
return nullptr;
|
||||
};
|
||||
virtual Script* LoadScript(ScriptCategory category, const std::string& scriptName) { return nullptr; };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_SCRIPTRESOLVER_HPP
|
||||
#endif // CREATURELIB_SCRIPTRESOLVER_HPP
|
||||
|
||||
@@ -5,14 +5,15 @@
|
||||
#include <unordered_map>
|
||||
#include "Script.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
class ScriptSet{
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSet {
|
||||
std::vector<Script*> _scripts;
|
||||
std::unordered_map<std::string, size_t> _lookup;
|
||||
|
||||
public:
|
||||
void Add(Script* script){
|
||||
void Add(Script* script) {
|
||||
auto f = _lookup.find(script->GetName());
|
||||
if (f != _lookup.end()){
|
||||
if (f != _lookup.end()) {
|
||||
_scripts[f.operator*().second]->Stack();
|
||||
return;
|
||||
}
|
||||
@@ -20,22 +21,18 @@ namespace CreatureLib::Battling{
|
||||
_lookup.insert({script->GetName(), _scripts.size() - 1});
|
||||
}
|
||||
|
||||
void Remove(const std::string& key){
|
||||
void Remove(const std::string& key) {
|
||||
auto find = _lookup.find(key);
|
||||
if (find != _lookup.end()){
|
||||
if (find != _lookup.end()) {
|
||||
_scripts.erase(_scripts.begin() + find.operator*().second);
|
||||
_lookup.erase(key);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Count() const{
|
||||
return _scripts.size();
|
||||
}
|
||||
size_t Count() const { return _scripts.size(); }
|
||||
|
||||
const std::vector<Script *> * GetIterator() const{
|
||||
return &_scripts;
|
||||
}
|
||||
const std::vector<Script*>* GetIterator() const { return &_scripts; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SCRIPTSET_HPP
|
||||
#endif // CREATURELIB_SCRIPTSET_HPP
|
||||
|
||||
@@ -5,15 +5,17 @@
|
||||
|
||||
#include "ScriptAggregator.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSource {
|
||||
bool _areScriptsInitialized = false;
|
||||
std::vector<ScriptWrapper> _scripts;
|
||||
|
||||
protected:
|
||||
virtual void GetActiveScripts(std::vector<ScriptWrapper>& scripts) = 0;
|
||||
|
||||
public:
|
||||
ScriptAggregator GetScriptIterator(){
|
||||
if (!_areScriptsInitialized){
|
||||
ScriptAggregator GetScriptIterator() {
|
||||
if (!_areScriptsInitialized) {
|
||||
GetActiveScripts(_scripts);
|
||||
_areScriptsInitialized = true;
|
||||
}
|
||||
@@ -22,4 +24,4 @@ namespace CreatureLib::Battling{
|
||||
};
|
||||
}
|
||||
|
||||
#endif //CREATURELIB_SCRIPTSOURCE_HPP
|
||||
#endif // CREATURELIB_SCRIPTSOURCE_HPP
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
|
||||
|
||||
#include "ScriptWrapper.hpp"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
#ifndef CREATURELIB_SCRIPTWRAPPER_HPP
|
||||
#define CREATURELIB_SCRIPTWRAPPER_HPP
|
||||
|
||||
@@ -7,27 +5,21 @@
|
||||
#include "Script.hpp"
|
||||
#include "ScriptSet.hpp"
|
||||
|
||||
namespace CreatureLib::Battling{
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptWrapper {
|
||||
std::variant<Script**, ScriptSet*> _value;
|
||||
bool _isSet;
|
||||
|
||||
public:
|
||||
ScriptWrapper(Script** s) : _value(s), _isSet(false){}
|
||||
ScriptWrapper(ScriptSet* s) : _value(s), _isSet(true){}
|
||||
ScriptWrapper(Script** s) : _value(s), _isSet(false) {}
|
||||
ScriptWrapper(ScriptSet* s) : _value(s), _isSet(true) {}
|
||||
|
||||
bool IsSet() const{
|
||||
return _isSet;
|
||||
}
|
||||
bool IsSet() const { return _isSet; }
|
||||
|
||||
Script** GetScript() const{
|
||||
return std::get<Script**>(_value);
|
||||
}
|
||||
Script** GetScript() const { return std::get<Script**>(_value); }
|
||||
|
||||
ScriptSet* GetScriptSet() const{
|
||||
return std::get<ScriptSet*>(_value);
|
||||
}
|
||||
ScriptSet* GetScriptSet() const { return std::get<ScriptSet*>(_value); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //CREATURELIB_SCRIPTWRAPPER_HPP
|
||||
#endif // CREATURELIB_SCRIPTWRAPPER_HPP
|
||||
|
||||
Reference in New Issue
Block a user