Search in sources :

Example 51 with SimpleUri

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);
        }
    }
}
Also used : BindsConfiguration(org.terasology.config.facade.BindsConfiguration) EngineSubsystem(org.terasology.engine.subsystem.EngineSubsystem) DependencyResolver(org.terasology.module.DependencyResolver) ControllerInput(org.terasology.input.ControllerInput) LoggerFactory(org.slf4j.LoggerFactory) Config(org.terasology.config.Config) RegisterBindAxis(org.terasology.input.RegisterBindAxis) FromModule(org.terasology.module.predicates.FromModule) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Lists(com.google.common.collect.Lists) ButtonEvent(org.terasology.input.events.ButtonEvent) ResolutionResult(org.terasology.module.ResolutionResult) Map(java.util.Map) Input(org.terasology.input.Input) BindableRealAxis(org.terasology.input.internal.BindableRealAxis) SimpleUri(org.terasology.engine.SimpleUri) MouseInput(org.terasology.input.MouseInput) BindAxisEvent(org.terasology.input.BindAxisEvent) BindableButton(org.terasology.input.BindableButton) AxisEvent(org.terasology.input.events.AxisEvent) AbstractBindableAxis(org.terasology.input.internal.AbstractBindableAxis) Name(org.terasology.naming.Name) ModuleManager(org.terasology.engine.module.ModuleManager) InputType(org.terasology.input.InputType) Context(org.terasology.context.Context) Logger(org.slf4j.Logger) BindableAxis(org.terasology.input.BindableAxis) Collection(java.util.Collection) ModuleEnvironment(org.terasology.module.ModuleEnvironment) BindableAxisImpl(org.terasology.input.internal.BindableAxisImpl) Maps(com.google.common.collect.Maps) List(java.util.List) BindsConfig(org.terasology.config.BindsConfig) DefaultBinding(org.terasology.input.DefaultBinding) RegisterBindButton(org.terasology.input.RegisterBindButton) BindButtonEvent(org.terasology.input.BindButtonEvent) Annotation(java.lang.annotation.Annotation) RegisterRealBindAxis(org.terasology.input.RegisterRealBindAxis) BindableButtonImpl(org.terasology.input.internal.BindableButtonImpl) BindableButton(org.terasology.input.BindableButton) RegisterBindButton(org.terasology.input.RegisterBindButton) SimpleUri(org.terasology.engine.SimpleUri)

Example 52 with SimpleUri

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);
        }
    }
}
Also used : RegisterRealBindAxis(org.terasology.input.RegisterRealBindAxis) ControllerInput(org.terasology.input.ControllerInput) Input(org.terasology.input.Input) MouseInput(org.terasology.input.MouseInput) SimpleUri(org.terasology.engine.SimpleUri) BindAxisEvent(org.terasology.input.BindAxisEvent) AbstractBindableAxis(org.terasology.input.internal.AbstractBindableAxis) BindableAxis(org.terasology.input.BindableAxis) Name(org.terasology.naming.Name)

Example 53 with SimpleUri

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;
}
Also used : GameManifest(org.terasology.game.GameManifest) Config(org.terasology.config.Config) WorldGenerationConfig(org.terasology.config.WorldGenerationConfig) SimpleUri(org.terasology.engine.SimpleUri) WorldInfo(org.terasology.world.internal.WorldInfo) ModuleManager(org.terasology.engine.module.ModuleManager) Module(org.terasology.module.Module) WorldGenerationConfig(org.terasology.config.WorldGenerationConfig) Name(org.terasology.naming.Name)

Example 54 with SimpleUri

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

Example 55 with SimpleUri

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;
}
Also used : Locale(java.util.Locale) InputStreamReader(java.io.InputStreamReader) AssetDataFile(org.terasology.assets.format.AssetDataFile) SimpleUri(org.terasology.engine.SimpleUri) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) Name(org.terasology.naming.Name)

Aggregations

SimpleUri (org.terasology.engine.SimpleUri)71 Test (org.junit.Test)18 Map (java.util.Map)10 Name (org.terasology.naming.Name)9 ResourceUrn (org.terasology.assets.ResourceUrn)7 DefaultClassMetadata (org.terasology.reflection.metadata.DefaultClassMetadata)7 Config (org.terasology.config.Config)6 Input (org.terasology.input.Input)6 FBO (org.terasology.rendering.opengl.FBO)6 ModuleManager (org.terasology.engine.module.ModuleManager)5 Command (org.terasology.logic.console.commandSystem.annotations.Command)5 ModuleEnvironment (org.terasology.module.ModuleEnvironment)5 List (java.util.List)4 DependencyResolver (org.terasology.module.DependencyResolver)4 ResolutionResult (org.terasology.module.ResolutionResult)4 UILabel (org.terasology.rendering.nui.widgets.UILabel)4 Lists (com.google.common.collect.Lists)3 IOException (java.io.IOException)3 Type (java.lang.reflect.Type)3 Locale (java.util.Locale)3