/* * Copyright (C) 2013 Alec Thomas * All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. * * Author: Alec Thomas */ #pragma once #include "entityx/System.h" #include "entityx/Event.h" #include "entityx/Entity.h" namespace entityx { namespace deps { /** * An entityx::System for declaring component dependencies. * * eg. To declare that a `Physics` component must always be paired with `Position` * and `Direction` components: * * system_manager->add>(); */ template class Dependency : public System>, public Receiver> { public: void receive(const ComponentAddedEvent &event) { assign(event.entity); } void configure(EventManager &events) override { events.subscribe>(*this); } void update(EntityManager &entities, EventManager &events, TimeDelta dt) override {} private: template void assign(Entity entity) { if (!entity.component()) entity.assign(); } template void assign(Entity entity) { assign(entity); assign(entity); } }; } // namespace deps } // namespace entityx