cc-haxe/src/lib/Debug.hx

52 lines
1.1 KiB
Haxe

package lib;
import kernel.KernelEvents;
import kernel.log.Log;
import lua.NativeStringTools;
import lib.ui.Canvas;
import cc.ComputerCraft;
#if webconsole
import cc.HTTP;
import kernel.net.Net;
#end
class Debug {
public static function printBuildInfo() {
Log.debug("Commit: " + BuildInfo.getGitCommitHash());
Log.debug("Build time: " + BuildInfo.buildTime().toString());
Log.debug("CC/MC version:" + ComputerCraft._HOST);
}
public static function printCanvasToConsole(canvas: Canvas) {
var lines: Array<String> = [];
for (pos => pixel in canvas){
if (lines[pos.y] == null) {
lines[pos.y] = "";
}
if (lines[pos.y].length < pos.x) {
lines[pos.y] += NativeStringTools.rep(" ", pos.x - lines[pos.y].length);
}
lines[pos.y] = lines[pos.y].substr(0, pos.x) + pixel.char + lines[pos.y].substr(pos.x + 1);
}
Log.debug("\n" + lines.join("\n"));
}
#if Debug
public static function printKernelEventsCount(){
KernelEvents.instance.printListenerCount();
}
#end
#if webconsole
public static function printWeb(msg:String) {
HTTP.request("http://127.0.0.1:8080/"+Net.instance.networkID,msg);
}
#end
}