2013-01-08 23:33:19 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2013 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "PropertyRuleHandler.h"
|
|
|
|
|
|
|
|
|
|
#include "EntityBuilder.h"
|
|
|
|
|
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/debug.h"
|
|
|
|
|
#include "common/compose.hpp"
|
2013-02-18 23:29:24 +00:00
|
|
|
#include "common/PropertyManager.h"
|
|
|
|
|
#include "common/PropertyFactory.h"
|
2013-01-08 23:33:19 +00:00
|
|
|
|
|
|
|
|
using Atlas::Message::Element;
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Message::ListType;
|
|
|
|
|
using Atlas::Objects::Root;
|
|
|
|
|
|
|
|
|
|
using String::compose;
|
|
|
|
|
|
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
|
|
|
|
|
|
int PropertyRuleHandler::check(const Atlas::Objects::Root & desc)
|
|
|
|
|
{
|
2017-07-24 13:39:22 +02:00
|
|
|
assert(!desc->getParent().empty());
|
2013-01-08 23:33:19 +00:00
|
|
|
if (desc->getObjtype() != "type") {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PropertyRuleHandler::install(const std::string & name,
|
2013-02-18 23:29:24 +00:00
|
|
|
const std::string & parent,
|
|
|
|
|
const Atlas::Objects::Root & desc,
|
|
|
|
|
std::string & dependent,
|
2018-05-08 14:32:02 +02:00
|
|
|
std::string & reason,
|
|
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate>& changes)
|
2013-01-08 23:33:19 +00:00
|
|
|
{
|
2013-02-18 23:29:24 +00:00
|
|
|
assert(desc->getObjtype() == "type");
|
2018-04-25 20:09:14 +02:00
|
|
|
PropertyManager& pm = PropertyManager::instance();
|
|
|
|
|
if (pm.getPropertyFactory(name) != nullptr) {
|
2013-02-20 16:30:48 +00:00
|
|
|
log(ERROR, compose("Property rule \"%1\" already exists.", name));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2018-04-25 20:09:14 +02:00
|
|
|
PropertyKit * parent_factory = pm.getPropertyFactory(parent);
|
|
|
|
|
if (parent_factory == nullptr) {
|
2013-02-18 23:29:24 +00:00
|
|
|
dependent = parent;
|
|
|
|
|
reason = compose("Property rule \"%1\" has parent \"%2\" which does "
|
|
|
|
|
"not exist.", name, parent);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
auto * factory = parent_factory->duplicateFactory();
|
2018-04-25 20:09:14 +02:00
|
|
|
assert(factory != nullptr);
|
2018-10-30 19:31:27 +01:00
|
|
|
pm.installFactory(name, desc, std::unique_ptr<PropertyKit>(factory));
|
2013-01-08 23:33:19 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PropertyRuleHandler::update(const std::string & name,
|
2018-05-08 14:32:02 +02:00
|
|
|
const Atlas::Objects::Root & desc,
|
|
|
|
|
std::map<const TypeNode*, TypeNode::PropertiesUpdate>& changes)
|
2013-01-08 23:33:19 +00:00
|
|
|
{
|
2013-02-18 23:29:24 +00:00
|
|
|
// There is not anything to be modified yet.
|
2013-01-08 23:33:19 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|