cc-haxe/src/util/Debug.hx

47 lines
1.0 KiB
Haxe

package util;
import lua.NativeStringTools;
import lib.ui.Canvas;
import cc.ComputerCraft;
import kernel.Log;
#if webconsole
import cc.HTTP;
import kernel.net.Net;
#end
class Debug {
public static function printBuildInfo() {
Log.debug("Commit: " + BuildInfo.getGitCommitHash());
var time:Date = Date.fromTime(BuildInfo.buildTime());
Log.debug("Build time: " + time.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 webconsole
public static function printWeb(msg:String) {
HTTP.request("http://127.0.0.1:8080/"+Net.instance.networkID,msg);
}
#end
}