mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
Restructure rule classes.
Classes under "rulesets" have been moved to "rules", and split up into futher subdirectories matching their library. As a result we can now better separate the python bindings, so that things that belongs to the simulation are separeted from things that belongs to the ai.
This commit is contained in:
parent
800d6f3d2c
commit
e85f0831b2
463 changed files with 1794 additions and 1515 deletions
73
rules/python/ScriptsProperty.cpp
Normal file
73
rules/python/ScriptsProperty.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
//
|
||||
// Created by erik on 2018-07-02.
|
||||
//
|
||||
|
||||
#include "ScriptsProperty.h"
|
||||
#include "rules/python/PythonScriptFactory.h"
|
||||
#include "rules/LocatedEntity.h"
|
||||
#include "rules/Script.h"
|
||||
#include "common/log.h"
|
||||
#include "common/compose.hpp"
|
||||
|
||||
using Atlas::Message::Element;
|
||||
using Atlas::Message::MapType;
|
||||
using Atlas::Message::ListType;
|
||||
|
||||
using String::compose;
|
||||
|
||||
std::map<std::pair<std::string, std::string>, std::shared_ptr<ScriptKit<LocatedEntity>>> ScriptsProperty::sScriptFactories;
|
||||
|
||||
void ScriptsProperty::set(const Atlas::Message::Element &element) {
|
||||
Property::set(element);
|
||||
|
||||
m_scripts.clear();
|
||||
for (auto &entry : m_data) {
|
||||
if (entry.isMap()) {
|
||||
std::string script_package;
|
||||
std::string script_class;
|
||||
if (Script::getScriptDetails(entry.Map(), "<none>", "Entity",
|
||||
script_package, script_class) == 0) {
|
||||
auto key = std::make_pair(script_package, script_class);
|
||||
auto I = sScriptFactories.find(key);
|
||||
if (I != sScriptFactories.end()) {
|
||||
m_scripts.push_back(I->second);
|
||||
} else {
|
||||
auto psf = std::make_shared<PythonScriptFactory<LocatedEntity>>(script_package, script_class);
|
||||
if (psf->setup() == 0) {
|
||||
sScriptFactories.emplace(key, psf);
|
||||
m_scripts.push_back(std::move(psf));
|
||||
} else {
|
||||
log(ERROR, String::compose("Python class \"%1.%2\" failed to load",
|
||||
script_package, script_class));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptsProperty::apply(LocatedEntity *entity) {
|
||||
|
||||
applyScripts(entity);
|
||||
}
|
||||
|
||||
void ScriptsProperty::applyScripts(LocatedEntity *entity) const {
|
||||
|
||||
for (auto script : entity->m_scripts) {
|
||||
delete script;
|
||||
}
|
||||
entity->m_scripts.clear();
|
||||
for (auto &scriptFactory : m_scripts) {
|
||||
scriptFactory->addScript(entity);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptsProperty::reloadAllScriptFactories() {
|
||||
for (auto& entry : sScriptFactories) {
|
||||
entry.second->refreshClass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue