This commit is contained in:
Anuken
2020-06-08 17:19:47 -04:00
parent 87ab895253
commit 8ea28e1ced
147 changed files with 438 additions and 437 deletions

View File

@@ -7,7 +7,7 @@ import arc.files.*;
import arc.func.*;
import arc.graphics.*;
import arc.mock.*;
import arc.struct.Array;
import arc.struct.Seq;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
@@ -102,8 +102,8 @@ public class ContentParser{
}};
/** Stores things that need to be parsed fully, e.g. reading fields of content.
* This is done to accomodate binding of content names first.*/
private Array<Runnable> reads = new Array<>();
private Array<Runnable> postreads = new Array<>();
private Seq<Runnable> reads = new Seq<>();
private Seq<Runnable> postreads = new Seq<>();
private ObjectSet<Object> toBeParsed = new ObjectSet<>();
private LoadedMod currentMod;
private Content currentContent;
@@ -368,7 +368,7 @@ public class ContentParser{
private void init(){
for(ContentType type : ContentType.all){
Array<Content> arr = Vars.content.getBy(type);
Seq<Content> arr = Vars.content.getBy(type);
if(!arr.isEmpty()){
Class<?> c = arr.first().getClass();
//get base content class, skipping intermediates
@@ -459,7 +459,7 @@ public class ContentParser{
}else if(t instanceof NullPointerException){
builder.append(Strings.parseException(t, true));
}else{
Array<Throwable> causes = Strings.getCauses(t);
Seq<Throwable> causes = Strings.getCauses(t);
for(Throwable e : causes){
builder.append("[accent][[").append(e.getClass().getSimpleName().replace("Exception", ""))
.append("][] ")

View File

@@ -33,13 +33,13 @@ public class Mods implements Loadable{
private Json json = new Json();
private @Nullable Scripts scripts;
private ContentParser parser = new ContentParser();
private ObjectMap<String, Array<Fi>> bundles = new ObjectMap<>();
private ObjectMap<String, Seq<Fi>> bundles = new ObjectMap<>();
private ObjectSet<String> specialFolders = ObjectSet.with("bundles", "sprites", "sprites-override");
private int totalSprites;
private MultiPacker packer;
private Array<LoadedMod> mods = new Array<>();
private Seq<LoadedMod> mods = new Seq<>();
private ObjectMap<Class<?>, ModMeta> metas = new ObjectMap<>();
private boolean requiresReload, createdAtlas;
@@ -103,8 +103,8 @@ public class Mods implements Loadable{
packer = new MultiPacker();
eachEnabled(mod -> {
Array<Fi> sprites = mod.root.child("sprites").findAll(f -> f.extension().equals("png"));
Array<Fi> overrides = mod.root.child("sprites-override").findAll(f -> f.extension().equals("png"));
Seq<Fi> sprites = mod.root.child("sprites").findAll(f -> f.extension().equals("png"));
Seq<Fi> overrides = mod.root.child("sprites-override").findAll(f -> f.extension().equals("png"));
packSprites(sprites, mod, true);
packSprites(overrides, mod, false);
Log.debug("Packed @ images for mod '@'.", sprites.size + overrides.size, mod.meta.name);
@@ -127,7 +127,7 @@ public class Mods implements Loadable{
}
}
private void packSprites(Array<Fi> sprites, LoadedMod mod, boolean prefix){
private void packSprites(Seq<Fi> sprites, LoadedMod mod, boolean prefix){
for(Fi file : sprites){
try(InputStream stream = file.read()){
byte[] bytes = Streams.copyBytes(stream, Math.max((int)file.length(), 512));
@@ -171,7 +171,7 @@ public class Mods implements Loadable{
packer.flush(filter, Core.atlas);
//generate new icons
for(Array<Content> arr : content.getContentMap()){
for(Seq<Content> arr : content.getContentMap()){
arr.each(c -> {
if(c instanceof UnlockableContent && c.minfo.mod != null){
UnlockableContent u = (UnlockableContent)c;
@@ -305,16 +305,16 @@ public class Mods implements Loadable{
}
}
private void topoSort(LoadedMod mod, Array<LoadedMod> stack, ObjectSet<LoadedMod> visited){
private void topoSort(LoadedMod mod, Seq<LoadedMod> stack, ObjectSet<LoadedMod> visited){
visited.add(mod);
mod.dependencies.each(m -> !visited.contains(m), m -> topoSort(m, stack, visited));
stack.add(mod);
}
/** @return mods ordered in the correct way needed for dependencies. */
private Array<LoadedMod> orderedMods(){
private Seq<LoadedMod> orderedMods(){
ObjectSet<LoadedMod> visited = new ObjectSet<>();
Array<LoadedMod> result = new Array<>();
Seq<LoadedMod> result = new Seq<>();
eachEnabled(mod -> {
if(!visited.contains(mod)){
topoSort(mod, result, visited);
@@ -346,7 +346,7 @@ public class Mods implements Loadable{
for(Fi file : folder.list()){
if(file.name().startsWith("bundle") && file.extension().equals("properties")){
String name = file.nameWithoutExtension();
bundles.get(name, Array::new).add(file);
bundles.get(name, Seq::new).add(file);
}
}
}
@@ -357,7 +357,7 @@ public class Mods implements Loadable{
while(bundle != null){
String str = bundle.getLocale().toString();
String locale = "bundle" + (str.isEmpty() ? "" : "_" + str);
for(Fi file : bundles.get(locale, Array::new)){
for(Fi file : bundles.get(locale, Seq::new)){
try{
PropertiesUtils.load(bundle.getProperties(), file.reader());
}catch(Throwable e){
@@ -469,7 +469,7 @@ public class Mods implements Loadable{
if(mod.root.child("scripts").exists()){
content.setCurrentMod(mod);
//if there's only one script file, use it (for backwards compatibility); if there isn't, use "main.js"
Array<Fi> allScripts = mod.root.child("scripts").findAll(f -> f.extEquals("js"));
Seq<Fi> allScripts = mod.root.child("scripts").findAll(f -> f.extEquals("js"));
Fi main = allScripts.size == 1 ? allScripts.first() : mod.root.child("scripts").child("main.js");
if(main.exists() && !main.isDirectory()){
try{
@@ -519,7 +519,7 @@ public class Mods implements Loadable{
}
}
Array<LoadRun> runs = new Array<>();
Seq<LoadRun> runs = new Seq<>();
for(LoadedMod mod : orderedMods()){
if(mod.root.child("content").exists()){
@@ -562,7 +562,7 @@ public class Mods implements Loadable{
}
/** @return a list of mods and versions, in the format name:version. */
public Array<String> getModStrings(){
public Seq<String> getModStrings(){
return mods.select(l -> !l.meta.hidden && l.enabled()).map(l -> l.name + ":" + l.meta.version);
}
@@ -579,9 +579,9 @@ public class Mods implements Loadable{
/** @return the mods that the client is missing.
* The inputted array is changed to contain the extra mods that the client has but the server doesn't.*/
public Array<String> getIncompatibility(Array<String> out){
Array<String> mods = getModStrings();
Array<String> result = mods.copy();
public Seq<String> getIncompatibility(Seq<String> out){
Seq<String> mods = getModStrings();
Seq<String> result = mods.copy();
for(String mod : mods){
if(out.remove(mod)){
result.remove(mod);
@@ -590,7 +590,7 @@ public class Mods implements Loadable{
return result;
}
public Array<LoadedMod> list(){
public Seq<LoadedMod> list(){
return mods;
}
@@ -681,11 +681,11 @@ public class Mods implements Loadable{
/** This mod's metadata. */
public final ModMeta meta;
/** This mod's dependencies as already-loaded mods. */
public Array<LoadedMod> dependencies = new Array<>();
public Seq<LoadedMod> dependencies = new Seq<>();
/** All missing dependencies of this mod as strings. */
public Array<String> missingDependencies = new Array<>();
public Seq<String> missingDependencies = new Seq<>();
/** Script files to run. */
public Array<Fi> scripts = new Array<>();
public Seq<Fi> scripts = new Seq<>();
/** Content with intialization code. */
public ObjectSet<Content> erroredContent = new ObjectSet<>();
/** Current state of this mod. */
@@ -805,7 +805,7 @@ public class Mods implements Loadable{
/** Plugin metadata information.*/
public static class ModMeta{
public String name, displayName, author, description, version, main, minGameVersion;
public Array<String> dependencies = Array.with();
public Seq<String> dependencies = Seq.with();
/** Hidden mods are only server-side or client-side, and do not support adding new content. */
public boolean hidden;

View File

@@ -18,15 +18,15 @@ import java.util.regex.*;
public class Scripts implements Disposable{
private final static Object[] emptyObjects = {};
private final Array<String> blacklist = Array.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk",
private final Seq<String> blacklist = Seq.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk",
"runtime", "util.os", "rmi", "security", "org.", "sun.", "beans", "sql", "http", "exec", "compiler", "process", "system",
".awt", "socket", "classloader", "oracle", "invoke", "arc.events", "java.util.function", "java.util.stream");
private final Array<String> whitelist = Array.with("mindustry.net", "netserver", "netclient", "com.sun.proxy.$proxy", "mindustry.gen.");
private final Seq<String> whitelist = Seq.with("mindustry.net", "netserver", "netclient", "com.sun.proxy.$proxy", "mindustry.gen.");
private final Context context;
private Scriptable scope;
private boolean errored;
private LoadedMod currentMod = null;
private Array<EventHandle> events = new Array<>();
private Seq<EventHandle> events = new Seq<>();
public Scripts(){
Time.mark();