Tweaks for Battle and ScriptSet, added Battle C interface.
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:
@@ -8,7 +8,7 @@
|
||||
namespace CreatureLib::Battling {
|
||||
class ScriptSet {
|
||||
std::vector<Script*> _scripts;
|
||||
std::unordered_map<ConstString, size_t> _lookup;
|
||||
std::unordered_map<uint32_t, size_t> _lookup;
|
||||
|
||||
public:
|
||||
~ScriptSet() {
|
||||
@@ -28,22 +28,26 @@ namespace CreatureLib::Battling {
|
||||
_lookup.insert({script->GetName(), _scripts.size() - 1});
|
||||
}
|
||||
|
||||
Script* Get(const ConstString& key) const {
|
||||
auto f = _lookup.find(key);
|
||||
Script* Get(const ConstString& key) const { return Get(key.GetHash()); }
|
||||
|
||||
Script* Get(uint32_t keyHash) const {
|
||||
auto f = _lookup.find(keyHash);
|
||||
if (f != _lookup.end()) {
|
||||
return _scripts[f->second];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Remove(const ConstString& key) {
|
||||
auto find = _lookup.find(key);
|
||||
void Remove(const ConstString& key) { Remove(key.GetHash()); }
|
||||
|
||||
void Remove(uint32_t keyHash) {
|
||||
auto find = _lookup.find(keyHash);
|
||||
if (find != _lookup.end()) {
|
||||
auto script = _scripts[find->second];
|
||||
script->OnRemove();
|
||||
delete script;
|
||||
_scripts.erase(_scripts.begin() + find.operator*().second);
|
||||
_lookup.erase(key);
|
||||
_lookup.erase(keyHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +59,9 @@ namespace CreatureLib::Battling {
|
||||
_lookup.clear();
|
||||
}
|
||||
|
||||
bool Has(const ConstString& key) const {
|
||||
auto find = _lookup.find(key);
|
||||
return find != _lookup.end();
|
||||
}
|
||||
bool Has(const ConstString& key) const { return _lookup.find(key) != _lookup.end(); }
|
||||
|
||||
bool Has(uint32_t keyHash) const { return _lookup.find(keyHash) != _lookup.end(); }
|
||||
|
||||
size_t Count() const { return _scripts.size(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user