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));
}
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();
}
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));
}
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;
}
}
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;
}
}
Aggregations