Search in sources :

Example 1 with EventSystem

use of org.terasology.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class StateHeadlessSetup method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    CoreRegistry.setContext(context);
    // let's get the entity event system running
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    eventSystem = context.get(EventSystem.class);
    context.put(Console.class, new ConsoleImpl(context));
    NUIManager nuiManager = new NUIManagerInternal(context.get(CanvasRenderer.class), context);
    context.put(NUIManager.class, nuiManager);
    componentSystemManager = new ComponentSystemManager(context);
    context.put(ComponentSystemManager.class, componentSystemManager);
    componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
    componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
    componentSystemManager.register(context.get(InputSystem.class), "engine:InputSystem");
    EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
    LocalPlayer localPlayer = new LocalPlayer();
    context.put(LocalPlayer.class, localPlayer);
    localPlayer.setClientEntity(localPlayerEntity);
    componentSystemManager.initialise();
    GameManifest gameManifest = null;
    List<GameInfo> savedGames = GameProvider.getSavedGames();
    if (savedGames.size() > 0) {
        gameManifest = savedGames.get(0).getManifest();
    } else {
        gameManifest = createGameManifest();
    }
    gameEngine.changeState(new StateLoading(gameManifest, NetworkMode.LISTEN_SERVER));
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) GameInfo(org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo) StateLoading(org.terasology.engine.modes.StateLoading) ConsoleImpl(org.terasology.logic.console.ConsoleImpl) CanvasRenderer(org.terasology.rendering.nui.internal.CanvasRenderer) LocalPlayer(org.terasology.logic.players.LocalPlayer) InputSystem(org.terasology.input.InputSystem) CoreCommands(org.terasology.logic.console.commands.CoreCommands) ClientComponent(org.terasology.network.ClientComponent) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) ConsoleSystem(org.terasology.logic.console.ConsoleSystem) GameManifest(org.terasology.game.GameManifest) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) NUIManager(org.terasology.rendering.nui.NUIManager) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 2 with EventSystem

use of org.terasology.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityPool method destroy.

/**
 * Destroys this entity, sending event
 *
 * @param entityId the id of the entity to destroy
 */
@Override
public void destroy(long entityId) {
    // Don't allow the destruction of unloaded entities.
    if (!entityManager.idLoaded(entityId)) {
        return;
    }
    EntityRef ref = getEntity(entityId);
    EventSystem eventSystem = entityManager.getEventSystem();
    if (eventSystem != null) {
        eventSystem.send(ref, BeforeDeactivateComponent.newInstance());
        eventSystem.send(ref, BeforeRemoveComponent.newInstance());
    }
    entityManager.notifyComponentRemovalAndEntityDestruction(entityId, ref);
    destroy(ref);
}
Also used : EventSystem(org.terasology.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 3 with EventSystem

use of org.terasology.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class EntitySystemSetupUtil method addEntityManagementRelatedClasses.

/**
 * Objects for the following classes must be available in the context:
 * <ul>
 * <li>{@link ModuleEnvironment}</li>
 * <li>{@link NetworkSystem}</li>
 * <li>{@link ReflectFactory}</li>
 * <li>{@link CopyStrategyLibrary}</li>
 * <li>{@link org.terasology.persistence.typeHandling.TypeSerializationLibrary}</li>
 * </ul>
 * <p>
 * The method will make objects for the following classes available in the context:
 * <ul>
 * <li>{@link EngineEntityManager}</li>
 * <li>{@link ComponentLibrary}</li>
 * <li>{@link EventLibrary}</li>
 * <li>{@link PrefabManager}</li>
 * <li>{@link EventSystem}</li>
 * </ul>
 */
public static void addEntityManagementRelatedClasses(Context context) {
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    // Entity Manager
    PojoEntityManager entityManager = new PojoEntityManager();
    context.put(EntityManager.class, entityManager);
    context.put(EngineEntityManager.class, entityManager);
    // Standard serialization library
    TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
    typeSerializationLibrary.add(EntityRef.class, new EntityRefTypeHandler(entityManager));
    entityManager.setTypeSerializerLibrary(typeSerializationLibrary);
    // Prefab Manager
    PrefabManager prefabManager = new PojoPrefabManager(context);
    entityManager.setPrefabManager(prefabManager);
    context.put(PrefabManager.class, prefabManager);
    EntitySystemLibrary library = context.get(EntitySystemLibrary.class);
    entityManager.setComponentLibrary(library.getComponentLibrary());
    // Event System
    EventSystem eventSystem = new EventSystemImpl(library.getEventLibrary(), networkSystem);
    entityManager.setEventSystem(eventSystem);
    context.put(EventSystem.class, eventSystem);
    // TODO: Review - NodeClassLibrary related to the UI for behaviours. Should not be here and probably not even in the CoreRegistry
    context.put(OneOfProviderFactory.class, new OneOfProviderFactory());
    registerComponents(library.getComponentLibrary(), environment);
    registerEvents(entityManager.getEventSystem(), environment);
}
Also used : OneOfProviderFactory(org.terasology.rendering.nui.properties.OneOfProviderFactory) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) ModuleEnvironment(org.terasology.module.ModuleEnvironment) EntitySystemLibrary(org.terasology.entitySystem.metadata.EntitySystemLibrary) PojoEntityManager(org.terasology.entitySystem.entity.internal.PojoEntityManager) PojoPrefabManager(org.terasology.entitySystem.prefab.internal.PojoPrefabManager) PrefabManager(org.terasology.entitySystem.prefab.PrefabManager) NetworkSystem(org.terasology.network.NetworkSystem) EntityRefTypeHandler(org.terasology.persistence.typeHandling.extensionTypes.EntityRefTypeHandler) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) ModuleManager(org.terasology.engine.module.ModuleManager) EventSystemImpl(org.terasology.entitySystem.event.internal.EventSystemImpl)

Example 4 with EventSystem

use of org.terasology.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testChangeComponentEventSentWhenAddOverExisting.

@Test
public void testChangeComponentEventSentWhenAddOverExisting() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    StringComponent comp2 = entity1.addComponent(new StringComponent());
    verify(eventSystem).send(entity1, OnChangedComponent.newInstance(), comp2);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 5 with EventSystem

use of org.terasology.entitySystem.event.internal.EventSystem in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testChangeComponentEventSentWhenSave.

@Test
public void testChangeComponentEventSentWhenSave() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    StringComponent comp = entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    entity1.saveComponent(comp);
    verify(eventSystem).send(entity1, OnChangedComponent.newInstance(), comp);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

EventSystem (org.terasology.entitySystem.event.internal.EventSystem)9 EntityRef (org.terasology.entitySystem.entity.EntityRef)8 Test (org.junit.Test)5 StringComponent (org.terasology.entitySystem.stubs.StringComponent)5 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 InputSystem (org.terasology.input.InputSystem)2 ConsoleImpl (org.terasology.logic.console.ConsoleImpl)2 ConsoleSystem (org.terasology.logic.console.ConsoleSystem)2 CoreCommands (org.terasology.logic.console.commands.CoreCommands)2 LocalPlayer (org.terasology.logic.players.LocalPlayer)2 ClientComponent (org.terasology.network.ClientComponent)2 NUIManager (org.terasology.rendering.nui.NUIManager)2 NUIManagerInternal (org.terasology.rendering.nui.internal.NUIManagerInternal)2 StateLoading (org.terasology.engine.modes.StateLoading)1 RegisterInputSystem (org.terasology.engine.modes.loadProcesses.RegisterInputSystem)1 ModuleManager (org.terasology.engine.module.ModuleManager)1 PojoEntityManager (org.terasology.entitySystem.entity.internal.PojoEntityManager)1 EventSystemImpl (org.terasology.entitySystem.event.internal.EventSystemImpl)1 EntitySystemLibrary (org.terasology.entitySystem.metadata.EntitySystemLibrary)1