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