1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2004 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
// $Id: EntityProperties.cpp,v 1.13 2007-12-02 23:49:06 alriddoch Exp $
#include "Entity.h"
#include "Container.h"
#include "common/Property_impl.h"
#include "common/type_utils.h"
#include "physics/BBox.h"
#include <wfmath/atlasconv.h>
using Atlas::Message::Element;
using Atlas::Message::MapType;
using Atlas::Message::ListType;
using Atlas::Objects::Entity::RootEntity;
template<>
bool ImmutableProperty<BBox>::get(Element & e) const
{
e = m_data.toAtlas();
return true;
}
template<>
void Property<BBox>::set(const Element & e)
{
if (e.isList() && (e.asList().size() > 2)) {
m_modData.fromAtlas(e.asList());
}
}
template<>
void ImmutableProperty<BBox>::add(const std::string & s, MapType & ent) const
{
if (m_data.isValid()) {
ent[s] = m_data.toAtlas();
}
}
template<>
void ImmutableProperty<BBox>::add(const std::string & s, const RootEntity & ent) const
{
if (m_data.isValid()) {
ent->setAttr(s, m_data.toAtlas());
}
}
template<>
bool ImmutableProperty<IdList>::get(Element & e) const
{
e = Atlas::Message::ListType();
idListasObject(m_data, e.asList());
return true;
}
template<>
void Property<IdList>::set(const Element & e)
{
if (e.isList()) {
idListFromAtlas(e.asList(), m_modData);
}
}
template<>
void ImmutableProperty<IdList>::add(const std::string & s, MapType & ent) const
{
if (!m_data.empty()) {
get(ent[s]);
}
}
template<>
void ImmutableProperty<IdList>::add(const std::string & s, const RootEntity & ent) const
{
if (!m_data.empty()) {
ListType list;
idListasObject(m_data, list);
ent->setAttr(s, list);
}
}
template<>
bool ImmutableProperty<LocatedEntitySet>::get(Element & e) const
{
e = ListType();
ListType & contlist = e.asList();
LocatedEntitySet::const_iterator Iend = m_data.end();
for (LocatedEntitySet::const_iterator I = m_data.begin(); I != Iend; ++I) {
contlist.push_back((*I)->getId());
}
return true;
}
template<>
void ImmutableProperty<LocatedEntitySet>::add(const std::string & s,
MapType & ent) const
{
if (!m_data.empty()) {
get(ent[s]);
}
}
template<>
void ImmutableProperty<LocatedEntitySet>::add(const std::string & s,
const RootEntity & ent) const
{
if (!m_data.empty()) {
Element v;
get(v);
ent->setAttr(s, v);
}
}
template<>
bool ImmutableProperty<Container>::get(Element & e) const
{
// FIXME Not sure if this is best. Why did we bother to virtualise
// addToMessage() if we have to do this here?
e = ListType();
ListType & contlist = e.asList();
Container::const_iterator Iend = m_data.end();
for (Container::const_iterator I = m_data.begin(); I != Iend; ++I) {
contlist.push_back((*I)->getId());
}
return true;
}
template<>
void ImmutableProperty<Container>::add(const std::string & s,
MapType & ent) const
{
if (!m_data.empty()) {
m_data.addToMessage(s, ent);
}
}
template<>
void ImmutableProperty<Container>::add(const std::string & s,
const RootEntity & ent) const
{
if (!m_data.empty()) {
m_data.addToEntity(s, ent);
}
}
template<>
void SignalProperty<BBox>::set(const Element & e)
{
if (e.isList() && (e.asList().size() > 2)) {
m_modData.fromAtlas(e.asList());
modified.emit();
}
}
template class Property<BBox>;
template class Property<IdList>;
template class ImmutableProperty<LocatedEntitySet>;
template class ImmutableProperty<Container>;
template class SignalProperty<BBox>;
|