feature(autoconfig): migrate SystemConfig (#4235)
parent
da784f037f
commit
717605a16d
|
@ -1,18 +1,5 @@
|
|||
/*
|
||||
* Copyright 2019 MovingBlocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package org.terasology.config.flexible.internal;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -28,6 +15,7 @@ import org.terasology.utilities.random.FastRandom;
|
|||
import org.terasology.utilities.random.Random;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
@ -37,7 +25,7 @@ public class SettingImplTest {
|
|||
private static final SimpleUri SETTING_ID = new SimpleUri("engine-tests:TestSetting");
|
||||
|
||||
@Nested
|
||||
public class SetValue {
|
||||
class SetValue {
|
||||
private Setting<Integer> setting;
|
||||
|
||||
private int eventResult;
|
||||
|
@ -45,9 +33,9 @@ public class SettingImplTest {
|
|||
@BeforeEach
|
||||
public void setUp() {
|
||||
setting = new SettingImpl<>(
|
||||
TypeInfo.of(Integer.class), 50,
|
||||
TypeInfo.of(Integer.class), 50,
|
||||
new NumberRangeConstraint<>(0, 100, false, false),
|
||||
"", "");
|
||||
"", "", Optional::empty);
|
||||
|
||||
eventResult = -1;
|
||||
|
||||
|
@ -55,14 +43,14 @@ public class SettingImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSetsValue() {
|
||||
void testSetsValue() {
|
||||
assertTrue(setting.set(25));
|
||||
|
||||
assertEquals(25, eventResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotSetValue() {
|
||||
void testDoesNotSetValue() {
|
||||
assertFalse(setting.set(101));
|
||||
|
||||
assertEquals(-1, eventResult);
|
||||
|
@ -70,7 +58,47 @@ public class SettingImplTest {
|
|||
}
|
||||
|
||||
@Nested
|
||||
public class Subscribers {
|
||||
class Override {
|
||||
private static final int TEST_CONFIG_OVERRIDE_VALUE = 75;
|
||||
private Integer override;
|
||||
private Setting<Integer> setting;
|
||||
|
||||
private int eventResult;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
setting = new SettingImpl<>(
|
||||
TypeInfo.of(Integer.class), 50,
|
||||
new NumberRangeConstraint<>(0, 100, false, false),
|
||||
"", "", () -> Optional.ofNullable(override));
|
||||
|
||||
eventResult = -1;
|
||||
|
||||
setting.subscribe((setting1, oldValue) -> eventResult = setting1.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSystemPropertyValue() {
|
||||
override = TEST_CONFIG_OVERRIDE_VALUE;
|
||||
assertEquals(75, setting.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSystemPropertyValueNotPresent() {
|
||||
override = null;
|
||||
assertEquals(50, setting.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoesNotSetValue() {
|
||||
assertFalse(setting.set(101));
|
||||
|
||||
assertEquals(-1, eventResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class Subscribers {
|
||||
private Setting<Integer> setting;
|
||||
|
||||
private SettingChangeListener<Integer> listener;
|
||||
|
@ -80,9 +108,9 @@ public class SettingImplTest {
|
|||
@BeforeEach
|
||||
public void setUp() {
|
||||
setting = new SettingImpl<>(
|
||||
TypeInfo.of(Integer.class), 50,
|
||||
TypeInfo.of(Integer.class), 50,
|
||||
new NumberRangeConstraint<>(0, 100, false, false),
|
||||
"", "");
|
||||
"", "", Optional::empty);
|
||||
|
||||
eventCallCount = 0;
|
||||
|
||||
|
@ -90,7 +118,7 @@ public class SettingImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testHasSubscribers() {
|
||||
void testHasSubscribers() {
|
||||
setting.subscribe(listener);
|
||||
|
||||
assertTrue(setting.hasSubscribers());
|
||||
|
@ -101,7 +129,7 @@ public class SettingImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSetEventCall() {
|
||||
void testSetEventCall() {
|
||||
setting.subscribe(listener);
|
||||
|
||||
Random random = new FastRandom();
|
||||
|
@ -118,7 +146,7 @@ public class SettingImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSubscribe() {
|
||||
void testSubscribe() {
|
||||
final int subscriberCount = 10;
|
||||
|
||||
for (int i = 0; i < subscriberCount; i++) {
|
||||
|
@ -131,7 +159,7 @@ public class SettingImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testUnsubscribe() {
|
||||
void testUnsubscribe() {
|
||||
int subscriberCount = 10;
|
||||
|
||||
List<SettingChangeListener<Integer>> listeners = Lists.newArrayListWithCapacity(subscriberCount);
|
||||
|
|
|
@ -97,10 +97,6 @@ public final class Config {
|
|||
return config.getPlayer();
|
||||
}
|
||||
|
||||
public SystemConfig getSystem() {
|
||||
return config.getSystem();
|
||||
}
|
||||
|
||||
public RenderingConfig getRendering() {
|
||||
return config.getRendering();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Map;
|
|||
* and loaded in a JSON format.
|
||||
*/
|
||||
public final class RootConfig {
|
||||
private SystemConfig system = new SystemConfig();
|
||||
private PlayerConfig player = new PlayerConfig();
|
||||
private PermissionConfig permission = new PermissionConfig();
|
||||
private InputConfig input = new InputConfig();
|
||||
|
@ -75,10 +74,6 @@ public final class RootConfig {
|
|||
return player;
|
||||
}
|
||||
|
||||
public SystemConfig getSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
public RenderingConfig getRendering() {
|
||||
return rendering;
|
||||
}
|
||||
|
|
|
@ -1,114 +1,80 @@
|
|||
/*
|
||||
* Copyright 2013 MovingBlocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.config;
|
||||
|
||||
import org.terasology.config.flexible.AutoConfig;
|
||||
import org.terasology.config.flexible.Setting;
|
||||
import org.terasology.config.flexible.constraints.NumberRangeConstraint;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Locale.Category;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SystemConfig {
|
||||
import static org.terasology.config.flexible.SettingArgument.constraint;
|
||||
import static org.terasology.config.flexible.SettingArgument.defaultValue;
|
||||
import static org.terasology.config.flexible.SettingArgument.override;
|
||||
import static org.terasology.config.flexible.SettingArgument.type;
|
||||
|
||||
public class SystemConfig extends AutoConfig {
|
||||
public static final String SAVED_GAMES_ENABLED_PROPERTY = "org.terasology.savedGamesEnabled";
|
||||
public static final String PERMISSIVE_SECURITY_ENABLED_PROPERTY = "org.terasology.permissiveSecurityEnabled";
|
||||
|
||||
private long dayNightLengthInMs;
|
||||
private int maxThreads;
|
||||
private int maxSecondsBetweenSaves;
|
||||
private int maxUnloadedChunksPercentageTillSave;
|
||||
private boolean debugEnabled;
|
||||
private boolean monitoringEnabled;
|
||||
private boolean writeSaveGamesEnabled;
|
||||
private long chunkGenerationFailTimeoutInMs;
|
||||
private String locale;
|
||||
public final Setting<Long> dayNightLengthInMs = setting(
|
||||
type(Long.class),
|
||||
defaultValue(1800000L),
|
||||
constraint(new NumberRangeConstraint<>(0L, Long.MAX_VALUE, false, false))
|
||||
);
|
||||
|
||||
public long getDayNightLengthInMs() {
|
||||
return dayNightLengthInMs;
|
||||
}
|
||||
public final Setting<Integer> maxThreads = setting(
|
||||
type(Integer.class),
|
||||
defaultValue(Runtime.getRuntime().availableProcessors() - 1),
|
||||
constraint(new NumberRangeConstraint<>(0, Integer.MAX_VALUE, false, false))
|
||||
);
|
||||
|
||||
public void setDayNightLengthInMs(long dayNightLengthInMs) {
|
||||
this.dayNightLengthInMs = dayNightLengthInMs;
|
||||
}
|
||||
public final Setting<Integer> maxSecondsBetweenSaves = setting(
|
||||
type(Integer.class),
|
||||
defaultValue(60),
|
||||
constraint(new NumberRangeConstraint<>(0, Integer.MAX_VALUE, false, false))
|
||||
);
|
||||
|
||||
public int getMaxThreads() {
|
||||
return maxThreads;
|
||||
}
|
||||
public final Setting<Integer> maxUnloadedChunksPercentageTillSave = setting(
|
||||
type(Integer.class),
|
||||
defaultValue(40),
|
||||
constraint(new NumberRangeConstraint<>(0, 100, false, false))
|
||||
);
|
||||
|
||||
public void setMaxThreads(int maxThreads) {
|
||||
this.maxThreads = maxThreads;
|
||||
}
|
||||
public final Setting<Boolean> debugEnabled = setting(
|
||||
type(Boolean.class),
|
||||
defaultValue(false)
|
||||
);
|
||||
|
||||
public int getMaxSecondsBetweenSaves() {
|
||||
return maxSecondsBetweenSaves;
|
||||
}
|
||||
public final Setting<Boolean> monitoringEnabled = setting(
|
||||
type(Boolean.class),
|
||||
defaultValue(false)
|
||||
);
|
||||
|
||||
public void setMaxSecondsBetweenSaves(int maxSecondsBetweenSaves) {
|
||||
this.maxSecondsBetweenSaves = maxSecondsBetweenSaves;
|
||||
}
|
||||
public final Setting<Boolean> writeSaveGamesEnabled = setting(
|
||||
type(Boolean.class),
|
||||
defaultValue(true),
|
||||
override(() -> Optional.ofNullable(
|
||||
System.getProperty(SAVED_GAMES_ENABLED_PROPERTY))
|
||||
.map(Boolean::parseBoolean))
|
||||
);
|
||||
|
||||
public int getMaxUnloadedChunksPercentageTillSave() {
|
||||
return maxUnloadedChunksPercentageTillSave;
|
||||
}
|
||||
public final Setting<Long> chunkGenerationFailTimeoutInMs = setting(
|
||||
type(Long.class),
|
||||
defaultValue(1800000L),
|
||||
constraint(new NumberRangeConstraint<>(0L, Long.MAX_VALUE, false, false))
|
||||
);
|
||||
|
||||
public void setMaxUnloadedChunksPercentageTillSave(int maxUnloadedChunksPercentageTillSave) {
|
||||
this.maxUnloadedChunksPercentageTillSave = maxUnloadedChunksPercentageTillSave;
|
||||
}
|
||||
public final Setting<Locale> locale = setting(
|
||||
type(Locale.class),
|
||||
defaultValue(Locale.getDefault(Category.DISPLAY))
|
||||
);
|
||||
|
||||
public boolean isDebugEnabled() {
|
||||
return debugEnabled;
|
||||
}
|
||||
|
||||
public void setDebugEnabled(boolean debugEnabled) {
|
||||
this.debugEnabled = debugEnabled;
|
||||
}
|
||||
|
||||
public boolean isMonitoringEnabled() {
|
||||
return monitoringEnabled;
|
||||
}
|
||||
|
||||
public void setMonitoringEnabled(boolean monitoringEnabled) {
|
||||
this.monitoringEnabled = monitoringEnabled;
|
||||
}
|
||||
|
||||
public boolean isWriteSaveGamesEnabled() {
|
||||
String property = System.getProperty(SAVED_GAMES_ENABLED_PROPERTY);
|
||||
if (property != null) {
|
||||
return Boolean.parseBoolean(property);
|
||||
}
|
||||
return writeSaveGamesEnabled;
|
||||
}
|
||||
|
||||
public void setWriteSaveGamesEnabled(boolean writeSaveGamesEnabled) {
|
||||
this.writeSaveGamesEnabled = writeSaveGamesEnabled;
|
||||
}
|
||||
|
||||
public long getChunkGenerationFailTimeoutInMs() {
|
||||
return chunkGenerationFailTimeoutInMs;
|
||||
}
|
||||
|
||||
public void setChunkGenerationFailTimeoutInMs(long chunkGenerationFailTimeoutInMs) {
|
||||
this.chunkGenerationFailTimeoutInMs = chunkGenerationFailTimeoutInMs;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
if (locale == null) {
|
||||
setLocale(Locale.getDefault(Category.DISPLAY));
|
||||
}
|
||||
return Locale.forLanguageTag(locale);
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale.toLanguageTag();
|
||||
@Override
|
||||
public String getName() {
|
||||
return "${engine:menu#system-settings-title}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,14 @@
|
|||
/*
|
||||
* Copyright 2019 MovingBlocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package org.terasology.config.flexible;
|
||||
|
||||
import org.terasology.config.flexible.constraints.SettingConstraint;
|
||||
import org.terasology.config.flexible.internal.SettingBuilder;
|
||||
import org.terasology.reflection.TypeInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SettingArgument<P, V> {
|
||||
private P argument;
|
||||
|
@ -55,6 +44,11 @@ public class SettingArgument<P, V> {
|
|||
return new SettingArgument<>(description, SettingBuilder::description);
|
||||
}
|
||||
|
||||
public static <V> SettingArgument<Supplier<Optional<V>>, V> override(Supplier<Optional<V>> overrideProvider) {
|
||||
return new SettingArgument<>(overrideProvider, SettingBuilder::override);
|
||||
}
|
||||
|
||||
|
||||
void setInBuilder(SettingBuilder<V> builder) {
|
||||
setter.accept(builder, argument);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,14 @@
|
|||
/*
|
||||
* Copyright 2019 MovingBlocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package org.terasology.config.flexible.internal;
|
||||
|
||||
import org.terasology.config.flexible.Setting;
|
||||
import org.terasology.config.flexible.constraints.SettingConstraint;
|
||||
import org.terasology.reflection.TypeInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A builder for creating a {@link Setting} storing values of type {@link T}.
|
||||
*
|
||||
|
@ -66,8 +56,14 @@ public interface SettingBuilder<T> {
|
|||
SettingBuilder<T> description(String description);
|
||||
|
||||
/**
|
||||
* Builds the {@link Setting} with the components that have already been specified and
|
||||
* returns it.
|
||||
* Specfies the override of the {@link Setting} being created.
|
||||
* @param overrideProvider The Supplier which provide override for settings value if exists.
|
||||
* @return This builder object.
|
||||
*/
|
||||
SettingBuilder<T> override(Supplier<Optional<T>> overrideProvider);
|
||||
|
||||
/**
|
||||
* Builds the {@link Setting} with the components that have already been specified and returns it.
|
||||
*/
|
||||
Setting<T> build();
|
||||
}
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
/*
|
||||
* Copyright 2019 MovingBlocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package org.terasology.config.flexible.internal;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
@ -24,7 +11,9 @@ import org.terasology.config.flexible.SettingChangeListener;
|
|||
import org.terasology.config.flexible.constraints.SettingConstraint;
|
||||
import org.terasology.reflection.TypeInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -40,6 +29,8 @@ class SettingImpl<T> implements Setting<T> {
|
|||
private final String humanReadableName;
|
||||
private final String description;
|
||||
|
||||
private final Supplier<Optional<T>> override;
|
||||
|
||||
private final SettingConstraint<T> constraint;
|
||||
private final Set<SettingChangeListener<T>> subscribers = Sets.newHashSet();
|
||||
|
||||
|
@ -49,24 +40,26 @@ class SettingImpl<T> implements Setting<T> {
|
|||
* Creates a new {@link SettingImpl} with the given id, default value and constraint.
|
||||
*
|
||||
* @param valueType The {@link TypeInfo} describing the type of values t
|
||||
* @param defaultValue The default value of the setting.
|
||||
* @param constraint The constraint that the setting values must satisfy.
|
||||
* @param defaultValue The default value of the setting.
|
||||
* @param constraint The constraint that the setting values must satisfy.
|
||||
* @param humanReadableName The human readable name of the setting.
|
||||
* @param description A description of the setting.
|
||||
* @param description A description of the setting.
|
||||
* @param override A override provider of the setting.
|
||||
*/
|
||||
SettingImpl(TypeInfo<T> valueType, T defaultValue, SettingConstraint<T> constraint,
|
||||
String humanReadableName, String description) {
|
||||
String humanReadableName, String description, Supplier<Optional<T>> override) {
|
||||
this.valueType = valueType;
|
||||
this.humanReadableName = humanReadableName;
|
||||
this.description = description;
|
||||
|
||||
this.constraint = constraint;
|
||||
this.override = override;
|
||||
|
||||
Preconditions.checkNotNull(defaultValue, "The default value for a Setting cannot be null.");
|
||||
|
||||
if (isConstraintUnsatisfiedBy(defaultValue)) {
|
||||
throw new IllegalArgumentException("The default value must be a valid value. " +
|
||||
"Check the logs for more information.");
|
||||
"Check the logs for more information.");
|
||||
}
|
||||
|
||||
this.defaultValue = defaultValue;
|
||||
|
@ -137,13 +130,19 @@ class SettingImpl<T> implements Setting<T> {
|
|||
|
||||
@Override
|
||||
public T get() {
|
||||
return value;
|
||||
return override.get().orElse(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(T newValue) {
|
||||
Preconditions.checkNotNull(newValue, "The value of a setting cannot be null.");
|
||||
|
||||
if (override.get().isPresent()) {
|
||||
LOGGER.warn("An attempt was made to overwrite the value specified in the System property." +
|
||||
" This will give nothing while the System Property value is supplied");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isConstraintUnsatisfiedBy(newValue)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,31 +1,22 @@
|
|||
/*
|
||||
* Copyright 2019 MovingBlocks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
package org.terasology.config.flexible.internal;
|
||||
|
||||
import org.terasology.config.flexible.Setting;
|
||||
import org.terasology.config.flexible.constraints.SettingConstraint;
|
||||
import org.terasology.reflection.TypeInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SettingImplBuilder<T> implements SettingBuilder<T> {
|
||||
private T defaultValue;
|
||||
private SettingConstraint<T> constraint;
|
||||
private String humanReadableName = "";
|
||||
private String description = "";
|
||||
private TypeInfo<T> valueType;
|
||||
|
||||
private Supplier<Optional<T>> override = Optional::empty;
|
||||
|
||||
@Override
|
||||
public SettingBuilder<T> valueType(TypeInfo<T> valueType) {
|
||||
this.valueType = valueType;
|
||||
|
@ -59,10 +50,17 @@ public class SettingImplBuilder<T> implements SettingBuilder<T> {
|
|||
this.description = description;
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SettingBuilder<T> override(Supplier<Optional<T>> overrideProvider) {
|
||||
this.override = overrideProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Setting<T> build() {
|
||||
return new SettingImpl<>(valueType, defaultValue, constraint, humanReadableName, description);
|
||||
return new SettingImpl<>(valueType, defaultValue, constraint, humanReadableName, description, override);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.google.common.collect.Queues;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.context.Context;
|
||||
import org.terasology.crashreporter.CrashReporter;
|
||||
import org.terasology.engine.EngineTime;
|
||||
|
@ -76,6 +77,7 @@ public class StateLoading implements GameState {
|
|||
private LoadingScreen loadingScreen;
|
||||
|
||||
private Config config;
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
private int progress;
|
||||
private int maxProgress;
|
||||
|
@ -108,6 +110,7 @@ public class StateLoading implements GameState {
|
|||
CoreRegistry.setContext(context);
|
||||
|
||||
config = context.get(Config.class);
|
||||
systemConfig = context.get(SystemConfig.class);
|
||||
|
||||
this.nuiManager = new NUIManagerInternal((TerasologyCanvasRenderer) context.get(CanvasRenderer.class), context);
|
||||
context.put(NUIManager.class, nuiManager);
|
||||
|
@ -264,7 +267,7 @@ public class StateLoading implements GameState {
|
|||
|
||||
if (chunkGenerationStarted) {
|
||||
long timeSinceLastChunk = time.getRealTimeInMs() - timeLastChunkGenerated;
|
||||
long chunkGenerationTimeout = config.getSystem().getChunkGenerationFailTimeoutInMs();
|
||||
long chunkGenerationTimeout = systemConfig.chunkGenerationFailTimeoutInMs.get();
|
||||
if (timeSinceLastChunk > chunkGenerationTimeout) {
|
||||
String errorMessage = "World generation timed out, check the log for more info";
|
||||
gameEngine.changeState(new StateMainMenu(errorMessage));
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.google.common.collect.Maps;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.context.Context;
|
||||
import org.terasology.engine.ComponentSystemManager;
|
||||
import org.terasology.engine.GameEngine;
|
||||
|
@ -108,7 +109,7 @@ public class InitialiseWorld extends SingleStepLoadProcess {
|
|||
|
||||
// Init. a new world
|
||||
EngineEntityManager entityManager = (EngineEntityManager) context.get(EntityManager.class);
|
||||
boolean writeSaveGamesEnabled = context.get(Config.class).getSystem().isWriteSaveGamesEnabled();
|
||||
boolean writeSaveGamesEnabled = context.get(SystemConfig.class).writeSaveGamesEnabled.get();
|
||||
//Gets save data from a normal save or from a recording if it is a replay
|
||||
Path saveOrRecordingPath = getSaveOrRecordingPath();
|
||||
StorageManager storageManager;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package org.terasology.engine.subsystem.common;
|
||||
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.context.Context;
|
||||
import org.terasology.engine.GameEngine;
|
||||
import org.terasology.engine.subsystem.EngineSubsystem;
|
||||
|
@ -32,7 +33,7 @@ public class MonitoringSubsystem implements EngineSubsystem {
|
|||
|
||||
@Override
|
||||
public void initialise(GameEngine engine, Context rootContext) {
|
||||
if (rootContext.get(Config.class).getSystem().isMonitoringEnabled()) {
|
||||
if (rootContext.get(SystemConfig.class).monitoringEnabled.get()) {
|
||||
advancedMonitor = new AdvancedMonitor();
|
||||
advancedMonitor.setVisible(true);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.assets.ResourceUrn;
|
||||
import org.terasology.assets.management.AssetManager;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.context.Context;
|
||||
import org.terasology.engine.SimpleUri;
|
||||
|
@ -49,7 +48,7 @@ public class TranslationSystemImpl implements TranslationSystem {
|
|||
private final List<Consumer<TranslationProject>> changeListeners = new CopyOnWriteArrayList<>();
|
||||
private final Map<Uri, TranslationProject> projects = new HashMap<>();
|
||||
|
||||
private final SystemConfig config;
|
||||
private final SystemConfig systemConfig;
|
||||
|
||||
private AssetManager assetManager;
|
||||
|
||||
|
@ -58,7 +57,7 @@ public class TranslationSystemImpl implements TranslationSystem {
|
|||
*/
|
||||
public TranslationSystemImpl(Context context) {
|
||||
|
||||
config = context.get(Config.class).getSystem();
|
||||
systemConfig = context.get(SystemConfig.class);
|
||||
assetManager = context.get(AssetManager.class);
|
||||
|
||||
refresh();
|
||||
|
@ -91,7 +90,7 @@ public class TranslationSystemImpl implements TranslationSystem {
|
|||
|
||||
@Override
|
||||
public String translate(String id) {
|
||||
return translate(id, config.getLocale());
|
||||
return translate(id, systemConfig.locale.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.google.common.collect.Streams;
|
|||
import org.joml.Vector3f;
|
||||
import org.terasology.assets.ResourceUrn;
|
||||
import org.terasology.assets.management.AssetManager;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.engine.GameEngine;
|
||||
import org.terasology.engine.SimpleUri;
|
||||
import org.terasology.engine.TerasologyConstants;
|
||||
|
@ -125,7 +125,7 @@ public class CoreCommands extends BaseComponentSystem {
|
|||
private TranslationSystem translationSystem;
|
||||
|
||||
@In
|
||||
private Config config;
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
@In
|
||||
private ModuleManager moduleManager;
|
||||
|
@ -283,7 +283,7 @@ public class CoreCommands extends BaseComponentSystem {
|
|||
|
||||
// Try if language exists
|
||||
if (proj.getAvailableLocales().contains(locale)) {
|
||||
config.getSystem().setLocale(locale);
|
||||
systemConfig.locale.set(locale);
|
||||
nuiManager.invalidate();
|
||||
String nat = translationSystem.translate("${engine:menu#this-language-native}", locale);
|
||||
String eng = translationSystem.translate("${engine:menu#this-language-English}", locale);
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.joml.Vector3i;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.engine.GameEngine;
|
||||
import org.terasology.entitySystem.entity.EntityManager;
|
||||
import org.terasology.entitySystem.entity.EntityRef;
|
||||
|
@ -65,6 +66,9 @@ public class ServerCommands extends BaseComponentSystem {
|
|||
@In
|
||||
private Config config;
|
||||
|
||||
@In
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
@In
|
||||
private GameEngine gameEngine;
|
||||
|
||||
|
@ -192,7 +196,7 @@ public class ServerCommands extends BaseComponentSystem {
|
|||
@Command(shortDescription = "Invalidates the specified chunk and recreates it (requires storage manager disabled)", runOnServer = true)
|
||||
public String reloadChunk(@CommandParam("x") int x, @CommandParam("y") int y, @CommandParam("z") int z) {
|
||||
Vector3i pos = new Vector3i(x, y, z);
|
||||
if (config.getSystem().isWriteSaveGamesEnabled()) {
|
||||
if (systemConfig.writeSaveGamesEnabled.get()) {
|
||||
return "Writing save games is enabled! Invalidating chunk has no effect";
|
||||
}
|
||||
boolean success = chunkProvider.reloadChunk(pos);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package org.terasology.logic.players;
|
||||
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.entitySystem.entity.EntityRef;
|
||||
import org.terasology.entitySystem.event.EventPriority;
|
||||
import org.terasology.entitySystem.event.ReceiveEvent;
|
||||
|
@ -35,6 +36,8 @@ public class DebugControlSystem extends BaseComponentSystem {
|
|||
|
||||
@In
|
||||
private Config config;
|
||||
@In
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
@In
|
||||
private NUIManager nuiManager;
|
||||
|
@ -73,7 +76,7 @@ public class DebugControlSystem extends BaseComponentSystem {
|
|||
*/
|
||||
@ReceiveEvent(components = ClientComponent.class)
|
||||
public void onKeyEvent(KeyEvent event, EntityRef entity) {
|
||||
boolean debugEnabled = config.getSystem().isDebugEnabled();
|
||||
boolean debugEnabled = systemConfig.debugEnabled.get();
|
||||
// Features for debug mode only
|
||||
if (debugEnabled && event.isDown()) {
|
||||
switch (event.getKey().getId()) {
|
||||
|
@ -97,7 +100,7 @@ public class DebugControlSystem extends BaseComponentSystem {
|
|||
|
||||
@ReceiveEvent(components = ClientComponent.class)
|
||||
public void onKeyDown(KeyDownEvent event, EntityRef entity) {
|
||||
boolean debugEnabled = config.getSystem().isDebugEnabled();
|
||||
boolean debugEnabled = systemConfig.debugEnabled.get();
|
||||
// Features for debug mode only
|
||||
if (debugEnabled) {
|
||||
switch (event.getKey().getId()) {
|
||||
|
@ -131,7 +134,7 @@ public class DebugControlSystem extends BaseComponentSystem {
|
|||
event.consume();
|
||||
break;
|
||||
case Keyboard.KeyId.F3:
|
||||
config.getSystem().setDebugEnabled(!config.getSystem().isDebugEnabled());
|
||||
systemConfig.debugEnabled.set(!systemConfig.debugEnabled.get());
|
||||
event.consume();
|
||||
break;
|
||||
case Keyboard.KeyId.F4:
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.joml.Vector3ic;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.config.UniverseConfig;
|
||||
import org.terasology.engine.ComponentSystemManager;
|
||||
import org.terasology.engine.Time;
|
||||
|
@ -98,6 +99,7 @@ public final class ReadWriteStorageManager extends AbstractStorageManager implem
|
|||
private final Lock worldDirectoryWriteLock = worldDirectoryLock.writeLock();
|
||||
private SaveTransaction saveTransaction;
|
||||
private Config config;
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
/**
|
||||
* Time of the next save in the format that {@link System#currentTimeMillis()} returns.
|
||||
|
@ -142,6 +144,7 @@ public final class ReadWriteStorageManager extends AbstractStorageManager implem
|
|||
this.saveTransactionHelper = new SaveTransactionHelper(getStoragePathProvider());
|
||||
this.saveThreadManager = TaskMaster.createFIFOTaskMaster("Saving", 1);
|
||||
this.config = CoreRegistry.get(Config.class);
|
||||
this.systemConfig = CoreRegistry.get((SystemConfig.class));
|
||||
this.entityRefReplacingComponentLibrary = privateEntityManager.getComponentLibrary()
|
||||
.createCopyUsingCopyStrategy(EntityRef.class, new DelayedEntityRefCopyStrategy(this));
|
||||
this.entitySetDeltaRecorder = new EntitySetDeltaRecorder(this.entityRefReplacingComponentLibrary);
|
||||
|
@ -456,7 +459,7 @@ public final class ReadWriteStorageManager extends AbstractStorageManager implem
|
|||
int loadedChunkCount = chunkProvider.getAllChunks().size();
|
||||
double totalChunkCount = unloadedChunkCount + loadedChunkCount;
|
||||
double percentageUnloaded = 100.0 * unloadedChunkCount / totalChunkCount;
|
||||
if (percentageUnloaded >= config.getSystem().getMaxUnloadedChunksPercentageTillSave()) {
|
||||
if (percentageUnloaded >= systemConfig.maxUnloadedChunksPercentageTillSave.get()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -469,7 +472,7 @@ public final class ReadWriteStorageManager extends AbstractStorageManager implem
|
|||
}
|
||||
|
||||
private void scheduleNextAutoSave() {
|
||||
long msBetweenAutoSave = (long) config.getSystem().getMaxSecondsBetweenSaves() * 1000;
|
||||
long msBetweenAutoSave = (long) systemConfig.maxSecondsBetweenSaves.get() * 1000;
|
||||
nextAutoSave = System.currentTimeMillis() + msBetweenAutoSave;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ package org.terasology.rendering.nui.editor.layers;
|
|||
import com.google.common.collect.Lists;
|
||||
import org.terasology.assets.ResourceUrn;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.engine.SimpleUri;
|
||||
import org.terasology.i18n.TranslationProject;
|
||||
import org.terasology.i18n.TranslationSystem;
|
||||
|
@ -30,6 +31,9 @@ public class NUIEditorSettingsScreen extends CoreScreenLayer {
|
|||
@In
|
||||
private Config config;
|
||||
|
||||
@In
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
@In
|
||||
private TranslationSystem translationSystem;
|
||||
|
||||
|
@ -55,7 +59,7 @@ public class NUIEditorSettingsScreen extends CoreScreenLayer {
|
|||
if (config.getNuiEditor().getAlternativeLocale() != null) {
|
||||
alternativeLocale.setSelection(config.getNuiEditor().getAlternativeLocale());
|
||||
} else {
|
||||
alternativeLocale.setSelection(config.getSystem().getLocale());
|
||||
alternativeLocale.setSelection(systemConfig.locale.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package org.terasology.rendering.nui.layers.ingame.metrics;
|
|||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3i;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.engine.Time;
|
||||
import org.terasology.entitySystem.entity.EntityManager;
|
||||
import org.terasology.input.cameraTarget.CameraTargetSystem;
|
||||
|
@ -36,6 +37,9 @@ public class DebugOverlay extends CoreScreenLayer {
|
|||
@In
|
||||
private Config config;
|
||||
|
||||
@In
|
||||
private SystemConfig systemConfig;
|
||||
|
||||
@In
|
||||
private CameraTargetSystem cameraTarget;
|
||||
|
||||
|
@ -64,7 +68,7 @@ public class DebugOverlay extends CoreScreenLayer {
|
|||
bindVisible(new ReadOnlyBinding<Boolean>() {
|
||||
@Override
|
||||
public Boolean get() {
|
||||
return config.getSystem().isDebugEnabled();
|
||||
return systemConfig.debugEnabled.get();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.google.common.collect.Lists;
|
|||
import com.google.common.math.DoubleMath;
|
||||
import org.terasology.assets.ResourceUrn;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.context.Context;
|
||||
import org.terasology.engine.SimpleUri;
|
||||
import org.terasology.i18n.TranslationProject;
|
||||
|
@ -66,6 +67,8 @@ public class PlayerSettingsScreen extends CoreScreenLayer {
|
|||
@In
|
||||
private Config config;
|
||||
@In
|
||||
private SystemConfig systemConfig;
|
||||
@In
|
||||
private TranslationSystem translationSystem;
|
||||
@In
|
||||
private StorageServiceWorker storageService;
|
||||
|
@ -114,7 +117,7 @@ public class PlayerSettingsScreen extends CoreScreenLayer {
|
|||
discordPresence.setChecked(config.getPlayer().isDiscordPresence());
|
||||
}
|
||||
if (language != null) {
|
||||
language.setSelection(config.getSystem().getLocale());
|
||||
language.setSelection(systemConfig.locale.get());
|
||||
}
|
||||
updateImage();
|
||||
}
|
||||
|
@ -326,8 +329,8 @@ public class PlayerSettingsScreen extends CoreScreenLayer {
|
|||
config.getPlayer().setName(nametext.getText().trim());
|
||||
config.getPlayer().setHasEnteredUsername(true);
|
||||
}
|
||||
if (!config.getSystem().getLocale().equals(language.getSelection())) {
|
||||
config.getSystem().setLocale(language.getSelection());
|
||||
if (!systemConfig.locale.get().equals(language.getSelection())) {
|
||||
systemConfig.locale.set(language.getSelection());
|
||||
getManager().invalidate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.terasology.telemetry.metrics;
|
|||
import com.snowplowanalytics.snowplow.tracker.events.Unstructured;
|
||||
import org.terasology.config.Config;
|
||||
import org.terasology.config.PlayerConfig;
|
||||
import org.terasology.config.SystemConfig;
|
||||
import org.terasology.context.Context;
|
||||
import org.terasology.network.NetworkSystem;
|
||||
import org.terasology.registry.CoreRegistry;
|
||||
|
@ -93,7 +94,8 @@ public final class GameConfigurationMetric extends Metric {
|
|||
|
||||
private void fetchConfig() {
|
||||
Config config = context.get(Config.class);
|
||||
language = config.getSystem().getLocale().toString();
|
||||
SystemConfig systemConfig = context.get(SystemConfig.class);
|
||||
language = systemConfig.locale.get().toString();
|
||||
|
||||
PlayerConfig playerConfig = config.getPlayer();
|
||||
playerHeight = playerConfig.getHeight();
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"animate-water": "animate-water",
|
||||
"audio-settings": "audio-settings",
|
||||
"audio-settings-title": "audio-settings-title",
|
||||
"system-settings-title": "system-settings-title",
|
||||
"back": "back",
|
||||
"behavior-editor-assign": "behavior-editor-assign",
|
||||
"behavior-editor-copy": "behavior-editor-copy",
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"animate-water": "Animate Water",
|
||||
"audio-settings": "Audio",
|
||||
"audio-settings-title": "Audio Settings",
|
||||
"system-settings-title": "System Settings",
|
||||
"back": "Back",
|
||||
"behavior-editor-assign": "assign",
|
||||
"behavior-editor-copy": "copy",
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"animate-water": "Водяные волны",
|
||||
"audio-settings": "Аудионастройки",
|
||||
"audio-settings-title": "Аудионастройки",
|
||||
"system-settings-title": "Системные настройки",
|
||||
"back": "Назад",
|
||||
"behavior-editor-assign": "назначить",
|
||||
"behavior-editor-copy": "Копировать",
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
{
|
||||
"system": {
|
||||
"dayNightLengthInMs": 1800000,
|
||||
"maxThreads": 2,
|
||||
"maxSecondsBetweenSaves": 60,
|
||||
"maxUnloadedChunksPercentageTillSave": 40,
|
||||
"debugEnabled": false,
|
||||
"monitoringEnabled": false,
|
||||
"writeSaveGamesEnabled": true,
|
||||
"chunkGenerationFailTimeoutInMs": 120000
|
||||
},
|
||||
"input": {
|
||||
"mouseSensitivity": 0.25,
|
||||
"mouseYAxisInverted": false
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020 The Terasology Foundation
|
||||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.persistence.typeHandling;
|
||||
|
@ -15,6 +15,7 @@ import org.terasology.persistence.typeHandling.coreTypes.CharacterTypeHandler;
|
|||
import org.terasology.persistence.typeHandling.coreTypes.DoubleTypeHandler;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.FloatTypeHandler;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.IntTypeHandler;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.LocaleTypeHandler;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.LongTypeHandler;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.NumberTypeHandler;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.RuntimeDelegatingTypeHandler;
|
||||
|
@ -22,8 +23,8 @@ import org.terasology.persistence.typeHandling.coreTypes.StringTypeHandler;
|
|||
import org.terasology.persistence.typeHandling.coreTypes.factories.ArrayTypeHandlerFactory;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.factories.CollectionTypeHandlerFactory;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.factories.EnumTypeHandlerFactory;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.factories.ObjectFieldMapTypeHandlerFactory;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.factories.MapTypeHandlerFactory;
|
||||
import org.terasology.persistence.typeHandling.coreTypes.factories.ObjectFieldMapTypeHandlerFactory;
|
||||
import org.terasology.persistence.typeHandling.reflection.ReflectionsSandbox;
|
||||
import org.terasology.persistence.typeHandling.reflection.SerializationSandbox;
|
||||
import org.terasology.reflection.TypeInfo;
|
||||
|
@ -34,6 +35,7 @@ import org.terasology.reflection.reflect.ConstructorLibrary;
|
|||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -100,6 +102,7 @@ public class TypeHandlerLibrary {
|
|||
typeHandlerLibrary.addTypeHandler(Long.TYPE, new LongTypeHandler());
|
||||
typeHandlerLibrary.addTypeHandler(String.class, new StringTypeHandler());
|
||||
typeHandlerLibrary.addTypeHandler(Number.class, new NumberTypeHandler());
|
||||
typeHandlerLibrary.addTypeHandler(Locale.class, new LocaleTypeHandler());
|
||||
|
||||
typeHandlerLibrary.addTypeHandlerFactory(new ArrayTypeHandlerFactory());
|
||||
typeHandlerLibrary.addTypeHandler(byte[].class, new ByteArrayTypeHandler());
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2021 The Terasology Foundation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.terasology.persistence.typeHandling.coreTypes;
|
||||
|
||||
import org.terasology.persistence.typeHandling.StringRepresentationTypeHandler;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Serializes objects of type {@link java.util.Locale}
|
||||
*/
|
||||
public class LocaleTypeHandler extends StringRepresentationTypeHandler<Locale> {
|
||||
@Override
|
||||
public String getAsString(Locale item) {
|
||||
return item.toLanguageTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getFromString(String representation) {
|
||||
return Locale.forLanguageTag(representation);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue