use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.
the class BindsSubsystem method registerButtonBinds.
private void registerButtonBinds(ModuleEnvironment environment) {
Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindButton.class);
for (Class<?> registerBindClass : classes) {
RegisterBindButton info = registerBindClass.getAnnotation(RegisterBindButton.class);
SimpleUri bindUri = new SimpleUri(environment.getModuleProviding(registerBindClass), info.id());
if (BindButtonEvent.class.isAssignableFrom(registerBindClass)) {
try {
BindableButton bindButton = registerBindButton(bindUri, info.description(), (BindButtonEvent) registerBindClass.newInstance());
bindButton.setMode(info.mode());
bindButton.setRepeating(info.repeating());
bindsConfiguration.getBinds(bindUri).stream().filter(input -> input != null).forEach(input -> linkBindButtonToInput(input, bindUri));
logger.debug("Registered button bind: {}", bindUri);
} catch (InstantiationException | IllegalAccessException e) {
logger.error("Failed to register button bind \"{}\"", e);
}
} else {
logger.error("Failed to register button bind \"{}\", does not extend BindButtonEvent", bindUri);
}
}
}
use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.
the class BindsSubsystem method registerRealAxisBinds.
private void registerRealAxisBinds(ModuleEnvironment environment) {
Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class);
for (Class<?> registerBindClass : classes) {
RegisterRealBindAxis info = registerBindClass.getAnnotation(RegisterRealBindAxis.class);
Name moduleId = environment.getModuleProviding(registerBindClass);
SimpleUri id = new SimpleUri(moduleId, info.id());
if (BindAxisEvent.class.isAssignableFrom(registerBindClass)) {
try {
BindAxisEvent instance = (BindAxisEvent) registerBindClass.newInstance();
BindableAxis bindAxis = registerRealBindAxis(id.toString(), instance);
bindAxis.setSendEventMode(info.eventMode());
for (Input input : bindsConfiguration.getBinds(id)) {
linkAxisToInput(input, id);
}
logger.debug("Registered axis bind: {}", id);
} catch (InstantiationException | IllegalAccessException e) {
logger.error("Failed to register axis bind \"{}\"", id, e);
}
} else {
logger.error("Failed to register axis bind \"{}\", does not extend BindAxisEvent", id);
}
}
}
use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.
the class StateHeadlessSetup method createGameManifest.
public GameManifest createGameManifest() {
GameManifest gameManifest = new GameManifest();
Config config = context.get(Config.class);
ModuleManager moduleManager = context.get(ModuleManager.class);
for (Name moduleName : config.getDefaultModSelection().listModules()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
if (module != null) {
gameManifest.addModule(module.getId(), module.getVersion());
}
}
WorldGenerationConfig worldGenConfig = config.getWorldGeneration();
// If no valid default world generator set then try to find one - no option to pick one manually in headless
if (!worldGenConfig.getDefaultGenerator().isValid()) {
// find the first gameplay module that is available, it should have a preferred world gen
for (Name moduleName : config.getDefaultModSelection().listModules()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
if (StandardModuleExtension.isGameplayModule(module)) {
SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
worldGenConfig.setDefaultGenerator(defaultWorldGenerator);
break;
}
}
}
SimpleUri worldGeneratorUri = worldGenConfig.getDefaultGenerator();
gameManifest.setTitle(worldGenConfig.getWorldTitle());
gameManifest.setSeed(worldGenConfig.getDefaultSeed());
WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * 0.025f), worldGeneratorUri);
gameManifest.addWorld(worldInfo);
return gameManifest;
}
use of org.terasology.engine.SimpleUri 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);
}
use of org.terasology.engine.SimpleUri 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());
SimpleUri projUri = new SimpleUri(urn.getModuleName(), projName);
TranslationData data = new TranslationData(projUri, 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;
}
Aggregations