mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-02 20:33:50 +07:00
Usage of ExtendedPreferences
This commit is contained in:
parent
696a59f1b9
commit
7488a6d42b
@ -27,7 +27,7 @@ allprojects {
|
||||
appName = 'Mindustry'
|
||||
gdxVersion = '1.9.8'
|
||||
roboVMVersion = '2.3.0'
|
||||
uCoreVersion = '220916714cbe63664c34f95a9dc50a362feca732'
|
||||
uCoreVersion = '33847672a0ea5c215f9799c5a010d60aade3101c'
|
||||
|
||||
getVersionString = {
|
||||
String buildVersion = getBuildVersion()
|
||||
|
@ -30,6 +30,7 @@ import java.util.Locale;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Vars{
|
||||
public static final String appName = "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 crashReportURL = "http://mindustry.us.to/report";
|
||||
@ -174,7 +175,7 @@ public class Vars{
|
||||
gwt = Gdx.app.getType() == ApplicationType.WebGL;
|
||||
|
||||
if(!gwt){
|
||||
dataDirectory = OS.getAppDataDirectory("Mindustry");
|
||||
dataDirectory = OS.getAppDataDirectory(appName);
|
||||
customMapDirectory = dataDirectory.child("maps/");
|
||||
saveDirectory = dataDirectory.child("saves/");
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class Saves{
|
||||
|
||||
public void load(){
|
||||
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 ++){
|
||||
int index = slots.get(i);
|
||||
@ -143,7 +143,7 @@ public class Saves{
|
||||
IntArray result = new IntArray(saves.size);
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class Unlocks{
|
||||
public void load(){
|
||||
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()){
|
||||
ContentUnlockSet cset = new ContentUnlockSet();
|
||||
@ -102,7 +102,7 @@ public class Unlocks{
|
||||
output.put(centry.key, write);
|
||||
}
|
||||
|
||||
Settings.putBinary("content-sets", output);
|
||||
Settings.putObject("content-sets", output);
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class BundleLoader{
|
||||
|
||||
public static void load(){
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class Maps implements Disposable{
|
||||
Settings.putString("map-data-" + name, new String(Base64Coder.encode(stream.toByteArray())));
|
||||
if(!customMapNames.contains(name, false)){
|
||||
customMapNames.add(name);
|
||||
Settings.putBinary("custom-maps", customMapNames);
|
||||
Settings.putObject("custom-maps", customMapNames);
|
||||
}
|
||||
Settings.save();
|
||||
}
|
||||
@ -126,7 +126,7 @@ public class Maps implements Disposable{
|
||||
} else {
|
||||
customMapNames.removeValue(map.name, false);
|
||||
Settings.putString("map-data-" + map.name, "");
|
||||
Settings.putBinary("custom-maps", customMapNames);
|
||||
Settings.putObject("custom-maps", customMapNames);
|
||||
Settings.save();
|
||||
}
|
||||
}
|
||||
@ -159,7 +159,7 @@ public class Maps implements Disposable{
|
||||
}
|
||||
|
||||
}else{
|
||||
customMapNames = Settings.getBinary("custom-maps", Array.class, () -> new Array<>());
|
||||
customMapNames = Settings.getObject("custom-maps", Array.class, () -> new Array<>());
|
||||
|
||||
for(String name : customMapNames){
|
||||
try{
|
||||
|
@ -262,7 +262,7 @@ public class Sectors{
|
||||
}
|
||||
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){
|
||||
createTexture(sector);
|
||||
@ -286,7 +286,7 @@ public class Sectors{
|
||||
out.add(sector);
|
||||
}
|
||||
|
||||
Settings.putBinary("sectors", out);
|
||||
Settings.putObject("sectors", out);
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
|
@ -270,14 +270,14 @@ public class Administration{
|
||||
}
|
||||
|
||||
public void save(){
|
||||
Settings.putBinary("player-info", playerInfo);
|
||||
Settings.putBinary("banned-ips", bannedIPs);
|
||||
Settings.putObject("player-info", playerInfo);
|
||||
Settings.putObject("banned-ips", bannedIPs);
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
private void load(){
|
||||
playerInfo = Settings.getBinary("player-info", ObjectMap.class, () -> new ObjectMap<>());
|
||||
bannedIPs = Settings.getBinary("banned-ips", Array.class, () -> new Array<>());
|
||||
playerInfo = Settings.getObject("player-info", ObjectMap.class, () -> new ObjectMap<>());
|
||||
bannedIPs = Settings.getObject("banned-ips", Array.class, () -> new Array<>());
|
||||
}
|
||||
|
||||
@Serialize
|
||||
|
@ -327,11 +327,11 @@ public class JoinDialog extends FloatingDialog{
|
||||
}
|
||||
|
||||
private void loadServers(){
|
||||
servers = Settings.getBinary("server-list", Array.class, () -> new Array<>());
|
||||
servers = Settings.getObject("server-list", Array.class, () -> new Array<>());
|
||||
}
|
||||
|
||||
private void saveServers(){
|
||||
Settings.putBinary("server-list", servers);
|
||||
Settings.putObject("server-list", servers);
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,15 @@
|
||||
package io.anuke.mindustry.desktop;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.Files.FileType;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3FileHandle;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.kryonet.KryoClient;
|
||||
import io.anuke.kryonet.KryoServer;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
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{
|
||||
ObjectMap<String, Preferences> prefmap;
|
||||
@ -41,21 +35,4 @@ public class DesktopLauncher extends Lwjgl3Application{
|
||||
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;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.Files.FileType;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.backends.headless.HeadlessApplication;
|
||||
import com.badlogic.gdx.backends.headless.HeadlessApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.headless.HeadlessFileHandle;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.kryonet.KryoClient;
|
||||
import io.anuke.kryonet.KryoServer;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.ucore.io.BinaryPreferences;
|
||||
import io.anuke.ucore.util.EmptyLogger;
|
||||
import io.anuke.ucore.util.OS;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ServerLauncher extends HeadlessApplication{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user