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;
}
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);
}
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());
}
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);
}
}
}
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));
}
Aggregations