Search in sources :

Example 31 with Name

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

the class TranslationFormat method load.

@Override
public TranslationData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    if (inputs.size() != 1) {
        throw new IOException("Failed to load translation data '" + urn + "': " + inputs);
    }
    AssetDataFile file = inputs.get(0);
    Locale locale = localeFromFilename(file.getFilename());
    Name projName = basenameFromFilename(file.getFilename());
    ResourceUrn projUrn = new ResourceUrn(urn.getModuleName(), projName);
    TranslationData data = new TranslationData(projUrn, locale);
    try (InputStreamReader isr = new InputStreamReader(file.openStream(), Charsets.UTF_8)) {
        Map<String, String> entry = gson.fromJson(isr, MAP_TOKEN.getType());
        data.addAll(entry);
    } catch (JsonParseException e) {
        throw new IOException("Could not parse file '" + file + "'", e);
    }
    return data;
}
Also used : Locale(java.util.Locale) InputStreamReader(java.io.InputStreamReader) AssetDataFile(org.terasology.gestalt.assets.format.AssetDataFile) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) JsonParseException(com.google.gson.JsonParseException) Name(org.terasology.gestalt.naming.Name)

Example 32 with Name

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

the class ModuleDownloadListGeneratorTest method buildSimpleModule.

private Module buildSimpleModule(String id, String version) {
    ModuleMetadata metadata = new ModuleMetadata();
    metadata.setId(new Name(id));
    if (version != null) {
        metadata.setVersion(new Version(version));
    }
    return new Module(metadata, new EmptyFileSource(), Collections.emptyList(), new Reflections(), (c) -> false);
}
Also used : Version(org.terasology.gestalt.naming.Version) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) EmptyFileSource(org.terasology.gestalt.module.resources.EmptyFileSource) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name) Reflections(org.reflections.Reflections)

Example 33 with Name

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

the class TextureUtilTest method testColorTransformedToTextureUri.

@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());
}
Also used : Color(org.terasology.nui.Color) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name) Test(org.junit.jupiter.api.Test)

Example 34 with Name

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

the class EnvironmentSwitchHandler method registerComponents.

private static void registerComponents(ComponentLibrary library, ModuleEnvironment environment) {
    for (Class<? extends Component> componentType : environment.getSubtypesOf(Component.class)) {
        if (componentType.getAnnotation(DoNotAutoRegister.class) == null && !componentType.isInterface() && !Modifier.isAbstract(componentType.getModifiers())) {
            String componentName = MetadataUtil.getComponentClassName(componentType);
            Name componentModuleName = verifyNotNull(environment.getModuleProviding(componentType), "Could not find module for %s %s", componentName, componentType);
            library.register(new ResourceUrn(componentModuleName.toString(), componentName), componentType);
        }
    }
}
Also used : DoNotAutoRegister(org.terasology.engine.entitySystem.systems.internal.DoNotAutoRegister) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name)

Example 35 with Name

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

the class ModuleManager method ensureModulesDependOnEngine.

/**
 * Ensure all modules declare a dependency on the engine module.
 * <p>
 * This is to ensure that the set of modules is a graph with a single root.
 * We need this to ensure the engine is loaded <em>before</em> other modules
 * when things iterate over the module list in dependency order.
 * <p>
 * See <a href="https://github.com/MovingBlocks/Terasology/issues/1450">#1450</a>.
 */
private void ensureModulesDependOnEngine() {
    DependencyInfo engineDep = new DependencyInfo();
    engineDep.setId(engineModule.getId());
    engineDep.setMinVersion(engineModule.getVersion());
    Set<Name> engineModules = Sets.newHashSet(engineModule.getId());
    engineModules.addAll(engineModule.getMetadata().getDependencies().stream().map(DependencyInfo::getId).collect(Collectors.toList()));
    registry.stream().filter(mod -> !engineModules.contains(mod.getId())).forEach(mod -> mod.getMetadata().getDependencies().add(engineDep));
}
Also used : Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) SystemConfig(org.terasology.engine.config.SystemConfig) PermissionProviderFactory(org.terasology.gestalt.module.sandbox.PermissionProviderFactory) Reflections(org.reflections.Reflections) Jvm(org.terasology.engine.utilities.Jvm) StandardPermissionProviderFactory(org.terasology.gestalt.module.sandbox.StandardPermissionProviderFactory) PropertyPermission(java.util.PropertyPermission) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) Map(java.util.Map) ModuleMetadataLoader(org.terasology.gestalt.module.ModuleMetadataLoader) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) JarURLConnection(java.net.JarURLConnection) Path(java.nio.file.Path) Policy(java.security.Policy) ReflectPermission(java.lang.reflect.ReflectPermission) Scanner(org.reflections.scanners.Scanner) Module(org.terasology.gestalt.module.Module) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Collection(java.util.Collection) TableModuleRegistry(org.terasology.gestalt.module.TableModuleRegistry) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ClasspathHelper(org.reflections.util.ClasspathHelper) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) List(java.util.List) ModuleSecurityPolicy(org.terasology.gestalt.module.sandbox.ModuleSecurityPolicy) Name(org.terasology.gestalt.naming.Name) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) APIScanner(org.terasology.gestalt.module.sandbox.APIScanner) WarnOnlyProviderFactory(org.terasology.gestalt.module.sandbox.WarnOnlyProviderFactory) HashSet(java.util.HashSet) ModuleRegistry(org.terasology.gestalt.module.ModuleRegistry) ModuleSecurityManager(org.terasology.gestalt.module.sandbox.ModuleSecurityManager) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Logger(org.slf4j.Logger) PermissionProvider(org.terasology.gestalt.module.sandbox.PermissionProvider) PermissionSet(org.terasology.gestalt.module.sandbox.PermissionSet) IOException(java.io.IOException) File(java.io.File) Config(org.terasology.engine.config.Config) ModulePathScanner(org.terasology.gestalt.module.ModulePathScanner) ModuleMetadataJsonAdapter(org.terasology.gestalt.module.ModuleMetadataJsonAdapter) Collections(java.util.Collections) PathManager(org.terasology.engine.core.PathManager) ModuleFactory(org.terasology.gestalt.module.ModuleFactory) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) 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