use of org.terasology.gestalt.assets.management.AssetManager in project Terasology by MovingBlocks.
the class HeadlessEnvironment method setupAssetManager.
@Override
protected AssetManager setupAssetManager() {
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionDataAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionDataAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
assetTypeManager.createAssetType(StaticSound.class, NullSound::new, "sounds");
assetTypeManager.createAssetType(StreamingSound.class, NullStreamingSound::new, "music");
assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
assetTypeManager.createAssetType(Font.class, FontImpl::new, "fonts");
AssetType<Texture, TextureData> textureDataAssetType = assetTypeManager.createAssetType(Texture.class, HeadlessTexture::create, "textures", "fonts");
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getPath().get(1).equals("textures")));
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getPath().get(1).equals("fonts")));
assetTypeManager.createAssetType(Shader.class, HeadlessShader::new, "shaders");
assetTypeManager.createAssetType(Material.class, HeadlessMaterial::new, "materials");
assetTypeManager.createAssetType(Mesh.class, HeadlessMesh::new, "mesh");
assetTypeManager.createAssetType(SkeletalMesh.class, HeadlessSkeletalMesh::new, "skeletalMesh");
assetTypeManager.createAssetType(MeshAnimation.class, MeshAnimationImpl::new, "animations");
assetTypeManager.createAssetType(Atlas.class, Atlas::new, "atlas");
assetTypeManager.createAssetType(Subtexture.class, Subtexture::new);
assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());
context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
context.put(AssetManager.class, assetTypeManager.getAssetManager());
return assetTypeManager.getAssetManager();
}
use of org.terasology.gestalt.assets.management.AssetManager in project Terasology by MovingBlocks.
the class SettingWidgetFactoryTest method testCreateWidgetFor.
@Test
void testCreateWidgetFor() {
ModuleEnvironment environment = mock(ModuleEnvironment.class);
when(environment.getSubtypesOf(eq(ConstraintWidgetFactory.class))).thenReturn(Lists.newArrayList(NumberRangeConstraintWidgetFactory.class));
AssetManager assetManager = new AssetManager(mock(AssetTypeManager.class));
SettingWidgetFactory settingWidgetFactory = new SettingWidgetFactory(environment, assetManager, null);
Setting<Integer> setting = mock(Setting.class);
when(setting.getConstraint()).thenReturn(new NumberRangeConstraint<>(0, 10, false, false));
Optional<ConstraintWidgetFactory<Integer, ?>> widget = settingWidgetFactory.getConstraintWidgetFactory(setting);
assertTrue(widget.isPresent());
assertTrue(widget.get() instanceof NumberRangeConstraintWidgetFactory);
}
use of org.terasology.gestalt.assets.management.AssetManager in project Terasology by MovingBlocks.
the class ChunkTest method setup.
@BeforeEach
public void setup() throws Exception {
super.setup();
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
CoreRegistry.put(BlockManager.class, blockManager);
ExtraBlockDataManager extraDataManager = new ExtraBlockDataManager();
chunk = new ChunkImpl(new Vector3i(0, 0, 0), blockManager, extraDataManager);
BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
}
use of org.terasology.gestalt.assets.management.AssetManager in project Terasology by MovingBlocks.
the class ChunkViewTest method setup.
@BeforeEach
public void setup() throws IOException {
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
CoreRegistry.put(BlockManager.class, blockManager);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);
extraDataManager = new ExtraBlockDataManager();
BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
}
use of org.terasology.gestalt.assets.management.AssetManager in project Terasology by MovingBlocks.
the class SettingWidgetFactory method getConstraintWidgetFactory.
/**
* Try to find {@link ConstraintWidgetFactory} for this {@link Setting}.
*
* @param setting for constaint factory.
* @param <T> type of settings
* @return {@link ConstraintWidgetFactory} for {@link Setting} if found, {@code Optinal.empty()} otherwise.
*/
<T> Optional<ConstraintWidgetFactory<T, ?>> getConstraintWidgetFactory(Setting<T> setting) {
SettingConstraint<?> constraint = setting.getConstraint();
if (constraint != null) {
for (Class<? extends ConstraintWidgetFactory> widgetType : environment.getSubtypesOf(ConstraintWidgetFactory.class)) {
Type constraintType = ReflectionUtil.getTypeParameterForSuper(widgetType, ConstraintWidgetFactory.class, 1);
if (constraint.getClass().equals(ReflectionUtil.getRawType(constraintType))) {
ConstraintWidgetFactory<T, ?> factory = InjectionHelper.createWithConstructorInjection(widgetType, context);
InjectionHelper.inject(factory, In.class, ImmutableMap.of(AssetManager.class, assetManager));
return Optional.of(factory);
}
}
}
return Optional.empty();
}
Aggregations