Ejemplo n.º 1
0
QScriptValue toScriptValueComponentMap(QScriptEngine *engine, const Entity::ComponentMap &components)
{
    // Expose the set of components as a JavaScript _associative_ array. (array[component1Id] = component11, etc.)
    QScriptValue obj = engine->newObject();
    Entity::ComponentMap::const_iterator iter = components.begin();
    while(iter != components.end())
    {
        if ((*iter).second)
            obj.setProperty((*iter).first, engine->newQObject((*iter).second.get()));
        ++iter;
    }
    return obj;
}
Ejemplo n.º 2
0
void ECBrowser::RemoveEntity(EntityPtr entity)
{
    if (!entity)
        return;

    for(EntityWeakPtrList::iterator iter = entities_.begin(); iter != entities_.end(); ++iter)
        if (iter->lock() == entity)
        {
            EntityPtr ent_ptr = iter->lock();

            disconnect(entity.get(), SIGNAL(ComponentAdded(IComponent*, AttributeChange::Type)), this,
                SLOT(OnComponentAdded(IComponent*, AttributeChange::Type)));
            disconnect(entity.get(), SIGNAL(ComponentRemoved(IComponent*, AttributeChange::Type)), this,
                SLOT(OnComponentRemoved(IComponent*, AttributeChange::Type)));

            const Entity::ComponentMap components = ent_ptr->Components();
            for (Entity::ComponentMap::const_iterator i = components.begin(); i != components.end(); ++i)
                RemoveComponentFromGroup(i->second);

            entities_.erase(iter);
            break;
        }
Ejemplo n.º 3
0
void ECBrowser::RemoveEntity(const EntityPtr &entity)
{
    if (!entity)
        return;

    EntityMap::iterator iter = entities_.find(entity->Id());
    if (iter != entities_.end())
    {
        Entity *entity = iter->second.lock().get();
        if (entity)
        {
            disconnect(entity, SIGNAL(ComponentAdded(IComponent*, AttributeChange::Type)), this,
                SLOT(OnComponentAdded(IComponent*, AttributeChange::Type)));
            disconnect(entity, SIGNAL(ComponentRemoved(IComponent*, AttributeChange::Type)), this,
                SLOT(OnComponentRemoved(IComponent*, AttributeChange::Type)));

            const Entity::ComponentMap components = entity->Components();
            for (Entity::ComponentMap::const_iterator i = components.begin(); i != components.end(); ++i)
                RemoveComponentFromGroup(i->second);
        }

        entities_.erase(iter);
    }
Ejemplo n.º 4
0
void fromScriptValueComponentMap(const QScriptValue &obj, Entity::ComponentMap &components)
{
    components.clear();
    QScriptValueIterator it(obj);
    while(it.hasNext())
    {
        it.next();
        QObject *o = it.value().toQObject();
        if (o)
        {
            IComponent *c = qobject_cast<IComponent  *>(o);
            if (c)
                components[c->TypeId()] = c->shared_from_this();
        }
    }
}