| Total Complexity | 5 | 
| Total Lines | 25 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | package de.pewpewproject.lasertag.lasertaggame.state.synced.implementation; | ||
| 15 | public class SettingsState extends HashMap<String, Object> { | ||
| 16 | |||
| 17 |     public static SettingsState createBaseSettings() { | ||
| 18 | var settings = new SettingsState(); | ||
| 19 | |||
| 20 |         for (var setting : SettingDescription.values()) { | ||
| 21 |             if (setting.getDataType().isEnum()) { | ||
| 22 | settings.put(setting.getName(), ((Enum<?>)setting.getDefaultValue()).name()); | ||
| 23 |             } else { | ||
| 24 | settings.put(setting.getName(), setting.getDefaultValue()); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | return settings; | ||
| 29 | } | ||
| 30 | |||
| 31 |     public String toJson() { | ||
| 32 | return new Gson().toJson(this); | ||
| 33 | } | ||
| 34 | |||
| 35 |     public static SettingsState fromJson(String json) { | ||
| 36 | return new GsonBuilder() | ||
| 37 | .setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE) | ||
| 38 | .create() | ||
| 39 | .fromJson(json, SettingsState.class); | ||
| 40 | } | ||
| 42 |