Usage of ExtendedPreferences
This commit is contained in:
@@ -27,7 +27,7 @@ allprojects {
|
|||||||
appName = 'Mindustry'
|
appName = 'Mindustry'
|
||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
roboVMVersion = '2.3.0'
|
roboVMVersion = '2.3.0'
|
||||||
uCoreVersion = '220916714cbe63664c34f95a9dc50a362feca732'
|
uCoreVersion = '33847672a0ea5c215f9799c5a010d60aade3101c'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class Vars{
|
public class Vars{
|
||||||
|
public static final String appName = "Mindustry";
|
||||||
public static final String discordURL = "https://discord.gg/mindustry";
|
public static final String discordURL = "https://discord.gg/mindustry";
|
||||||
public static final String releasesURL = "https://api.github.com/repos/Anuken/Mindustry/releases";
|
public static final String releasesURL = "https://api.github.com/repos/Anuken/Mindustry/releases";
|
||||||
public static final String crashReportURL = "http://mindustry.us.to/report";
|
public static final String crashReportURL = "http://mindustry.us.to/report";
|
||||||
@@ -174,7 +175,7 @@ public class Vars{
|
|||||||
gwt = Gdx.app.getType() == ApplicationType.WebGL;
|
gwt = Gdx.app.getType() == ApplicationType.WebGL;
|
||||||
|
|
||||||
if(!gwt){
|
if(!gwt){
|
||||||
dataDirectory = OS.getAppDataDirectory("Mindustry");
|
dataDirectory = OS.getAppDataDirectory(appName);
|
||||||
customMapDirectory = dataDirectory.child("maps/");
|
customMapDirectory = dataDirectory.child("maps/");
|
||||||
saveDirectory = dataDirectory.child("saves/");
|
saveDirectory = dataDirectory.child("saves/");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class Saves{
|
|||||||
|
|
||||||
public void load(){
|
public void load(){
|
||||||
saves.clear();
|
saves.clear();
|
||||||
IntArray slots = Settings.getBinary("save-slots", IntArray.class, IntArray::new);
|
IntArray slots = Settings.getObject("save-slots", IntArray.class, IntArray::new);
|
||||||
|
|
||||||
for(int i = 0; i < slots.size; i ++){
|
for(int i = 0; i < slots.size; i ++){
|
||||||
int index = slots.get(i);
|
int index = slots.get(i);
|
||||||
@@ -143,7 +143,7 @@ public class Saves{
|
|||||||
IntArray result = new IntArray(saves.size);
|
IntArray result = new IntArray(saves.size);
|
||||||
for(int i = 0; i < saves.size; i++) result.add(saves.get(i).index);
|
for(int i = 0; i < saves.size; i++) result.add(saves.get(i).index);
|
||||||
|
|
||||||
Settings.putBinary("save-slots", result);
|
Settings.putObject("save-slots", result);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class Unlocks{
|
|||||||
public void load(){
|
public void load(){
|
||||||
sets.clear();
|
sets.clear();
|
||||||
|
|
||||||
ObjectMap<String, ObjectMap<ContentType, Array<String>>> result = Settings.getBinary("content-sets", ObjectMap.class, () -> new ObjectMap<>());
|
ObjectMap<String, ObjectMap<ContentType, Array<String>>> result = Settings.getObject("content-sets", ObjectMap.class, () -> new ObjectMap<>());
|
||||||
|
|
||||||
for(Entry<String, ObjectMap<ContentType, Array<String>>> outer : result.entries()){
|
for(Entry<String, ObjectMap<ContentType, Array<String>>> outer : result.entries()){
|
||||||
ContentUnlockSet cset = new ContentUnlockSet();
|
ContentUnlockSet cset = new ContentUnlockSet();
|
||||||
@@ -102,7 +102,7 @@ public class Unlocks{
|
|||||||
output.put(centry.key, write);
|
output.put(centry.key, write);
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.putBinary("content-sets", output);
|
Settings.putObject("content-sets", output);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class BundleLoader{
|
|||||||
|
|
||||||
public static void load(){
|
public static void load(){
|
||||||
Settings.defaults("locale", "default");
|
Settings.defaults("locale", "default");
|
||||||
Settings.load(headless ? "io.anuke.mindustry.server" : "io.anuke.mindustry");
|
Settings.load(Vars.appName, headless ? "io.anuke.mindustry.server" : "io.anuke.mindustry");
|
||||||
loadBundle();
|
loadBundle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class Maps implements Disposable{
|
|||||||
Settings.putString("map-data-" + name, new String(Base64Coder.encode(stream.toByteArray())));
|
Settings.putString("map-data-" + name, new String(Base64Coder.encode(stream.toByteArray())));
|
||||||
if(!customMapNames.contains(name, false)){
|
if(!customMapNames.contains(name, false)){
|
||||||
customMapNames.add(name);
|
customMapNames.add(name);
|
||||||
Settings.putBinary("custom-maps", customMapNames);
|
Settings.putObject("custom-maps", customMapNames);
|
||||||
}
|
}
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ public class Maps implements Disposable{
|
|||||||
} else {
|
} else {
|
||||||
customMapNames.removeValue(map.name, false);
|
customMapNames.removeValue(map.name, false);
|
||||||
Settings.putString("map-data-" + map.name, "");
|
Settings.putString("map-data-" + map.name, "");
|
||||||
Settings.putBinary("custom-maps", customMapNames);
|
Settings.putObject("custom-maps", customMapNames);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ public class Maps implements Disposable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
customMapNames = Settings.getBinary("custom-maps", Array.class, () -> new Array<>());
|
customMapNames = Settings.getObject("custom-maps", Array.class, () -> new Array<>());
|
||||||
|
|
||||||
for(String name : customMapNames){
|
for(String name : customMapNames){
|
||||||
try{
|
try{
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ public class Sectors{
|
|||||||
}
|
}
|
||||||
grid.clear();
|
grid.clear();
|
||||||
|
|
||||||
Array<Sector> out = Settings.getBinary("sectors", Array.class, () -> new Array<>());
|
Array<Sector> out = Settings.getObject("sectors", Array.class, () -> new Array<>());
|
||||||
|
|
||||||
for(Sector sector : out){
|
for(Sector sector : out){
|
||||||
createTexture(sector);
|
createTexture(sector);
|
||||||
@@ -286,7 +286,7 @@ public class Sectors{
|
|||||||
out.add(sector);
|
out.add(sector);
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.putBinary("sectors", out);
|
Settings.putObject("sectors", out);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -270,14 +270,14 @@ public class Administration{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save(){
|
public void save(){
|
||||||
Settings.putBinary("player-info", playerInfo);
|
Settings.putObject("player-info", playerInfo);
|
||||||
Settings.putBinary("banned-ips", bannedIPs);
|
Settings.putObject("banned-ips", bannedIPs);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load(){
|
private void load(){
|
||||||
playerInfo = Settings.getBinary("player-info", ObjectMap.class, () -> new ObjectMap<>());
|
playerInfo = Settings.getObject("player-info", ObjectMap.class, () -> new ObjectMap<>());
|
||||||
bannedIPs = Settings.getBinary("banned-ips", Array.class, () -> new Array<>());
|
bannedIPs = Settings.getObject("banned-ips", Array.class, () -> new Array<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serialize
|
@Serialize
|
||||||
|
|||||||
@@ -327,11 +327,11 @@ public class JoinDialog extends FloatingDialog{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadServers(){
|
private void loadServers(){
|
||||||
servers = Settings.getBinary("server-list", Array.class, () -> new Array<>());
|
servers = Settings.getObject("server-list", Array.class, () -> new Array<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveServers(){
|
private void saveServers(){
|
||||||
Settings.putBinary("server-list", servers);
|
Settings.putObject("server-list", servers);
|
||||||
Settings.save();
|
Settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
package io.anuke.mindustry.desktop;
|
package io.anuke.mindustry.desktop;
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.Files.FileType;
|
|
||||||
import com.badlogic.gdx.Preferences;
|
import com.badlogic.gdx.Preferences;
|
||||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3FileHandle;
|
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import io.anuke.kryonet.KryoClient;
|
import io.anuke.kryonet.KryoClient;
|
||||||
import io.anuke.kryonet.KryoServer;
|
import io.anuke.kryonet.KryoServer;
|
||||||
import io.anuke.mindustry.Mindustry;
|
import io.anuke.mindustry.Mindustry;
|
||||||
import io.anuke.mindustry.core.Platform;
|
import io.anuke.mindustry.core.Platform;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.io.BinaryPreferences;
|
|
||||||
import io.anuke.ucore.util.OS;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class DesktopLauncher extends Lwjgl3Application{
|
public class DesktopLauncher extends Lwjgl3Application{
|
||||||
ObjectMap<String, Preferences> prefmap;
|
ObjectMap<String, Preferences> prefmap;
|
||||||
@@ -41,21 +35,4 @@ public class DesktopLauncher extends Lwjgl3Application{
|
|||||||
CrashHandler.handle(e);
|
CrashHandler.handle(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Preferences getPreferences(String name){
|
|
||||||
String prefsDirectory = OS.getAppDataDirectoryString("Mindustry");
|
|
||||||
|
|
||||||
if(prefmap == null){
|
|
||||||
prefmap = new ObjectMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(prefmap.containsKey(name)){
|
|
||||||
return prefmap.get(name);
|
|
||||||
}else{
|
|
||||||
Preferences prefs = new BinaryPreferences(new Lwjgl3FileHandle(new File(prefsDirectory, name), FileType.Absolute));
|
|
||||||
prefmap.put(name, prefs);
|
|
||||||
return prefs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
package io.anuke.mindustry.server;
|
package io.anuke.mindustry.server;
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.Files.FileType;
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Preferences;
|
import com.badlogic.gdx.Preferences;
|
||||||
import com.badlogic.gdx.backends.headless.HeadlessApplication;
|
import com.badlogic.gdx.backends.headless.HeadlessApplication;
|
||||||
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
|
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
|
||||||
import com.badlogic.gdx.backends.headless.HeadlessFileHandle;
|
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import io.anuke.kryonet.KryoClient;
|
import io.anuke.kryonet.KryoClient;
|
||||||
import io.anuke.kryonet.KryoServer;
|
import io.anuke.kryonet.KryoServer;
|
||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.io.BinaryPreferences;
|
|
||||||
import io.anuke.ucore.util.EmptyLogger;
|
import io.anuke.ucore.util.EmptyLogger;
|
||||||
import io.anuke.ucore.util.OS;
|
import io.anuke.ucore.util.OS;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class ServerLauncher extends HeadlessApplication{
|
public class ServerLauncher extends HeadlessApplication{
|
||||||
ObjectMap<String, Preferences> prefmap;
|
ObjectMap<String, Preferences> prefmap;
|
||||||
|
|
||||||
@@ -52,21 +47,4 @@ public class ServerLauncher extends HeadlessApplication{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Preferences getPreferences(String name){
|
|
||||||
String prefsDirectory = OS.getAppDataDirectoryString("Mindustry");
|
|
||||||
|
|
||||||
if(prefmap == null){
|
|
||||||
prefmap = new ObjectMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(prefmap.containsKey(name)){
|
|
||||||
return prefmap.get(name);
|
|
||||||
}else{
|
|
||||||
Preferences prefs = new BinaryPreferences(new HeadlessFileHandle(new File(prefsDirectory, name), FileType.Absolute));
|
|
||||||
prefmap.put(name, prefs);
|
|
||||||
return prefs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user