Search in sources :

Example 6 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer 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 7 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class InputSystemTests method setUpLocalPlayer.

private void setUpLocalPlayer(Context context) {
    LocalPlayer localPlayer = new LocalPlayer();
    clientEntity = mock(EntityRef.class);
    ClientComponent clientComponent = new ClientComponent();
    characterEntity = mock(EntityRef.class);
    clientComponent.character = characterEntity;
    when(clientEntity.getComponent(ClientComponent.class)).thenReturn(clientComponent);
    localPlayer.setClientEntity(clientEntity);
    context.put(LocalPlayer.class, localPlayer);
    registerEntityKeyCapturing();
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 8 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class VisualCharacterSystemTest method setup.

@Before
public void setup() throws Exception {
    this.system = new VisualCharacterSystem();
    Context context = new ContextImpl();
    this.localPlayer = Mockito.mock(LocalPlayer.class);
    context.put(LocalPlayer.class, localPlayer);
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return clientEntityReturnedByLocalPlayer;
        }
    }).when(localPlayer).getClientEntity();
    this.entityManager = Mockito.mock(EntityManager.class);
    Mockito.doReturn(Mockito.mock(EntityBuilder.class)).when(entityManager).newBuilder();
    context.put(EntityManager.class, this.entityManager);
    InjectionHelper.inject(system, context);
    system.setCreateAndAttachVisualEntityStrategy((entityBuilder, characterEntity) -> Mockito.mock(EntityRef.class));
}
Also used : Context(org.terasology.context.Context) Answer(org.mockito.stubbing.Answer) EntityManager(org.terasology.entitySystem.entity.EntityManager) LocalPlayer(org.terasology.logic.players.LocalPlayer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) ContextImpl(org.terasology.context.internal.ContextImpl) EntityRef(org.terasology.entitySystem.entity.EntityRef) Before(org.junit.Before)

Example 9 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class BlockDestroyedMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    localPlayer = CoreRegistry.get(LocalPlayer.class);
    EntityRef playerEntity = localPlayer.getCharacterEntity();
    if (playerEntity.hasComponent(GamePlayStatsComponent.class)) {
        GamePlayStatsComponent gamePlayStatsComponent = playerEntity.getComponent(GamePlayStatsComponent.class);
        telemetryFieldToValue.clear();
        telemetryFieldToValue.putAll(gamePlayStatsComponent.blockDestroyedMap);
        return telemetryFieldToValue;
    } else {
        return telemetryFieldToValue;
    }
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 10 with LocalPlayer

use of org.terasology.logic.players.LocalPlayer in project Terasology by MovingBlocks.

the class BlockPlacedMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    localPlayer = CoreRegistry.get(LocalPlayer.class);
    EntityRef playerEntity = localPlayer.getCharacterEntity();
    if (playerEntity.hasComponent(GamePlayStatsComponent.class)) {
        GamePlayStatsComponent gamePlayStatsComponent = playerEntity.getComponent(GamePlayStatsComponent.class);
        telemetryFieldToValue.clear();
        telemetryFieldToValue.putAll(gamePlayStatsComponent.blockPlacedMap);
        return telemetryFieldToValue;
    } else {
        return telemetryFieldToValue;
    }
}
Also used : LocalPlayer(org.terasology.logic.players.LocalPlayer) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

LocalPlayer (org.terasology.logic.players.LocalPlayer)11 EntityRef (org.terasology.entitySystem.entity.EntityRef)8 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)5 ClientComponent (org.terasology.network.ClientComponent)4 GamePlayStatsComponent (org.terasology.telemetry.GamePlayStatsComponent)4 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)3 RenderingSubsystemFactory (org.terasology.engine.subsystem.RenderingSubsystemFactory)2 EntityManager (org.terasology.entitySystem.entity.EntityManager)2 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)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 BackdropProvider (org.terasology.rendering.backdrop.BackdropProvider)2 BackdropRenderer (org.terasology.rendering.backdrop.BackdropRenderer)2 Skysphere (org.terasology.rendering.backdrop.Skysphere)2 WorldRenderer (org.terasology.rendering.world.WorldRenderer)2 WorldProvider (org.terasology.world.WorldProvider)2 BlockManager (org.terasology.world.block.BlockManager)2 EntityAwareWorldProvider (org.terasology.world.internal.EntityAwareWorldProvider)2