use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class FontMaterialProducer method getAssetData.
@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();
}
use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class WorldAtlasImpl method createTextureAtlas.
private void createTextureAtlas(final Texture texture) {
final Map<Name, Map<Name, SubtextureData>> textureAtlases = Maps.newHashMap();
final Vector2f texSize = new Vector2f(getRelativeTileSize(), getRelativeTileSize());
tileIndexes.forEachEntry((tileUri, index) -> {
Vector2f coords = getTexCoords(index);
SubtextureData subtextureData = new SubtextureData(texture, Rect2f.createFromMinAndSize(coords, texSize));
Map<Name, SubtextureData> textureAtlas = textureAtlases.get(tileUri.getModuleName());
if (textureAtlas == null) {
textureAtlas = Maps.newHashMap();
textureAtlases.put(tileUri.getModuleName(), textureAtlas);
}
textureAtlas.put(tileUri.getResourceName(), subtextureData);
return true;
});
for (Map.Entry<Name, Map<Name, SubtextureData>> atlas : textureAtlases.entrySet()) {
AtlasData data = new AtlasData(atlas.getValue());
Assets.generateAsset(new ResourceUrn(atlas.getKey(), new Name("terrain")), data, Atlas.class);
}
}
use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class InitialiseGraphics method step.
@Override
public boolean step() {
// Refresh widget library after modules got laoded:
NUIManager nuiManager = context.get(NUIManager.class);
((NUIManagerInternal) nuiManager).refreshWidgetsLibrary();
// TODO: This should be elsewhere
// Create gelatinousCubeMesh
Tessellator tessellator = new Tessellator();
TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1.0f, 1.0f, 1.0f, 1.0f), 0.8f, 0.8f, 0.6f, 0f, 0f, 0f);
TessellatorHelper.addBlockMesh(tessellator, new Vector4f(1.0f, 1.0f, 1.0f, 0.6f), 1.0f, 1.0f, 0.8f, 0f, 0f, 0f);
tessellator.generateMesh(new ResourceUrn(TerasologyConstants.ENGINE_MODULE, new Name("gelatinousCube")));
return true;
}
use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class TranslationSystemImpl method refresh.
@Override
public void refresh() {
Set<ResourceUrn> urns = assetManager.getAvailableAssets(Translation.class);
for (ResourceUrn urn : urns) {
Optional<Translation> asset = assetManager.getAsset(urn, Translation.class);
if (asset.isPresent()) {
Translation trans = asset.get();
Uri uri = trans.getProjectUri();
if (uri.isValid()) {
TranslationProject proj = projects.computeIfAbsent(uri, e -> new StandardTranslationProject());
proj.add(trans);
trans.subscribe(this::onAssetChanged);
logger.info("Discovered " + trans);
} else {
logger.warn("Ignoring invalid project uri: {}", uri);
}
}
}
}
use of org.terasology.assets.ResourceUrn in project Terasology by MovingBlocks.
the class TranslationSystemImpl method translate.
@Override
public String translate(String text, Locale otherLocale) {
TemplateEngine templateEngine = new TemplateEngineImpl(id -> {
ResourceUrn uri = new ResourceUrn(id);
SimpleUri projectUri = new SimpleUri(uri.getModuleName(), uri.getResourceName());
TranslationProject project = getProject(projectUri);
if (project != null) {
Optional<String> opt = project.translate(uri.getFragmentName(), otherLocale);
if (opt.isPresent()) {
return opt.get();
} else {
logger.warn("No translation for '{}'", id);
return "?" + uri.getFragmentName() + "?";
}
} else {
logger.warn("Invalid project id '{}'", id);
return "?" + uri.getFragmentName() + "?";
}
});
return templateEngine.transform(text);
}
Aggregations