mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-12-05 18:30:22 -08:00
Closes Anuken/Mindustry-Suggestions/issues/5742
This commit is contained in:
parent
fdae9a14fe
commit
17a5b2f387
5 changed files with 65 additions and 56 deletions
|
|
@ -89,6 +89,8 @@ public class Vars implements Loadable{
|
||||||
public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md";
|
public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md";
|
||||||
/** list of built-in servers.*/
|
/** list of built-in servers.*/
|
||||||
public static final Seq<ServerGroup> defaultServers = Seq.with();
|
public static final Seq<ServerGroup> defaultServers = Seq.with();
|
||||||
|
/** cached server list - only used if defaultServers have not been fetched*/
|
||||||
|
public static final Seq<ServerGroup> cachedServers = Seq.with();
|
||||||
/** maximum openGL errors logged */
|
/** maximum openGL errors logged */
|
||||||
public static final int maxGlErrors = 100;
|
public static final int maxGlErrors = 100;
|
||||||
/** maximum size of any block, do not change unless you know what you're doing */
|
/** maximum size of any block, do not change unless you know what you're doing */
|
||||||
|
|
@ -206,6 +208,10 @@ public class Vars implements Loadable{
|
||||||
public static boolean drawDebugHitboxes = false;
|
public static boolean drawDebugHitboxes = false;
|
||||||
/** Whether to draw avoidance fields. */
|
/** Whether to draw avoidance fields. */
|
||||||
public static boolean debugDrawAvoidance = false;
|
public static boolean debugDrawAvoidance = false;
|
||||||
|
/** Whether the on-disk server file cache has been loaded. */
|
||||||
|
public static boolean loadedServerCache = false;
|
||||||
|
/** Whether the server list has been fetched from Github. */
|
||||||
|
public static boolean fetchedServers = false;
|
||||||
/** application data directory, equivalent to {@link Settings#getDataDirectory()} */
|
/** application data directory, equivalent to {@link Settings#getDataDirectory()} */
|
||||||
public static Fi dataDirectory;
|
public static Fi dataDirectory;
|
||||||
/** data subdirectory used for screenshots */
|
/** data subdirectory used for screenshots */
|
||||||
|
|
@ -226,6 +232,8 @@ public class Vars implements Loadable{
|
||||||
public static Fi bebuildDirectory;
|
public static Fi bebuildDirectory;
|
||||||
/** file used to store launch ID */
|
/** file used to store launch ID */
|
||||||
public static Fi launchIDFile;
|
public static Fi launchIDFile;
|
||||||
|
/** local cache of server list */
|
||||||
|
public static Fi serverCacheFile;
|
||||||
/** empty map, indicates no current map */
|
/** empty map, indicates no current map */
|
||||||
public static Map emptyMap;
|
public static Map emptyMap;
|
||||||
/** empty tile for payloads */
|
/** empty tile for payloads */
|
||||||
|
|
@ -322,6 +330,7 @@ public class Vars implements Loadable{
|
||||||
modDirectory = dataDirectory.child("mods/");
|
modDirectory = dataDirectory.child("mods/");
|
||||||
schematicDirectory = dataDirectory.child("schematics/");
|
schematicDirectory = dataDirectory.child("schematics/");
|
||||||
bebuildDirectory = dataDirectory.child("be_builds/");
|
bebuildDirectory = dataDirectory.child("be_builds/");
|
||||||
|
serverCacheFile = dataDirectory.child("server_list.json");
|
||||||
emptyMap = new Map(new StringMap());
|
emptyMap = new Map(new StringMap());
|
||||||
|
|
||||||
if(tree == null) tree = new FileTree();
|
if(tree == null) tree = new FileTree();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import arc.util.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
import mindustry.world.blocks.environment.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
|
|
@ -36,6 +37,16 @@ public class EditorRenderer implements Disposable{
|
||||||
packWidth = width * tilesize + packPad * 2;
|
packWidth = width * tilesize + packPad * 2;
|
||||||
packHeight = height * tilesize + packPad * 2;
|
packHeight = height * tilesize + packPad * 2;
|
||||||
|
|
||||||
|
//clear darkness
|
||||||
|
for(int x = 0; x < width; x++){
|
||||||
|
for(int y = 0; y < height; y++){
|
||||||
|
Tile tile = world.tile(x, y);
|
||||||
|
if(tile.block() instanceof StaticWall){
|
||||||
|
tile.data = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
recache();
|
recache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@ package mindustry.io.versions;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
|
||||||
import mindustry.*;
|
|
||||||
import mindustry.ctype.*;
|
|
||||||
import mindustry.ui.dialogs.JoinDialog.*;
|
import mindustry.ui.dialogs.JoinDialog.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
@ -50,35 +47,4 @@ public class LegacyIO{
|
||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readResearch(){
|
|
||||||
try{
|
|
||||||
byte[] bytes = Core.settings.getBytes("unlocks");
|
|
||||||
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(bytes));
|
|
||||||
|
|
||||||
int length = stream.readInt();
|
|
||||||
if(length > 0){
|
|
||||||
stream.readUTF(); //name of key type
|
|
||||||
stream.readUTF(); //name of value type
|
|
||||||
|
|
||||||
//each element is an array list
|
|
||||||
for(int i = 0; i < length; i++){
|
|
||||||
ContentType type = ContentType.all[stream.readInt()];
|
|
||||||
int arrLength = stream.readInt();
|
|
||||||
if(arrLength > 0){
|
|
||||||
stream.readUTF(); //type of contents (String)
|
|
||||||
for(int j = 0; j < arrLength; j++){
|
|
||||||
String name = stream.readUTF();
|
|
||||||
Content out = Vars.content.getByName(type, name);
|
|
||||||
if(out instanceof UnlockableContent u){
|
|
||||||
u.quietUnlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
|
||||||
Log.err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import mindustry.ui.*;
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class JoinDialog extends BaseDialog{
|
public class JoinDialog extends BaseDialog{
|
||||||
|
Seq<ServerGroup> tmpServers = new Seq<>();
|
||||||
Seq<Server> servers = new Seq<>();
|
Seq<Server> servers = new Seq<>();
|
||||||
Dialog add;
|
Dialog add;
|
||||||
Server renaming;
|
Server renaming;
|
||||||
|
|
@ -110,10 +111,6 @@ public class JoinDialog extends BaseDialog{
|
||||||
keyDown(KeyCode.f5, this::refreshAll);
|
keyDown(KeyCode.f5, this::refreshAll);
|
||||||
|
|
||||||
shown(() -> {
|
shown(() -> {
|
||||||
if(defaultServers.isEmpty()){
|
|
||||||
fetchServers();
|
|
||||||
}
|
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
refreshAll();
|
refreshAll();
|
||||||
|
|
||||||
|
|
@ -394,7 +391,7 @@ public class JoinDialog extends BaseDialog{
|
||||||
global.clear();
|
global.clear();
|
||||||
global.background(null);
|
global.background(null);
|
||||||
|
|
||||||
if(defaultServers.isEmpty()){
|
if(!fetchedServers){
|
||||||
fetchServers();
|
fetchServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -406,8 +403,12 @@ public class JoinDialog extends BaseDialog{
|
||||||
t.button(Icon.zoom, Styles.emptyi, this::refreshCommunity).size(54f);
|
t.button(Icon.zoom, Styles.emptyi, this::refreshCommunity).size(54f);
|
||||||
}).width((targetWidth() + 5f) * columns()).height(70f).pad(4).row();
|
}).width((targetWidth() + 5f) * columns()).height(70f).pad(4).row();
|
||||||
|
|
||||||
for(int i = 0; i < defaultServers.size; i ++){
|
//if the servers have been fetched, use the fetched list
|
||||||
ServerGroup group = defaultServers.get((i + defaultServers.size/2) % defaultServers.size);
|
//otherwise use the cached list + the extra servers that may have been included by mods
|
||||||
|
var servers = fetchedServers ? defaultServers : tmpServers.clear().addAll(cachedServers).addAll(defaultServers);
|
||||||
|
|
||||||
|
for(int i = 0; i < servers.size; i ++){
|
||||||
|
ServerGroup group = servers.get((i + servers.size/2) % servers.size);
|
||||||
boolean hidden = group.hidden();
|
boolean hidden = group.hidden();
|
||||||
if(hidden && !showHidden){
|
if(hidden && !showHidden){
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -661,6 +662,15 @@ public class JoinDialog extends BaseDialog{
|
||||||
var urls = Version.type.equals("bleeding-edge") || Vars.forceBeServers ? serverJsonBeURLs : serverJsonURLs;
|
var urls = Version.type.equals("bleeding-edge") || Vars.forceBeServers ? serverJsonBeURLs : serverJsonURLs;
|
||||||
|
|
||||||
if(Core.settings.getBool("communityservers", true)){
|
if(Core.settings.getBool("communityservers", true)){
|
||||||
|
try{
|
||||||
|
if(!loadedServerCache && serverCacheFile.exists()){
|
||||||
|
loadedServerCache = true;
|
||||||
|
cachedServers.addAll(parseServerString(serverCacheFile.readString()));
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
Log.err("Failed to load cached server file", e);
|
||||||
|
}
|
||||||
|
|
||||||
fetchServers(urls, 0);
|
fetchServers(urls, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -678,28 +688,41 @@ public class JoinDialog extends BaseDialog{
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.submit(result -> {
|
.submit(result -> {
|
||||||
Jval val = Jval.read(result.getResultAsString());
|
String text = result.getResultAsString();
|
||||||
Seq<ServerGroup> servers = new Seq<>();
|
Seq<ServerGroup> servers = parseServerString(text);
|
||||||
val.asArray().each(child -> {
|
|
||||||
String name = child.getString("name", "");
|
|
||||||
boolean prioritized = child.getBool("prioritized", false);
|
|
||||||
String[] addresses;
|
|
||||||
if(child.has("addresses") || (child.has("address") && child.get("address").isArray())){
|
|
||||||
addresses = (child.has("addresses") ? child.get("addresses") : child.get("address")).asArray().map(Jval::asString).toArray(String.class);
|
|
||||||
}else{
|
|
||||||
addresses = new String[]{child.getString("address", "<invalid>")};
|
|
||||||
}
|
|
||||||
servers.add(new ServerGroup(name, addresses, prioritized));
|
|
||||||
});
|
|
||||||
//modify default servers on main thread
|
//modify default servers on main thread
|
||||||
Core.app.post(() -> {
|
Core.app.post(() -> {
|
||||||
servers.sort(s -> s.name == null ? Integer.MAX_VALUE : s.name.hashCode());
|
//cache the server list to a file, so it can be loaded in case of an outage later
|
||||||
|
try{
|
||||||
|
serverCacheFile.writeString(text);
|
||||||
|
}catch(Exception e){
|
||||||
|
Log.err("Failed to write server cache", e);
|
||||||
|
}
|
||||||
defaultServers.addAll(servers);
|
defaultServers.addAll(servers);
|
||||||
|
fetchedServers = true;
|
||||||
Log.info("Fetched @ community servers.", defaultServers.sum(s -> s.addresses.length));
|
Log.info("Fetched @ community servers.", defaultServers.sum(s -> s.addresses.length));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Seq<ServerGroup> parseServerString(String str){
|
||||||
|
Jval val = Jval.read(str);
|
||||||
|
Seq<ServerGroup> servers = new Seq<>();
|
||||||
|
val.asArray().each(child -> {
|
||||||
|
String name = child.getString("name", "");
|
||||||
|
boolean prioritized = child.getBool("prioritized", false);
|
||||||
|
String[] addresses;
|
||||||
|
if(child.has("addresses") || (child.has("address") && child.get("address").isArray())){
|
||||||
|
addresses = (child.has("addresses") ? child.get("addresses") : child.get("address")).asArray().map(Jval::asString).toArray(String.class);
|
||||||
|
}else{
|
||||||
|
addresses = new String[]{child.getString("address", "<invalid>")};
|
||||||
|
}
|
||||||
|
servers.add(new ServerGroup(name, addresses, prioritized));
|
||||||
|
});
|
||||||
|
servers.sort(s -> s.name == null ? Integer.MAX_VALUE : s.name.hashCode());
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
|
||||||
private void saveServers(){
|
private void saveServers(){
|
||||||
Core.settings.putJson("servers", Server.class, servers);
|
Core.settings.putJson("servers", Server.class, servers);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue