Search in sources :

Example 1 with Config

use of org.terasology.config.Config in project Terasology by MovingBlocks.

the class MenuAnimationSystems method createDefaultSwipeAnimation.

public static MenuAnimationSystem createDefaultSwipeAnimation() {
    RenderingConfig config = CoreRegistry.get(Config.class).getRendering();
    MenuAnimationSystem swipe = new SwipeMenuAnimationSystem(0.25f, Direction.LEFT_TO_RIGHT);
    MenuAnimationSystem instant = new MenuAnimationSystemStub();
    Supplier<MenuAnimationSystem> provider = () -> config.isAnimatedMenu() ? swipe : instant;
    return new DeferredMenuAnimationSystem(provider);
}
Also used : RenderingConfig(org.terasology.config.RenderingConfig) Config(org.terasology.config.Config) RenderingConfig(org.terasology.config.RenderingConfig)

Example 2 with Config

use of org.terasology.config.Config in project Terasology by MovingBlocks.

the class TreeTests method setup.

@Before
public void setup() {
    ContextImpl context = new ContextImpl();
    CoreRegistry.setContext(context);
    // Needed only as long as #1536 is unresolved
    context.put(Config.class, new Config(new MockContext()));
    blockManager = Mockito.mock(BlockManager.class);
    Block air = blockManager.getBlock(BlockManager.AIR_ID);
    biomeManager = Mockito.mock(BiomeManager.class);
    Mockito.when(blockManager.getBlock(Matchers.<BlockUri>any())).thenReturn(air);
    Mockito.when(blockManager.getBlock(Matchers.<String>any())).thenReturn(air);
    context.put(BlockManager.class, blockManager);
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) MockContext(org.terasology.context.internal.MockContext) Config(org.terasology.config.Config) BlockManager(org.terasology.world.block.BlockManager) Block(org.terasology.world.block.Block) ContextImpl(org.terasology.context.internal.ContextImpl) Before(org.junit.Before)

Example 3 with Config

use of org.terasology.config.Config in project Terasology by MovingBlocks.

the class CreateWorldEntity method step.

@Override
public boolean step() {
    EntityManager entityManager = context.get(EntityManager.class);
    ChunkProvider chunkProvider = context.get(ChunkProvider.class);
    Iterator<EntityRef> worldEntityIterator = entityManager.getEntitiesWith(WorldComponent.class).iterator();
    if (worldEntityIterator.hasNext()) {
        EntityRef worldEntity = worldEntityIterator.next();
        chunkProvider.setWorldEntity(worldEntity);
        // get the world generator config from the world entity
        // replace the world generator values from the components in the world entity
        WorldGenerator worldGenerator = context.get(WorldGenerator.class);
        WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
        Map<String, Component> params = worldConfigurator.getProperties();
        for (Map.Entry<String, Component> entry : params.entrySet()) {
            Class<? extends Component> clazz = entry.getValue().getClass();
            Component comp = worldEntity.getComponent(clazz);
            if (comp != null) {
                worldConfigurator.setProperty(entry.getKey(), comp);
            }
        }
    } else {
        EntityRef worldEntity = entityManager.create();
        worldEntity.addComponent(new WorldComponent());
        NetworkComponent networkComponent = new NetworkComponent();
        networkComponent.replicateMode = NetworkComponent.ReplicateMode.ALWAYS;
        worldEntity.addComponent(networkComponent);
        chunkProvider.setWorldEntity(worldEntity);
        // transfer all world generation parameters from Config to WorldEntity
        WorldGenerator worldGenerator = context.get(WorldGenerator.class);
        SimpleUri generatorUri = worldGenerator.getUri();
        Config config = context.get(Config.class);
        // get the map of properties from the world generator.
        // Replace its values with values from the config set by the UI.
        // Also set all the components to the world entity.
        WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
        Map<String, Component> params = worldConfigurator.getProperties();
        for (Map.Entry<String, Component> entry : params.entrySet()) {
            Class<? extends Component> clazz = entry.getValue().getClass();
            Component comp = config.getModuleConfig(generatorUri, entry.getKey(), clazz);
            if (comp != null) {
                worldEntity.addComponent(comp);
                worldConfigurator.setProperty(entry.getKey(), comp);
            } else {
                worldEntity.addComponent(entry.getValue());
            }
        }
    }
    return true;
}
Also used : WorldGenerator(org.terasology.world.generator.WorldGenerator) WorldConfigurator(org.terasology.world.generator.WorldConfigurator) Config(org.terasology.config.Config) SimpleUri(org.terasology.engine.SimpleUri) EntityManager(org.terasology.entitySystem.entity.EntityManager) NetworkComponent(org.terasology.network.NetworkComponent) ChunkProvider(org.terasology.world.chunks.ChunkProvider) WorldComponent(org.terasology.world.WorldComponent) NetworkComponent(org.terasology.network.NetworkComponent) WorldComponent(org.terasology.world.WorldComponent) Component(org.terasology.entitySystem.Component) EntityRef(org.terasology.entitySystem.entity.EntityRef) Map(java.util.Map)

Example 4 with Config

use of org.terasology.config.Config in project Terasology by MovingBlocks.

the class StartServer method step.

@Override
public boolean step() {
    try {
        Config config = context.get(Config.class);
        int port = config.getNetwork().getServerPort();
        context.get(NetworkSystem.class).host(port, dedicated);
    } catch (HostingFailedException e) {
        context.get(NUIManager.class).pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Failed to Host", e.getMessage() + " - Reverting to single player");
    }
    return true;
}
Also used : Config(org.terasology.config.Config) HostingFailedException(org.terasology.network.exceptions.HostingFailedException) NetworkSystem(org.terasology.network.NetworkSystem) NUIManager(org.terasology.rendering.nui.NUIManager)

Example 5 with Config

use of org.terasology.config.Config in project Terasology by MovingBlocks.

the class ConfigurationSubsystem method preInitialise.

@Override
public void preInitialise(Context rootContext) {
    config = new Config(rootContext);
    config.load();
    FlexibleConfigManager flexibleConfigManager = new FlexibleConfigManagerImpl();
    rootContext.put(FlexibleConfigManager.class, flexibleConfigManager);
    // TODO: Update rendering config description
    FlexibleConfig renderingFlexibleConfig = new FlexibleConfigImpl("Rendering Config");
    flexibleConfigManager.addConfig(new SimpleUri("engine:rendering"), renderingFlexibleConfig);
    flexibleConfigManager.loadAllConfigs();
    // Add settings to RenderingFC
    String serverPortProperty = System.getProperty(SERVER_PORT_PROPERTY);
    if (serverPortProperty != null) {
        try {
            config.getNetwork().setServerPort(Integer.parseInt(serverPortProperty));
        } catch (NumberFormatException e) {
            logger.error("Failed to set server port to invalid value: {}", serverPortProperty);
        }
    }
    if (Iterables.isEmpty(config.getDefaultModSelection().listModules())) {
        config.getDefaultModSelection().addModule(TerasologyConstants.CORE_GAMEPLAY_MODULE);
    }
    checkServerIdentity();
    // TODO: Move to display subsystem
    logger.info("Video Settings: {}", config.renderConfigAsJson(config.getRendering()));
    rootContext.put(Config.class, config);
    // add facades
    rootContext.put(InputDeviceConfiguration.class, new InputDeviceConfigurationImpl(config));
    rootContext.put(BindsConfiguration.class, new BindsConfigurationImpl(config));
}
Also used : FlexibleConfigImpl(org.terasology.config.flexible.FlexibleConfigImpl) BindsConfigurationImpl(org.terasology.config.facade.BindsConfigurationImpl) FlexibleConfig(org.terasology.config.flexible.FlexibleConfig) Config(org.terasology.config.Config) SimpleUri(org.terasology.engine.SimpleUri) FlexibleConfigManagerImpl(org.terasology.config.flexible.FlexibleConfigManagerImpl) FlexibleConfig(org.terasology.config.flexible.FlexibleConfig) InputDeviceConfigurationImpl(org.terasology.config.facade.InputDeviceConfigurationImpl) FlexibleConfigManager(org.terasology.config.flexible.FlexibleConfigManager)

Aggregations

Config (org.terasology.config.Config)19 TelemetryConfig (org.terasology.config.TelemetryConfig)4 ContextImpl (org.terasology.context.internal.ContextImpl)4 SimpleUri (org.terasology.engine.SimpleUri)4 MockContext (org.terasology.context.internal.MockContext)3 ModuleManager (org.terasology.engine.module.ModuleManager)3 Map (java.util.Map)2 BeforeClass (org.junit.BeforeClass)2 Component (org.terasology.entitySystem.Component)2 Name (org.terasology.naming.Name)2 BlockManager (org.terasology.world.block.BlockManager)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 Lists (com.google.common.collect.Lists)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ByteBuffer (java.nio.ByteBuffer)1 FileSystem (java.nio.file.FileSystem)1 List (java.util.List)1 Objects (java.util.Objects)1 Callable (java.util.concurrent.Callable)1