Search in sources :

Example 1 with WorldConfigurator

use of org.terasology.engine.world.generator.WorldConfigurator in project Terasology by MovingBlocks.

the class PreviewWorldScreen method resetEnvironment.

private void resetEnvironment() {
    CoreRegistry.setContext(context);
    if (environment != null) {
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        environmentSwitchHandler.handleSwitchBackFromPreviewEnvironment(subContext);
        environment.close();
        environment = null;
    }
    previewGen.close();
    WorldConfigurator worldConfig = worldGenerator.getConfigurator();
    Map<String, Component> params = worldConfig.getProperties();
    if (params != null) {
        config.setModuleConfigs(worldGenerator.getUri(), params);
    }
}
Also used : WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) Component(org.terasology.gestalt.entitysystem.component.Component) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 2 with WorldConfigurator

use of org.terasology.engine.world.generator.WorldConfigurator in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method addGameManifestToSaveTransaction.

private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
    BlockManager blockManager = CoreRegistry.get(BlockManager.class);
    UniverseConfig universeConfig = config.getUniverseConfig();
    Time time = CoreRegistry.get(Time.class);
    Game game = CoreRegistry.get(Game.class);
    GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    List<String> registeredBlockFamilies = Lists.newArrayList();
    for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
        registeredBlockFamilies.add(family.getURI().toString());
    }
    gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
    gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
    List<WorldInfo> worlds = universeConfig.getWorlds();
    for (WorldInfo worldInfo : worlds) {
        gameManifest.addWorld(worldInfo);
    }
    WorldGenerator worldGenerator = CoreRegistry.get(WorldGenerator.class);
    if (worldGenerator != null) {
        WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
        Map<String, Component> params = worldConfigurator.getProperties();
        gameManifest.setModuleConfigs(worldGenerator.getUri(), params);
    }
    saveTransactionBuilder.setGameManifest(gameManifest);
}
Also used : WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) Time(org.terasology.engine.core.Time) UniverseConfig(org.terasology.engine.config.UniverseConfig) ModuleManager(org.terasology.engine.core.module.ModuleManager) Game(org.terasology.engine.game.Game) GameManifest(org.terasology.engine.game.GameManifest) BlockManager(org.terasology.engine.world.block.BlockManager) WorldInfo(org.terasology.engine.world.internal.WorldInfo) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) Module(org.terasology.gestalt.module.Module) Component(org.terasology.gestalt.entitysystem.component.Component) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 3 with WorldConfigurator

use of org.terasology.engine.world.generator.WorldConfigurator in project Terasology by MovingBlocks.

the class PreviewWorldScreen method configureProperties.

private void configureProperties() {
    PropertyLayout propLayout = find("properties", PropertyLayout.class);
    propLayout.setOrdering(PropertyOrdering.byLabel());
    propLayout.clear();
    WorldConfigurator worldConfig = worldGenerator.getConfigurator();
    Map<String, Component> params = worldConfig.getProperties();
    for (String key : params.keySet()) {
        Class<? extends Component> clazz = params.get(key).getClass();
        Component comp = config.getModuleConfig(worldGenerator.getUri(), key, clazz);
        if (comp != null) {
            // use the data from the config instead of defaults
            worldConfig.setProperty(key, comp);
        }
    }
    ComponentLibrary compLib = subContext.get(ComponentLibrary.class);
    for (String label : params.keySet()) {
        PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), context.get(OneOfProviderFactory.class)) {

            @Override
            protected <T> Binding<T> createTextBinding(Object target, FieldMetadata<Object, T> fieldMetadata) {
                return new WorldConfigBinding<>(worldConfig, label, compLib, fieldMetadata);
            }

            @Override
            protected Binding<Float> createFloatBinding(Object target, FieldMetadata<Object, ?> fieldMetadata) {
                return new WorldConfigNumberBinding(worldConfig, label, compLib, fieldMetadata);
            }
        };
        Component target = params.get(label);
        List<Property<?, ?>> properties = provider.createProperties(target);
        propLayout.addProperties(label, properties);
    }
}
Also used : FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.nui.properties.PropertyProvider) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) Component(org.terasology.gestalt.entitysystem.component.Component) Property(org.terasology.nui.properties.Property)

Example 4 with WorldConfigurator

use of org.terasology.engine.world.generator.WorldConfigurator in project Terasology by MovingBlocks.

the class WorldSetupScreen method configureProperties.

/**
 * Assigns a {@link WorldConfigurator} for every world if it doesn't exist. Using
 * the WorldConfigurator it gets the properties associated with that world.
 */
private void configureProperties() {
    PropertyLayout propLayout = find("properties", PropertyLayout.class);
    propLayout.setOrdering(PropertyOrdering.byLabel());
    propLayout.clear();
    WorldConfigurator worldConfig;
    if (world.getWorldConfigurator() != null) {
        worldConfig = world.getWorldConfigurator();
    } else {
        worldConfig = worldGenerator.getConfigurator();
        world.setWorldConfigurator(worldConfig);
    }
    oldWorldConfig = worldConfig;
    Map<String, Component> params = worldConfig.getProperties();
    for (String key : params.keySet()) {
        Class<? extends Component> clazz = params.get(key).getClass();
        Component comp = config.getModuleConfig(worldGenerator.getUri(), key, clazz);
        if (comp != null) {
            // use the data from the config instead of defaults
            worldConfig.setProperty(key, comp);
        }
    }
    ComponentLibrary compLib = context.get(ComponentLibrary.class);
    for (String label : params.keySet()) {
        PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), context.get(OneOfProviderFactory.class)) {

            @Override
            protected <T> Binding<T> createTextBinding(Object target, FieldMetadata<Object, T> fieldMetadata) {
                return new WorldSetupScreen.WorldConfigBinding<>(worldConfig, label, compLib, fieldMetadata);
            }

            @Override
            protected Binding<Float> createFloatBinding(Object target, FieldMetadata<Object, ?> fieldMetadata) {
                return new WorldSetupScreen.WorldConfigNumberBinding(worldConfig, label, compLib, fieldMetadata);
            }
        };
        Component target = params.get(label);
        List<Property<?, ?>> properties = provider.createProperties(target);
        propLayout.addProperties(label, properties);
    }
}
Also used : FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.nui.properties.PropertyProvider) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) Component(org.terasology.gestalt.entitysystem.component.Component) Property(org.terasology.nui.properties.Property)

Aggregations

WorldConfigurator (org.terasology.engine.world.generator.WorldConfigurator)4 Component (org.terasology.gestalt.entitysystem.component.Component)4 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)2 PropertyLayout (org.terasology.nui.layouts.PropertyLayout)2 OneOfProviderFactory (org.terasology.nui.properties.OneOfProviderFactory)2 Property (org.terasology.nui.properties.Property)2 PropertyProvider (org.terasology.nui.properties.PropertyProvider)2 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)2 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)2 UniverseConfig (org.terasology.engine.config.UniverseConfig)1 Time (org.terasology.engine.core.Time)1 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 Game (org.terasology.engine.game.Game)1 GameManifest (org.terasology.engine.game.GameManifest)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 ClientComponent (org.terasology.engine.network.ClientComponent)1 BlockManager (org.terasology.engine.world.block.BlockManager)1 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)1 WorldGenerator (org.terasology.engine.world.generator.WorldGenerator)1