Search in sources :

Example 41 with ResourceUrn

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();
}
Also used : MaterialData(org.terasology.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.assets.ResourceUrn) Texture(org.terasology.rendering.assets.texture.Texture)

Example 42 with ResourceUrn

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);
    }
}
Also used : AtlasData(org.terasology.rendering.assets.atlas.AtlasData) Vector2f(org.terasology.math.geom.Vector2f) SubtextureData(org.terasology.rendering.assets.texture.subtexture.SubtextureData) ResourceUrn(org.terasology.assets.ResourceUrn) TObjectIntMap(gnu.trove.map.TObjectIntMap) Map(java.util.Map) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Name(org.terasology.naming.Name)

Example 43 with ResourceUrn

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;
}
Also used : Tessellator(org.terasology.rendering.primitives.Tessellator) Vector4f(org.terasology.math.geom.Vector4f) NUIManager(org.terasology.rendering.nui.NUIManager) ResourceUrn(org.terasology.assets.ResourceUrn) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) Name(org.terasology.naming.Name)

Example 44 with ResourceUrn

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);
            }
        }
    }
}
Also used : Translation(org.terasology.i18n.assets.Translation) ResourceUrn(org.terasology.assets.ResourceUrn) Uri(org.terasology.engine.Uri) SimpleUri(org.terasology.engine.SimpleUri)

Example 45 with ResourceUrn

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);
}
Also used : TemplateEngine(org.terasology.persistence.TemplateEngine) TemplateEngineImpl(org.terasology.persistence.TemplateEngineImpl) SimpleUri(org.terasology.engine.SimpleUri) 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