Search in sources :

Example 16 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class BindsSubsystem method addButtonDefaultsFor.

private void addButtonDefaultsFor(Name moduleId, Iterable<Class<?>> classes, BindsConfiguration config) {
    for (Class<?> buttonEvent : classes) {
        if (ButtonEvent.class.isAssignableFrom(buttonEvent)) {
            RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class);
            SimpleUri bindUri = new SimpleUri(moduleId, info.id());
            if (!config.hasBinds(bindUri)) {
                addDefaultBindings(bindUri, buttonEvent, config);
            }
        }
    }
}
Also used : RegisterBindButton(org.terasology.input.RegisterBindButton) SimpleUri(org.terasology.engine.SimpleUri)

Example 17 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class FlexibleConfigImpl method load.

@Override
public void load(Reader reader) {
    try {
        JsonObject jsonObject = new JsonParser().parse(reader).getAsJsonObject();
        for (Map.Entry<String, JsonElement> jsonEntry : jsonObject.entrySet()) {
            if (jsonEntry.getKey().equals(DESCRIPTION_PROPERTY_NAME)) {
                continue;
            }
            SimpleUri id = new SimpleUri(jsonEntry.getKey());
            String valueJson = jsonEntry.getValue().toString();
            temporarilyParkedSettings.put(id, valueJson);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error parsing config file!");
    }
}
Also used : JsonElement(com.google.gson.JsonElement) SimpleUri(org.terasology.engine.SimpleUri) JsonObject(com.google.gson.JsonObject) Map(java.util.Map) JsonParser(com.google.gson.JsonParser)

Example 18 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class FlexibleConfigImpl method save.

@Override
public void save(Writer writer) {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty(DESCRIPTION_PROPERTY_NAME, description);
    for (Map.Entry<SimpleUri, Setting> entry : settings.entrySet()) {
        Setting setting = entry.getValue();
        if (!setting.getValue().equals(setting.getDefaultValue())) {
            jsonObject.add(entry.getKey().toString(), setting.getValueAsJson());
        }
    }
    // Add any temporarily parked setting that hasn't been used in this session of the application.
    for (Map.Entry<SimpleUri, String> entry : temporarilyParkedSettings.entrySet()) {
        jsonObject.addProperty(entry.getKey().toString(), entry.getValue());
    }
    gson.toJson(jsonObject, writer);
}
Also used : SimpleUri(org.terasology.engine.SimpleUri) JsonObject(com.google.gson.JsonObject) Map(java.util.Map)

Example 19 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class FlexibleConfigManagerImpl method loadAllConfigs.

@Override
public void loadAllConfigs() {
    for (Entry<SimpleUri, FlexibleConfig> entry : flexibleConfigs.entrySet()) {
        SimpleUri flexibleConfigId = entry.getKey();
        FlexibleConfig flexibleConfig = entry.getValue();
        Path configPath = getPathForFlexibleConfig(flexibleConfigId);
        if (Files.exists(configPath)) {
            try (Reader reader = Files.newBufferedReader(configPath, TerasologyConstants.CHARSET)) {
                flexibleConfig.load(reader);
            } catch (IOException e) {
                throw new RuntimeException("Exception loading config file for configId " + entry.getKey());
            }
        }
    // else: The config does not exist, so the default values will be used.
    }
}
Also used : Path(java.nio.file.Path) SimpleUri(org.terasology.engine.SimpleUri) Reader(java.io.Reader) IOException(java.io.IOException)

Example 20 with SimpleUri

use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.

the class EntitySystemSetupUtil 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) {
            String componentName = MetadataUtil.getComponentClassName(componentType);
            library.register(new SimpleUri(environment.getModuleProviding(componentType), componentName), componentType);
        }
    }
}
Also used : DoNotAutoRegister(org.terasology.entitySystem.systems.internal.DoNotAutoRegister) SimpleUri(org.terasology.engine.SimpleUri)

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