Mod subtitles

This commit is contained in:
Anuken
2022-04-27 23:14:14 -04:00
parent f892811ac3
commit 1075e4b1b7
8 changed files with 19 additions and 74 deletions
-52
View File
@@ -2,10 +2,8 @@ package mindustry.mod;
import arc.*;
import arc.files.*;
import arc.func.*;
import arc.util.*;
import arc.util.Log.*;
import arc.util.io.*;
import mindustry.*;
import mindustry.mod.Mods.*;
import rhino.*;
@@ -67,60 +65,10 @@ public class Scripts implements Disposable{
Log.log(level, "[@]: @", source, message);
}
//region utility mod functions
public float[] newFloats(int capacity){
return new float[capacity];
}
public String readString(String path){
return Vars.tree.get(path, true).readString();
}
public byte[] readBytes(String path){
return Vars.tree.get(path, true).readBytes();
}
/** Ask the user to select a file to read for a certain purpose like "Please upload a sprite" */
public void readFile(String purpose, String ext, Cons<String> cons){
selectFile(true, purpose, ext, fi -> cons.get(fi.readString()));
}
/** readFile but for a byte[] */
public void readBinFile(String purpose, String ext, Cons<byte[]> cons){
selectFile(true, purpose, ext, fi -> cons.get(fi.readBytes()));
}
/** Ask the user to write a file. */
public void writeFile(String purpose, String ext, String contents){
if(contents == null) contents = "";
final String fContents = contents;
selectFile(false, purpose, ext, fi -> fi.writeString(fContents));
}
/** writeFile but for a byte[] */
public void writeBinFile(String purpose, String ext, byte[] contents){
if(contents == null) contents = Streams.emptyBytes;
final byte[] fContents = contents;
selectFile(false, purpose, ext, fi -> fi.writeBytes(fContents));
}
private void selectFile(boolean open, String purpose, String ext, Cons<Fi> cons){
purpose = purpose.startsWith("@") ? Core.bundle.get(purpose.substring(1)) : purpose;
//add purpose and extension at the top
String title = Core.bundle.get(open ? "open" : "save") + " - " + purpose + " (." + ext + ")";
Vars.platform.showFileChooser(open, title, ext, fi -> {
try{
cons.get(fi);
}catch(Exception e){
Log.err("Failed to select file '@' for a mod", fi);
Log.err(e);
}
});
}
//endregion
public void run(LoadedMod mod, Fi file){
currentMod = mod;
run(file.readString(), file.name(), true);