public void reset() { Config defaultConfig = new Config(new MockContext()); defaultConfig.loadDefaults(); InputConfig defaultInputConfig = defaultConfig.getInput(); setMouseSensitivity(defaultInputConfig.mouseSensitivity); setMouseYAxisInverted(defaultInputConfig.mouseYAxisInverted); }
private boolean validateServerIdentity() { PrivateIdentityCertificate privateCert = config.getSecurity().getServerPrivateCertificate(); PublicIdentityCertificate publicCert = config.getSecurity().getServerPublicCertificate(); if (privateCert == null || publicCert == null) { return false; } // Validate the signature if (!publicCert.verifySelfSigned()) { logger.error("Server signature is not self signed! Generating new server identity."); return false; } return true; }
public void load() { JsonObject jsonConfig = loadDefaultToJson(); Optional<JsonObject> defaultsConfig = loadFileToJson(getOverrideDefaultConfigFile()); if (defaultsConfig.isPresent()) { merge(jsonConfig, defaultsConfig.get()); } Optional<JsonObject> userConfig = loadFileToJson(getConfigFile()); if (userConfig.isPresent()) { merge(jsonConfig, userConfig.get()); } config = createGson().fromJson(jsonConfig, RootConfig.class); }
public void loadDefaults() { JsonObject jsonConfig = loadDefaultToJson(); config = createGson().fromJson(jsonConfig, RootConfig.class); }
@Override protected void setupConfig() { Config config = new Config(context); config.loadDefaults(); context.put(Config.class, config); }
@Override public void preInitialise(Context rootContext) { config = new Config(rootContext); config.load(); FlexibleConfigManager flexibleConfigManager = new FlexibleConfigManagerImpl(); rootContext.put(FlexibleConfigManager.class, flexibleConfigManager); // TODO: Update rendering config description FlexibleConfig renderingFlexibleConfig = new FlexibleConfigImpl("Rendering Config"); flexibleConfigManager.addConfig(new SimpleUri("engine:rendering"), renderingFlexibleConfig); flexibleConfigManager.loadAllConfigs(); // Add settings to RenderingFC String serverPortProperty = System.getProperty(SERVER_PORT_PROPERTY); if (serverPortProperty != null) { try { config.getNetwork().setServerPort(Integer.parseInt(serverPortProperty)); } catch (NumberFormatException e) { logger.error("Failed to set server port to invalid value: {}", serverPortProperty); } } if (Iterables.isEmpty(config.getDefaultModSelection().listModules())) { config.getDefaultModSelection().addModule(TerasologyConstants.CORE_GAMEPLAY_MODULE); } checkServerIdentity(); // TODO: Move to display subsystem logger.info("Video Settings: {}", config.renderConfigAsJson(config.getRendering())); rootContext.put(Config.class, config); //add facades rootContext.put(InputDeviceConfiguration.class, new InputDeviceConfigurationImpl(config)); rootContext.put(BindsConfiguration.class, new BindsConfigurationImpl(config)); }
@Before public void setup() { ContextImpl context = new ContextImpl(); CoreRegistry.setContext(context); // Needed only as long as #1536 is unresolved context.put(Config.class, new Config(new MockContext())); blockManager = Mockito.mock(BlockManager.class); Block air = blockManager.getBlock(BlockManager.AIR_ID); biomeManager = Mockito.mock(BiomeManager.class); extraDataManager = new ExtraBlockDataManager(); Mockito.when(blockManager.getBlock(Matchers.<BlockUri>any())).thenReturn(air); Mockito.when(blockManager.getBlock(Matchers.<String>any())).thenReturn(air); context.put(BlockManager.class, blockManager); }
private void checkServerIdentity() { if (!validateServerIdentity()) { CertificateGenerator generator = new CertificateGenerator(); CertificatePair serverIdentity = generator.generateSelfSigned(); config.getSecurity().setServerCredentials(serverIdentity.getPublicCert(), serverIdentity.getPrivateCert()); config.save(); } }
public StorageServiceWorker(Context context) { this.config = context.get(Config.class); this.storageConfig = this.config.getIdentityStorageService(); this.securityConfig = this.config.getSecurity(); this.translationSystem = context.get(TranslationSystem.class); this.notificationBuffer = new LinkedBlockingDeque<>(); this.conflictingRemoteIdentities = new ArrayDeque<>(); }
@Override public BindsConfig getBindsConfig() { return config.getBinds(); }
/** * Saves this config to the default configuration file */ public void save() { try (BufferedWriter writer = Files.newBufferedWriter(getConfigFile(), TerasologyConstants.CHARSET)) { createGson().toJson(config, writer); } catch (IOException e) { logger.error("Failed to save config", e); } context.get(FlexibleConfigManager.class).saveAllConfigs(); }
@Override public void initialise(GameEngine engine, Context rootContext) { Config config = rootContext.get(Config.class); try { audioManager = new OpenALManager(config.getAudio()); } catch (LWJGLException | OpenALException e) { logger.warn("Could not load OpenAL manager - sound is disabled", e); audioManager = new NullAudioManager(); } rootContext.put(AudioManager.class, audioManager); }
/** * @param generatorUri the generator Uri * @param configs the new config params for the world generator */ public void setModuleConfigs(SimpleUri generatorUri, Map<String, Component> configs) { Gson gson = createGsonForModules(); Map<String, JsonElement> map = Maps.newHashMap(); for (Map.Entry<String, Component> entry : configs.entrySet()) { JsonElement json = gson.toJsonTree(entry.getValue()); map.put(entry.getKey(), json); } config.getModuleConfigs().put(generatorUri, map); }
public String renderConfigAsJson(Object configObject) { return createGson().toJsonTree(configObject).toString(); }
@BeforeClass public static void setUpClass() throws Exception { Config config = new Config(new MockContext()); CoreRegistry.setContext(new ContextImpl()); CoreRegistry.put(Config.class, config); }
config.getSecurity().addIdentity(serverCertificate, identity); config.save();
@Override public void setBinds(BindsConfig other) { config.getBinds().setBinds(other); }
@Override public void initialise() { setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation()); UISlider sound = find("sound", UISlider.class); if (sound != null) { sound.setIncrement(0.05f); sound.setPrecision(2); sound.setMinimum(0); sound.setRange(1.0f); sound.bindValue(BindHelper.bindBeanProperty("soundVolume", config.getAudio(), Float.TYPE)); } UISlider music = find("music", UISlider.class); if (music != null) { music.setIncrement(0.05f); music.setPrecision(2); music.setMinimum(0); music.setRange(1.0f); music.bindValue(BindHelper.bindBeanProperty("musicVolume", config.getAudio(), Float.TYPE)); } WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation()); }
/** * @param uri the uri to look up * @param key the look-up key * @param clazz the class to convert the data to * @return a config component for the given uri and class or <code>null</code> */ public <T extends Component> T getModuleConfig(SimpleUri uri, String key, Class<T> clazz) { Map<String, JsonElement> map = config.getModuleConfigs().get(uri); if (map == null) { return null; } JsonElement element = map.get(key); Gson gson = createGsonForModules(); return gson.fromJson(element, clazz); }
@Test public void testRegionPositions() { CoreRegistry.setContext(new ContextImpl()); CoreRegistry.put(Config.class, new Config(new MockContext())); assertEquals(1, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(0, 0, 0))).length); assertEquals(1, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(31, 63, 31))).length); assertEquals(2, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 31))).length); assertEquals(4, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 32))).length); assertEquals(8, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 64, 32))).length); assertEquals(12, ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(-1, 0, 0), new Vector3i(32, 64, 32))).length); Vector3i[] chunks = ChunkMath.calcChunkPos(Region3i.createFromMinMax(new Vector3i(0, 0, 0), new Vector3i(32, 63, 31))); assertEquals(new Vector3i(0, 0, 0), chunks[0]); assertEquals(new Vector3i(1, 0, 0), chunks[1]); } }