@Override public Optional<TextureData> getAssetData(ResourceUrn urn) throws IOException { if (TerasologyConstants.ENGINE_MODULE.equals(urn.getModuleName()) && TextureUtil.COLOR_RESOURCE_NAME.equals(urn.getResourceName())) { Name fragmentName = urn.getFragmentName(); if (!fragmentName.isEmpty()) { Color color = TextureUtil.getColorForColorName(fragmentName.toLowerCase()); return Optional.of(TextureDataFactory.newInstance(color)); } } return Optional.empty(); } }
@Override public String convertToString(Name value) { return value.toString(); } }
@Override public Set<Name> getModulesProviding(Name resourceName) { if (ICON_DISCRIMINATOR.equals(resourceName)) { return ImmutableSet.copyOf(Collections2.transform(assetManager.resolve(resourceName.toString(), TextureRegionAsset.class), new Function<ResourceUrn, Name>() { @Nullable @Override public Name apply(ResourceUrn input) { return input.getModuleName(); } })); } return Collections.emptySet(); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append(blockFamilyDefinition.toString()); if (shape.isPresent()) { builder.append(MODULE_SEPARATOR); builder.append(shape.get().toString()); } if (!blockName.isEmpty()) { builder.append(IDENTIFIER_SEPARATOR); builder.append(blockName.toString()); } return builder.toString(); }
public static Mesh getIconMesh(TextureRegion region) { if (region instanceof Asset) { ResourceUrn urn = ((Asset<?>) region).getUrn(); if (urn.getFragmentName().isEmpty()) { return Assets.get(new ResourceUrn(urn.getModuleName(), IconMeshDataProducer.ICON_DISCRIMINATOR, urn.getResourceName()), Mesh.class).get(); } else { Name fragName = new Name(urn.getResourceName().toString() + ResourceUrn.FRAGMENT_SEPARATOR + urn.getFragmentName().toString()); return Assets.get(new ResourceUrn(urn.getModuleName(), IconMeshDataProducer.ICON_DISCRIMINATOR, fragName), Mesh.class).get(); } } else { return generateIconMesh(region); } }
@Override public Set<Name> getModulesProviding(Name resourceName) { if (TextureUtil.NOISE_RESOURCE_NAME.equals(resourceName)) { return ImmutableSet.of(TerasologyConstants.ENGINE_MODULE); } return Collections.emptySet(); }
/** * Determine if command is matching one of criteria * * @param searchLowercase searched string * @param command ConsoleCommand to check if matches searched string * @return boolean containing true if command matches searched string else false */ private static boolean matchesSearch(String searchLowercase, ConsoleCommand command) { return command.getName().toLowerCase().contains(searchLowercase) || command.getDescription().toLowerCase().contains(searchLowercase) || command.getHelpText().toLowerCase().contains(searchLowercase) || command.getUsage().toLowerCase().contains(searchLowercase) || command.getRequiredPermission().toLowerCase().contains(searchLowercase); }
@Override public Optional<MaterialData> getAssetData(ResourceUrn urn) throws IOException { if (RESOURCE_NAME.equals(urn.getResourceName()) && !urn.getFragmentName().isEmpty()) { Optional<? extends Shader> fontShader = assetManager.getAsset(FONT_SHADER_URN, Shader.class); if (!fontShader.isPresent()) { logger.error("Unable to resolve font shader"); return Optional.empty(); } Optional<Texture> texture = assetManager.getAsset(new ResourceUrn(urn.getModuleName(), urn.getFragmentName()), Texture.class); if (texture.isPresent()) { MaterialData materialData = new MaterialData(fontShader.get()); materialData.setParam("texture", texture.get()); return Optional.of(materialData); } } return Optional.empty(); } }
@Override public Optional<MeshData> getAssetData(ResourceUrn urn) throws IOException { if (ICON_DISCRIMINATOR.equals(urn.getResourceName())) { ResourceUrn textureUrn = new ResourceUrn(urn.getModuleName().toString() + ResourceUrn.RESOURCE_SEPARATOR + urn.getFragmentName().toString()); Optional<TextureRegionAsset> textureRegionAsset = assetManager.getAsset(textureUrn, TextureRegionAsset.class); if (textureRegionAsset.isPresent() && !textureRegionAsset.get().getTexture().isDisposed()) { return Optional.of(IconMeshFactory.generateIconMeshData(textureRegionAsset.get())); } } return Optional.empty(); }
@Override public Set<Name> getModulesProviding(Name resourceName) { if (TextureUtil.COLOR_RESOURCE_NAME.equals(resourceName)) { return ImmutableSet.of(TerasologyConstants.ENGINE_MODULE); } return Collections.emptySet(); }
@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); } }
/** * @return The uri of the block's family, including shape */ public BlockUri getFamilyUri() { if (!blockName.isEmpty()) { return new BlockUri(blockFamilyDefinition, shape, Name.EMPTY); } else { return this; } }
@Override public int compare(ConsoleCommand o1, ConsoleCommand o2) { int nameComparison = o1.getName().compareTo(o2.getName()); if (nameComparison != 0) { return nameComparison; } if (!o1.endsWithVarargs() && o2.endsWithVarargs()) { return -1; } else if (o1.endsWithVarargs() && !o2.endsWithVarargs()) { return 1; } return o2.getRequiredParameterCount() - o1.getRequiredParameterCount(); }; };
/** * Creates a SimpleUri for the given module:object combo * * @param moduleName * @param objectName */ public SimpleUri(Name moduleName, String objectName) { this(moduleName, new Name(objectName)); }
@Override public String getAsString(Name item) { if (item == null) { return ""; } return item.toString(); }