mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 15:48:26 -04:00
Remove the Thread.sleep in BaseMainActivity, make MCOptionUtils use ArrayMap instead of List
This commit is contained in:
parent
c0034126ca
commit
0020c4deb2
@ -1230,7 +1230,6 @@ public class BaseMainActivity extends LoggableActivity {
|
|||||||
public void getMcScale() {
|
public void getMcScale() {
|
||||||
//Get the scale stored in game files, used auto scale if found or if the stored scaled is bigger than the authorized size.
|
//Get the scale stored in game files, used auto scale if found or if the stored scaled is bigger than the authorized size.
|
||||||
MCOptionUtils.load();
|
MCOptionUtils.load();
|
||||||
try { Thread.sleep(200); } catch (Throwable th) {}
|
|
||||||
String str = MCOptionUtils.get("guiScale");
|
String str = MCOptionUtils.get("guiScale");
|
||||||
this.guiScale = (str == null ? 0 :Integer.parseInt(str));
|
this.guiScale = (str == null ? 0 :Integer.parseInt(str));
|
||||||
|
|
||||||
|
@ -1,22 +1,25 @@
|
|||||||
package net.kdt.pojavlaunch.utils;
|
package net.kdt.pojavlaunch.utils;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import net.kdt.pojavlaunch.*;
|
import net.kdt.pojavlaunch.*;
|
||||||
|
|
||||||
public class MCOptionUtils
|
public class MCOptionUtils
|
||||||
{
|
{
|
||||||
private static final List<String> mLineList = Collections.synchronizedList(new ArrayList<>());
|
private static final ArrayMap<String,String> parameterMap = new ArrayMap<>();
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
mLineList.clear();
|
parameterMap.clear();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(Tools.DIR_GAME_NEW + "/options.txt"));
|
BufferedReader reader = new BufferedReader(new FileReader(Tools.DIR_GAME_NEW + "/options.txt"));
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
mLineList.add(line);
|
int firstColonIndex = line.indexOf(':');
|
||||||
|
if(firstColonIndex < 0) {
|
||||||
|
Log.w(Tools.APP_NAME, "No colon on line \""+line+"\", skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
parameterMap.put(line.substring(0,firstColonIndex), line.substring(firstColonIndex+1));
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -25,34 +28,20 @@ public class MCOptionUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void set(String key, String value) {
|
public static void set(String key, String value) {
|
||||||
for (int i = 0; i < mLineList.size(); i++) {
|
parameterMap.put(key,value);
|
||||||
String line = mLineList.get(i);
|
|
||||||
if (line.startsWith(key + ":")) {
|
|
||||||
mLineList.set(i, key + ":" + value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mLineList.add(key + ":" + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String get(String key){
|
public static String get(String key){
|
||||||
if(mLineList.isEmpty()) load();
|
return parameterMap.get(key);
|
||||||
String searchedLine=null;
|
|
||||||
for(String line : mLineList){
|
|
||||||
if(line.startsWith(key + ":")) {
|
|
||||||
searchedLine = line;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(searchedLine != null) return searchedLine.substring(searchedLine.indexOf(':') + 1);
|
|
||||||
else return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save() {
|
public static void save() {
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
for(String line : mLineList)
|
for(String key : parameterMap.keySet())
|
||||||
result.append(line).append('\n');
|
result.append(key)
|
||||||
|
.append(':')
|
||||||
|
.append(parameterMap.get(key))
|
||||||
|
.append('\n');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Tools.write(Tools.DIR_GAME_NEW + "/options.txt", result.toString());
|
Tools.write(Tools.DIR_GAME_NEW + "/options.txt", result.toString());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user