@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); } }
@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); } }
@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()); }
ResourceUrn uri = TextureUtil.getTextureUriForColor(Color.WHITE); Texture tex = Assets.get(uri, Texture.class).get(); img.setImage(tex);