Search in sources :

Example 6 with Name

use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.

the class RegisterMods method step.

@Override
public boolean step() {
    if (applyModulesThread != null) {
        if (!applyModulesThread.isAlive()) {
            if (oldEnvironment != null) {
                oldEnvironment.close();
            }
            return true;
        }
        return false;
    } else {
        ModuleManager moduleManager = context.get(ModuleManager.class);
        List<Name> moduleIds = gameManifest.getModules().stream().map(NameVersion::getName).collect(Collectors.toCollection(ArrayList::new));
        DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
        ResolutionResult result = resolver.resolve(moduleIds);
        if (result.isSuccess()) {
            oldEnvironment = moduleManager.getEnvironment();
            ModuleEnvironment env = moduleManager.loadEnvironment(result.getModules(), true);
            for (Module moduleInfo : env.getModulesOrderedByDependencies()) {
                logger.info("Activating module: {}:{}", moduleInfo.getId(), moduleInfo.getVersion());
            }
            EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
            applyModulesThread = new Thread(() -> environmentSwitchHandler.handleSwitchToGameEnvironment(context));
            applyModulesThread.start();
            return false;
        } else {
            logger.warn("Missing at least one required module (or dependency) from the following list: {}", moduleIds);
            context.get(GameEngine.class).changeState(new StateMainMenu("Missing required module or dependency"));
            return true;
        }
    }
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) GameEngine(org.terasology.engine.core.GameEngine) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 7 with Name

use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.

the class FontFormat method parsePage.

private void parsePage(FontDataBuilder builder, Name moduleName, String pageInfo) throws IOException {
    Matcher pageMatcher = pagePattern.matcher(pageInfo);
    if (pageMatcher.matches()) {
        int pageId = Integer.parseInt(pageMatcher.group(1));
        Name textureName = new Name(pageMatcher.group(2).substring(0, pageMatcher.group(2).lastIndexOf('.')));
        Optional<Material> material = assetManager.getAsset(new ResourceUrn(moduleName, new Name("font"), textureName), Material.class);
        if (!material.isPresent()) {
            throw new IOException("Failed to load font - unable to resolve font page '" + textureName + "'");
        } else {
            builder.addPage(pageId, assetManager.getAsset(new ResourceUrn(moduleName, textureName), Texture.class).get(), material.get());
        }
    } else {
        throw new IOException("Failed to load font - invalid page line '" + pageInfo + "'");
    }
}
Also used : Matcher(java.util.regex.Matcher) Material(org.terasology.engine.rendering.assets.material.Material) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 8 with Name

use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.

the class NoiseTextureProducer method getAssetData.

@Override
public Optional<TextureData> getAssetData(ResourceUrn urn) throws IOException {
    if (TerasologyConstants.ENGINE_MODULE.equals(urn.getModuleName()) && TextureUtil.NOISE_RESOURCE_NAME.equals(urn.getResourceName())) {
        Name fragmentName = urn.getFragmentName();
        if (!fragmentName.isEmpty()) {
            String[] parts = fragmentName.toLowerCase().split("\\.");
            if (parts.length == 5) {
                String type = parts[0];
                int size = Integer.parseInt(parts[1]);
                long seed = Long.parseLong(parts[2]);
                int min = Integer.parseInt(parts[3]);
                int max = Integer.parseInt(parts[4]);
                switch(type) {
                    case "white":
                        return Optional.of(TextureDataFactory.createWhiteNoiseTexture(size, seed, min, max));
                }
            }
        }
    }
    return Optional.empty();
}
Also used : Name(org.terasology.gestalt.naming.Name)

Example 9 with Name

use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.

the class ReflectionUtil method getTypeUri.

public static String getTypeUri(Type type, ModuleEnvironment moduleEnvironment) {
    String typeSimpleName = typeToString(type, true);
    if (getRawType(type).getClassLoader() == null) {
        return typeSimpleName;
    }
    Name moduleProvidingType = moduleEnvironment.getModuleProviding(getRawType(type));
    if (moduleProvidingType == null) {
        return typeSimpleName;
    }
    return new SimpleUri(moduleProvidingType, typeSimpleName).toString();
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) Name(org.terasology.gestalt.naming.Name)

Example 10 with Name

use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.

the class ReflectionUtil method getFullyQualifiedSimpleUriFor.

/**
 * Returns the fully qualified {@link SimpleUri} for a type belonging to the {@link ModuleEnvironment}.
 * If the type does not belong to the module environment, null is returned.
 */
public static SimpleUri getFullyQualifiedSimpleUriFor(Type type, ModuleEnvironment environment) {
    Class<?> clazz = getRawType(type);
    if (clazz.getClassLoader() == null) {
        // Loaded with the bootstrap class loader, definitely not part of a module
        return null;
    }
    Name moduleProviding = environment.getModuleProviding(clazz);
    if (moduleProviding == null) {
        return null;
    }
    return new SimpleUri(moduleProviding, clazz.getTypeName());
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) Name(org.terasology.gestalt.naming.Name)

Aggregations

Name (org.terasology.gestalt.naming.Name)58 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)15 Module (org.terasology.gestalt.module.Module)14 SimpleUri (org.terasology.engine.core.SimpleUri)13 ModuleManager (org.terasology.engine.core.module.ModuleManager)10 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)7 IOException (java.io.IOException)6 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)6 List (java.util.List)5 GameEngine (org.terasology.engine.core.GameEngine)5 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)5 BlockUri (org.terasology.engine.world.block.BlockUri)5 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)5 UIText (org.terasology.nui.widgets.UIText)5 Map (java.util.Map)4 Set (java.util.Set)4 Config (org.terasology.engine.config.Config)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3