Move Script ownership to script holder, added OnRemove script hook.
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:
@@ -11,6 +11,12 @@ namespace CreatureLib::Battling {
|
||||
std::unordered_map<std::string, size_t> _lookup;
|
||||
|
||||
public:
|
||||
~ScriptSet() {
|
||||
for (auto s : _scripts) {
|
||||
delete s;
|
||||
}
|
||||
}
|
||||
|
||||
void Add(Script* script) {
|
||||
auto f = _lookup.find(script->GetName());
|
||||
if (f != _lookup.end()) {
|
||||
@@ -24,12 +30,18 @@ namespace CreatureLib::Battling {
|
||||
void Remove(const std::string& key) {
|
||||
auto find = _lookup.find(key);
|
||||
if (find != _lookup.end()) {
|
||||
auto script = _scripts[find->second];
|
||||
script->OnRemove();
|
||||
delete script;
|
||||
_scripts.erase(_scripts.begin() + find.operator*().second);
|
||||
_lookup.erase(key);
|
||||
}
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (auto s : _scripts) {
|
||||
delete s;
|
||||
}
|
||||
_scripts.clear();
|
||||
_lookup.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user