Search in sources :

Example 26 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class TextureAssetResolverTest method testNoiseTextures.

@Test
public void testNoiseTextures() {
    int size = 256;
    ResourceUrn textureUriForWhiteNoise = TextureUtil.getTextureUriForWhiteNoise(size, 123354, 0, 255);
    String simpleString = textureUriForWhiteNoise.toString();
    Optional<Texture> tex = Assets.getTexture(simpleString);
    assertTrue(tex.isPresent());
    assertTrue(tex.get().getWidth() == size);
    assertTrue(tex.get().getHeight() == size);
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) Test(org.junit.Test)

Example 27 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class TextureAssetResolverTest method testColorTextures.

@Test
public void testColorTextures() {
    Random r = new FastRandom(123456);
    for (int i = 0; i < 10; i++) {
        int rgba = r.nextInt();
        Color red = new Color(rgba);
        ResourceUrn textureUriForColor = TextureUtil.getTextureUriForColor(red);
        String simpleString = textureUriForColor.toString();
        Optional<Texture> tex = Assets.getTexture(simpleString);
        assertTrue(tex.isPresent());
        ByteBuffer dataBuffer = tex.get().getData().getBuffers()[0];
        int firstPixel = dataBuffer.asIntBuffer().get(0);
        Assert.assertEquals(rgba, firstPixel);
    }
}
Also used : Random(org.terasology.utilities.random.Random) FastRandom(org.terasology.utilities.random.FastRandom) Color(org.terasology.rendering.nui.Color) FastRandom(org.terasology.utilities.random.FastRandom) ResourceUrn(org.terasology.assets.ResourceUrn) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 28 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class TextureUtilTest method testColorTransformedToTextureUri.

@Test
public void testColorTransformedToTextureUri() throws Exception {
    ResourceUrn assetUri = TextureUtil.getTextureUriForColor(Color.RED);
    assertEquals(TerasologyConstants.ENGINE_MODULE, assetUri.getModuleName());
    assertEquals(new Name("color"), assetUri.getResourceName());
    assertEquals(new Name("ff0000ff"), assetUri.getFragmentName());
    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    assetUri = TextureUtil.getTextureUriForColor(new Color(red, green, blue, alpha));
    assertEquals(TerasologyConstants.ENGINE_MODULE, assetUri.getModuleName());
    assertEquals(new Name("color"), assetUri.getResourceName());
    assertEquals(new Name("1203c40e"), assetUri.getFragmentName());
}
Also used : Color(org.terasology.rendering.nui.Color) ResourceUrn(org.terasology.assets.ResourceUrn) Name(org.terasology.naming.Name) Test(org.junit.Test)

Example 29 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class TextureUtilTest method testColorTransformedToAssetUriTransformedToColor.

@Test
public void testColorTransformedToAssetUriTransformedToColor() throws Exception {
    Color expectedColor = Color.RED;
    ResourceUrn assetUri = TextureUtil.getTextureUriForColor(expectedColor);
    Color actualColor = TextureUtil.getColorForColorName(assetUri.getFragmentName().toLowerCase());
    assertEquals(expectedColor, actualColor);
    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    expectedColor = new Color(red, green, blue, alpha);
    assetUri = TextureUtil.getTextureUriForColor(expectedColor);
    actualColor = TextureUtil.getColorForColorName(assetUri.getFragmentName().toLowerCase());
    assertEquals(expectedColor, actualColor);
}
Also used : Color(org.terasology.rendering.nui.Color) ResourceUrn(org.terasology.assets.ResourceUrn) Test(org.junit.Test)

Example 30 with ResourceUrn

use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method createPrefabWithString.

private Prefab createPrefabWithString(String urn, String text, AssetManager assetManager) {
    PrefabData prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent(text));
    return assetManager.loadAsset(new ResourceUrn(urn), prefabData, Prefab.class);
}
Also used : PrefabData(org.terasology.entitySystem.prefab.PrefabData) StringComponent(org.terasology.entitySystem.stubs.StringComponent) ResourceUrn(org.terasology.assets.ResourceUrn)

Aggregations

ResourceUrn (org.terasology.assets.ResourceUrn)65 Before (org.junit.Before)10 BlockFamilyDefinitionData (org.terasology.world.block.loader.BlockFamilyDefinitionData)10 AssetManager (org.terasology.assets.management.AssetManager)9 Prefab (org.terasology.entitySystem.prefab.Prefab)9 SymmetricBlockFamilyFactory (org.terasology.world.block.family.SymmetricBlockFamilyFactory)9 Command (org.terasology.logic.console.commandSystem.annotations.Command)8 EntityRef (org.terasology.entitySystem.entity.EntityRef)7 PrefabData (org.terasology.entitySystem.prefab.PrefabData)7 BlockUri (org.terasology.world.block.BlockUri)7 Name (org.terasology.naming.Name)6 Texture (org.terasology.rendering.assets.texture.Texture)6 BlockManagerImpl (org.terasology.world.block.internal.BlockManagerImpl)6 NullWorldAtlas (org.terasology.world.block.tiles.NullWorldAtlas)6 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.Test)5 SimpleUri (org.terasology.engine.SimpleUri)5 IOException (java.io.IOException)4 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)4 BiomeManager (org.terasology.world.biomes.BiomeManager)4