2019-11-08 17:45:43 +00:00
|
|
|
#ifndef CREATURELIB_SCRIPTSET_HPP
|
|
|
|
#define CREATURELIB_SCRIPTSET_HPP
|
|
|
|
|
|
|
|
#include <any>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "Script.hpp"
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
namespace CreatureLib::Battling {
|
|
|
|
class ScriptSet {
|
2019-11-12 17:38:09 +00:00
|
|
|
std::vector<Script*> _scripts;
|
|
|
|
std::unordered_map<std::string, size_t> _lookup;
|
2019-11-28 11:55:22 +00:00
|
|
|
|
2019-11-08 17:45:43 +00:00
|
|
|
public:
|
2019-11-28 11:55:22 +00:00
|
|
|
void Add(Script* script) {
|
2019-11-12 17:38:09 +00:00
|
|
|
auto f = _lookup.find(script->GetName());
|
2019-11-28 11:55:22 +00:00
|
|
|
if (f != _lookup.end()) {
|
2019-11-12 17:38:09 +00:00
|
|
|
_scripts[f.operator*().second]->Stack();
|
|
|
|
return;
|
2019-11-08 17:45:43 +00:00
|
|
|
}
|
2019-11-12 17:38:09 +00:00
|
|
|
_scripts.push_back(script);
|
|
|
|
_lookup.insert({script->GetName(), _scripts.size() - 1});
|
2019-11-08 17:45:43 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
void Remove(const std::string& key) {
|
2019-11-12 17:38:09 +00:00
|
|
|
auto find = _lookup.find(key);
|
2019-11-28 11:55:22 +00:00
|
|
|
if (find != _lookup.end()) {
|
2019-11-12 17:38:09 +00:00
|
|
|
_scripts.erase(_scripts.begin() + find.operator*().second);
|
|
|
|
_lookup.erase(key);
|
|
|
|
}
|
2019-11-08 17:45:43 +00:00
|
|
|
}
|
2019-11-09 11:15:45 +00:00
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
size_t Count() const { return _scripts.size(); }
|
2019-11-09 11:15:45 +00:00
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
const std::vector<Script*>* GetIterator() const { return &_scripts; }
|
2019-11-08 17:45:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
#endif // CREATURELIB_SCRIPTSET_HPP
|