Better console / Better logging
This commit is contained in:
@@ -32,8 +32,8 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
|
||||
|
||||
@Override
|
||||
public void setup(){
|
||||
Vars.loadLogger();
|
||||
Vars.platform = this;
|
||||
Log.setUseColors(false);
|
||||
beginTime = Time.millis();
|
||||
|
||||
Time.setDeltaProvider(() -> {
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.anuke.mindustry.entities.effect.*;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.input.*;
|
||||
import io.anuke.mindustry.maps.*;
|
||||
@@ -25,12 +26,14 @@ import io.anuke.mindustry.world.blocks.defense.ForceProjector.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
|
||||
import static io.anuke.arc.Core.*;
|
||||
import static io.anuke.arc.Core.settings;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Vars implements Loadable{
|
||||
/** Whether to load locales.*/
|
||||
public static boolean loadLocales = true;
|
||||
/** Whether the logger is loaded. */
|
||||
public static boolean loadedLogger = false;
|
||||
/** Maximum schematic size.*/
|
||||
public static final int maxSchematicSize = 32;
|
||||
/** All schematic base64 starts with this string.*/
|
||||
@@ -270,6 +273,31 @@ public class Vars implements Loadable{
|
||||
maps.load();
|
||||
}
|
||||
|
||||
public static void loadLogger(){
|
||||
if(loadedLogger) return;
|
||||
|
||||
String[] tags = {"[green][D][]", "[royal][I][]", "[yellow][W][]", "[scarlet][E][]", ""};
|
||||
String[] stags = {"&lc&fb[D]", "&lg&fb[I]", "&ly&fb[W]", "&lr&fb[E]", ""};
|
||||
|
||||
Array<String> logBuffer = new Array<>();
|
||||
Log.setLogger((level, text, args) -> {
|
||||
String result = Log.format(text, args);
|
||||
System.out.println(Log.format(stags[level.ordinal()] + "&fr " + text, args));
|
||||
|
||||
result = tags[level.ordinal()] + " " + result;
|
||||
|
||||
if(!headless && (ui == null || ui.scriptfrag == null)){
|
||||
logBuffer.add(result);
|
||||
}else if(!headless){
|
||||
ui.scriptfrag.addMessage(result);
|
||||
}
|
||||
});
|
||||
|
||||
Events.on(ClientLoadEvent.class, e -> logBuffer.each(ui.scriptfrag::addMessage));
|
||||
|
||||
loadedLogger = true;
|
||||
}
|
||||
|
||||
public static void loadSettings(){
|
||||
Core.settings.setAppName(appName);
|
||||
|
||||
|
||||
@@ -87,12 +87,12 @@ public class ContentLoader{
|
||||
}
|
||||
}
|
||||
|
||||
Log.info("--- CONTENT INFO ---");
|
||||
Log.debug("--- CONTENT INFO ---");
|
||||
for(int k = 0; k < contentMap.length; k++){
|
||||
Log.info("[{0}]: loaded {1}", ContentType.values()[k].name(), contentMap[k].size);
|
||||
Log.debug("[{0}]: loaded {1}", ContentType.values()[k].name(), contentMap[k].size);
|
||||
}
|
||||
Log.info("Total content loaded: {0}", Array.with(ContentType.values()).mapInt(c -> contentMap[c.ordinal()].size).sum());
|
||||
Log.info("-------------------");
|
||||
Log.debug("Total content loaded: {0}", Array.with(ContentType.values()).mapInt(c -> contentMap[c.ordinal()].size).sum());
|
||||
Log.debug("-------------------");
|
||||
}
|
||||
|
||||
/** Calls Content#init() on everything. Use only after all modules have been created.*/
|
||||
|
||||
@@ -483,7 +483,7 @@ public class ContentParser{
|
||||
FieldMetadata metadata = fields.get(child.name().replace(" ", "_"));
|
||||
if(metadata == null){
|
||||
if(ignoreUnknownFields){
|
||||
Log.err("{0}: Ignoring unknown field: " + child.name + " (" + type.getName() + ")", object);
|
||||
Log.warn("{0}: Ignoring unknown field: " + child.name + " (" + type.getName() + ")", object);
|
||||
continue;
|
||||
}else{
|
||||
SerializationException ex = new SerializationException("Field not found: " + child.name + " (" + type.getName() + ")");
|
||||
|
||||
@@ -101,7 +101,7 @@ public class Mods implements Loadable{
|
||||
Array<FileHandle> overrides = mod.root.child("sprites-override").findAll(f -> f.extension().equals("png"));
|
||||
packSprites(sprites, mod, true);
|
||||
packSprites(overrides, mod, false);
|
||||
Log.info("Packed {0} images for mod '{1}'.", sprites.size + overrides.size, mod.meta.name);
|
||||
Log.debug("Packed {0} images for mod '{1}'.", sprites.size + overrides.size, mod.meta.name);
|
||||
totalSprites += sprites.size + overrides.size;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class Mods implements Loadable{
|
||||
}
|
||||
}
|
||||
|
||||
Log.info("Time to pack textures: {0}", Time.elapsed());
|
||||
Log.debug("Time to pack textures: {0}", Time.elapsed());
|
||||
}
|
||||
|
||||
private void packSprites(Array<FileHandle> sprites, LoadedMod mod, boolean prefix){
|
||||
@@ -158,12 +158,12 @@ public class Mods implements Loadable{
|
||||
|
||||
Core.atlas = packer.flush(filter, new TextureAtlas());
|
||||
Core.atlas.setErrorRegion("error");
|
||||
Log.info("Total pages: {0}", Core.atlas.getTextures().size);
|
||||
Log.debug("Total pages: {0}", Core.atlas.getTextures().size);
|
||||
}
|
||||
|
||||
packer.dispose();
|
||||
packer = null;
|
||||
Log.info("Time to update textures: {0}", Time.elapsed());
|
||||
Log.debug("Time to update textures: {0}", Time.elapsed());
|
||||
}
|
||||
|
||||
private PageType getPage(AtlasRegion region){
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
package io.anuke.mindustry.mod;
|
||||
|
||||
import io.anuke.arc.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.arc.util.Log.*;
|
||||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.mod.Mods.*;
|
||||
import org.mozilla.javascript.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Scripts implements Disposable{
|
||||
private final Context context;
|
||||
private final String wrapper;
|
||||
private Scriptable scope;
|
||||
private Array<String> logBuffer = new Array<>();
|
||||
|
||||
public Scripts(){
|
||||
Time.mark();
|
||||
@@ -50,18 +47,11 @@ public class Scripts implements Disposable{
|
||||
}
|
||||
|
||||
public void log(String source, String message){
|
||||
Log.info("[{0}]: {1}", source, message);
|
||||
logBuffer.add("[accent][" + source + "]:[] " + message);
|
||||
if(!headless && ui.scriptfrag != null){
|
||||
onLoad();
|
||||
}
|
||||
log(LogLevel.info, source, message);
|
||||
}
|
||||
|
||||
public void onLoad(){
|
||||
if(!headless){
|
||||
logBuffer.each(ui.scriptfrag::addMessage);
|
||||
}
|
||||
logBuffer.clear();
|
||||
public void log(LogLevel level, String source, String message){
|
||||
Log.log(level, "[{0}]: {1}", source, message);
|
||||
}
|
||||
|
||||
public void run(LoadedMod mod, FileHandle file){
|
||||
@@ -72,7 +62,7 @@ public class Scripts implements Disposable{
|
||||
try{
|
||||
context.evaluateString(scope, script, file, 1, null);
|
||||
}catch(Throwable t){
|
||||
log(file, "[scarlet]" + getError(t));
|
||||
log(LogLevel.err, file, "" + getError(t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import static io.anuke.arc.Core.*;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ScriptConsoleFragment extends Table{
|
||||
private final static int messagesShown = 14;
|
||||
private final static int messagesShown = 30;
|
||||
private Array<String> messages = new Array<>();
|
||||
private boolean open = false, shown;
|
||||
private TextField chatfield;
|
||||
@@ -71,16 +71,13 @@ public class ScriptConsoleFragment extends Table{
|
||||
historyPos--;
|
||||
updateChat();
|
||||
}
|
||||
scrollPos = (int)Mathf.clamp(scrollPos + input.axis(Binding.chat_scroll), 0, Math.max(0, messages.size - messagesShown));
|
||||
}
|
||||
|
||||
scrollPos = (int)Mathf.clamp(scrollPos + input.axis(Binding.chat_scroll), 0, Math.max(0, messages.size - messagesShown));
|
||||
});
|
||||
|
||||
history.insert(0, "");
|
||||
setup();
|
||||
|
||||
if(mods.hasScripts()){
|
||||
app.post(() -> mods.getScripts().onLoad());
|
||||
}
|
||||
}
|
||||
|
||||
public Fragment container(){
|
||||
|
||||
Reference in New Issue
Block a user