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);
}
}
}
}
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!");
}
}
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);
}
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.
}
}
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);
}
}
}
Aggregations