Search in sources :

Example 6 with ComponentLibrary

use of org.terasology.engine.entitySystem.metadata.ComponentLibrary 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 7 with ComponentLibrary

use of org.terasology.engine.entitySystem.metadata.ComponentLibrary 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

ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)7 Component (org.terasology.gestalt.entitysystem.component.Component)3 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)3 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ContextImpl (org.terasology.engine.context.internal.ContextImpl)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)2 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)2 PrefabFormat (org.terasology.engine.entitySystem.prefab.internal.PrefabFormat)2 NetworkSystem (org.terasology.engine.network.NetworkSystem)2 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)2 WorldConfigurator (org.terasology.engine.world.generator.WorldConfigurator)2 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)2 ModuleAwareAssetTypeManager (org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager)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 CopyStrategyLibrary (org.terasology.reflection.copy.CopyStrategyLibrary)2