Search in sources :

Example 26 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class GameManifestProvider method createGameManifest.

/**
 * Generates game manifest with default settings (title, seed) if not specified.
 * Uses default world generator, and modules selection.
 * @TODO: rewrite/fix it when code will be more stable
 *
 * @param universeWrapper  contains the universe level properties
 * @param moduleManager    resolves modules
 * @param config           provides default module selection, world generator
 * @return                 game manifest with default settings
 */
public static GameManifest createGameManifest(final UniverseWrapper universeWrapper, final ModuleManager moduleManager, final Config config) {
    GameManifest gameManifest = new GameManifest();
    if (StringUtils.isNotBlank(universeWrapper.getGameName())) {
        gameManifest.setTitle(GameProvider.getNextGameName(universeWrapper.getGameName()));
    } else {
        gameManifest.setTitle(GameProvider.getNextGameName());
    }
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (!result.isSuccess()) {
        logger.error("Can't resolve dependencies");
        return null;
    }
    for (Module module : result.getModules()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    SimpleUri uri;
    String seed;
    WorldSetupWrapper worldSetup = universeWrapper.getTargetWorld();
    if (worldSetup != null) {
        uri = worldSetup.getWorldGenerator().getUri();
        seed = worldSetup.getWorldGenerator().getWorldSeed();
    } else {
        uri = config.getWorldGeneration().getDefaultGenerator();
        seed = universeWrapper.getSeed();
    }
    gameManifest.setSeed(seed);
    String targetWorldName = "";
    Map<String, Component> worldConfig = Maps.newHashMap();
    if (worldSetup != null) {
        targetWorldName = worldSetup.getWorldName().toString();
        if (worldSetup.getWorldConfigurator() != null) {
            // horrible hack to get configs into manifest.
            // config driven by CreateWorldEntity.
            // world config set somewhere else as well no clear drive from config --> world
            gameManifest.setModuleConfigs(uri, worldSetup.getWorldConfigurator().getProperties());
        }
    }
    // This is multiplied by the number of seconds in a day (86400000) to determine the exact  millisecond at which the game will start.
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, targetWorldName, seed, (long) (WorldTime.DAY_LENGTH * WorldTime.SUNRISE_OFFSET), uri);
    gameManifest.addWorld(worldInfo);
    config.getUniverseConfig().addWorldManager(worldInfo);
    config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
    config.getUniverseConfig().setUniverseSeed(universeWrapper.getSeed());
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) Module(org.terasology.gestalt.module.Module) Component(org.terasology.gestalt.entitysystem.component.Component) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver)

Example 27 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class ParticleUpdaterImplTest method getTestGeneratorsAndAffectors.

private Iterator<Component> getTestGeneratorsAndAffectors() {
    Collection<Component> components = new LinkedList<>();
    components.add(new EnergyRangeGeneratorComponent(0.5f, 1f));
    components.add(new VelocityAffectorComponent());
    return components.iterator();
}
Also used : EnergyRangeGeneratorComponent(org.terasology.engine.particles.components.generators.EnergyRangeGeneratorComponent) VelocityAffectorComponent(org.terasology.engine.particles.components.affectors.VelocityAffectorComponent) Component(org.terasology.gestalt.entitysystem.component.Component) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) EnergyRangeGeneratorComponent(org.terasology.engine.particles.components.generators.EnergyRangeGeneratorComponent) LinkedList(java.util.LinkedList) VelocityAffectorComponent(org.terasology.engine.particles.components.affectors.VelocityAffectorComponent)

Example 28 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class ParticleUpdaterImplTest method testEmitterConfiguration.

@Test
public void testEmitterConfiguration() {
    EntityRef emitterEntity = mock(EntityRef.class);
    Iterator<Component> componentIterator = getTestGeneratorsAndAffectors();
    when(emitterEntity.iterateComponents()).thenReturn(() -> componentIterator);
    ParticleEmitterComponent particleEmitterComponent = new ParticleEmitterComponent();
    particleEmitterComponent.ownerEntity = emitterEntity;
    when(emitterEntity.getComponent(ParticleEmitterComponent.class)).thenReturn(particleEmitterComponent);
    particleUpdater.addEmitter(emitterEntity);
    particleUpdater.configureEmitter(particleEmitterComponent);
    for (Component component : (Iterable<Component>) () -> componentIterator) {
        if (component.getClass() == EnergyRangeGeneratorComponent.class) {
            assertTrue(particleEmitterComponent.generatorFunctionMap.containsKey(component));
        } else if (component.getClass() == VelocityAffectorComponent.class) {
            assertTrue(particleEmitterComponent.affectorFunctionMap.containsKey(component));
        }
    }
}
Also used : VelocityAffectorComponent(org.terasology.engine.particles.components.affectors.VelocityAffectorComponent) Component(org.terasology.gestalt.entitysystem.component.Component) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) EnergyRangeGeneratorComponent(org.terasology.engine.particles.components.generators.EnergyRangeGeneratorComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) VelocityAffectorComponent(org.terasology.engine.particles.components.affectors.VelocityAffectorComponent) Test(org.junit.jupiter.api.Test)

Example 29 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class EntityBuilder method addPrefab.

/**
 * Adds all of the components from a prefab to this builder
 *
 * @param prefab the prefab to add
 * @return whether the prefab was successfully added
 */
public void addPrefab(Prefab prefab) {
    if (prefab != null) {
        for (Component component : prefab.iterateComponents()) {
            Component componentCopy = entityManager.getComponentLibrary().copy(component);
            addComponent(verifyNotNull(componentCopy, "Component %s not registered (in prefab %s)", component, prefab));
        }
        addComponent(new EntityInfoComponent(prefab, prefab.isPersisted(), prefab.isAlwaysRelevant()));
    } else {
        addComponent(new EntityInfoComponent());
    }
}
Also used : EntityInfoComponent(org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent) Component(org.terasology.gestalt.entitysystem.component.Component) OnAddedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnAddedComponent) OnActivatedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent) EntityInfoComponent(org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent)

Example 30 with Component

use of org.terasology.gestalt.entitysystem.component.Component in project Terasology by MovingBlocks.

the class GameManifest method setModuleConfigs.

/**
 * @param generatorUri the generator Uri
 * @param configs      the new config params for the world generator
 */
public void setModuleConfigs(SimpleUri generatorUri, Map<String, Component> configs) {
    Gson gson = createGson();
    Map<String, JsonElement> map = Maps.newHashMap();
    for (Map.Entry<String, Component> entry : configs.entrySet()) {
        JsonElement json = gson.toJsonTree(entry.getValue());
        map.put(entry.getKey(), json);
    }
    getModuleConfigs().put(generatorUri, map);
}
Also used : JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) Component(org.terasology.gestalt.entitysystem.component.Component) Map(java.util.Map)

Aggregations

Component (org.terasology.gestalt.entitysystem.component.Component)57 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)20 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)12 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 OnActivatedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent)11 NetworkComponent (org.terasology.engine.network.NetworkComponent)10 OnChangedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnChangedComponent)9 EntityData (org.terasology.protobuf.EntityData)8 BeforeDeactivateComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent)7 OnAddedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnAddedComponent)7 BlockComponent (org.terasology.engine.world.block.BlockComponent)7 EntityInfoComponent (org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent)6 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)6 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)5 ClientComponent (org.terasology.engine.network.ClientComponent)5 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)4 ByteString (com.google.protobuf.ByteString)3