mobile fixes on logs and some format (#423)
* mobile fixes on logs and some format * oops * use switch on here * mb i forgor switches could handle only inlines * no more dissasembled bodies no more murder.. no more innocence? * Update Logs.hx * Update Logs.hx --------- Co-authored-by: ⍚~Nex <87421482+NexIsDumb@users.noreply.github.com>
This commit is contained in:
@@ -11,8 +11,7 @@ class Logs {
|
||||
|
||||
public static var nativeTrace = Log.trace;
|
||||
public static function init() {
|
||||
|
||||
Log.trace = function(v : Dynamic, ?infos : Null<haxe.PosInfos>) {
|
||||
Log.trace = function(v:Dynamic, ?infos:Null<haxe.PosInfos>) {
|
||||
var data = [
|
||||
logText('${infos.fileName}:${infos.lineNumber}: ', CYAN),
|
||||
logText(Std.string(v))
|
||||
@@ -28,22 +27,48 @@ class Logs {
|
||||
__showInConsole(prepareColoredTrace(data, TRACE));
|
||||
};
|
||||
|
||||
LogFrontEnd.onLogs = function(Data, Style, FireOnce) {
|
||||
LogFrontEnd.onLogs = function(data, style, fireOnce) {
|
||||
var prefix = "[FLIXEL]";
|
||||
var color:ConsoleColor = LIGHTGRAY;
|
||||
var level:Level = INFO;
|
||||
if (Style == LogStyle.CONSOLE) {prefix = "> "; color = WHITE; level = INFO; } else
|
||||
if (Style == LogStyle.ERROR) {prefix = "[FLIXEL]"; color = RED; level = ERROR; } else
|
||||
if (Style == LogStyle.NORMAL) {prefix = "[FLIXEL]"; color = WHITE; level = INFO; } else
|
||||
if (Style == LogStyle.NOTICE) {prefix = "[FLIXEL]"; color = GREEN; level = VERBOSE;} else
|
||||
if (Style == LogStyle.WARNING) {prefix = "[FLIXEL]"; color = YELLOW; level = WARNING;}
|
||||
if (style == LogStyle.CONSOLE) // cant place a switch here as these arent inline values - Nex
|
||||
{
|
||||
prefix = "> ";
|
||||
color = WHITE;
|
||||
level = INFO;
|
||||
}
|
||||
else if (style == LogStyle.ERROR)
|
||||
{
|
||||
prefix = "[FLIXEL]";
|
||||
color = RED;
|
||||
level = ERROR;
|
||||
}
|
||||
else if (style == LogStyle.NORMAL)
|
||||
{
|
||||
prefix = "[FLIXEL]";
|
||||
color = WHITE;
|
||||
level = INFO;
|
||||
}
|
||||
else if (style == LogStyle.NOTICE)
|
||||
{
|
||||
prefix = "[FLIXEL]";
|
||||
color = GREEN;
|
||||
level = VERBOSE;
|
||||
}
|
||||
else if (style == LogStyle.WARNING)
|
||||
{
|
||||
prefix = "[FLIXEL]";
|
||||
color = YELLOW;
|
||||
level = WARNING;
|
||||
}
|
||||
|
||||
var d:Dynamic = Data;
|
||||
var d:Dynamic = data;
|
||||
if (!(d is Array))
|
||||
d = [d];
|
||||
var a:Array<Dynamic> = d;
|
||||
var strs = [for(e in a) Std.string(e)];
|
||||
for(e in strs) {
|
||||
for(e in strs)
|
||||
{
|
||||
Logs.trace('$prefix $e', level, color);
|
||||
}
|
||||
};
|
||||
@@ -55,12 +80,18 @@ class Logs {
|
||||
logText('[ '),
|
||||
logText('${Std.string(time.getHours()).addZeros(2)}:${Std.string(time.getMinutes()).addZeros(2)}:${Std.string(time.getSeconds()).addZeros(2)}', DARKMAGENTA),
|
||||
logText(' |'),
|
||||
switch(level) {
|
||||
case WARNING: logText(' WARNING ', DARKYELLOW);
|
||||
case ERROR: logText(' ERROR ', DARKRED);
|
||||
case TRACE: logText(' TRACE ', GRAY);
|
||||
case VERBOSE: logText(' VERBOSE ', DARKMAGENTA);
|
||||
default: logText(' INFORMATION ', CYAN);
|
||||
switch (level)
|
||||
{
|
||||
case WARNING:
|
||||
logText(' WARNING ', DARKYELLOW);
|
||||
case ERROR:
|
||||
logText(' ERROR ', DARKRED);
|
||||
case TRACE:
|
||||
logText(' TRACE ', GRAY);
|
||||
case VERBOSE:
|
||||
logText(' VERBOSE ', DARKMAGENTA);
|
||||
default:
|
||||
logText(' INFORMATION ', CYAN);
|
||||
},
|
||||
logText('] ')
|
||||
];
|
||||
@@ -77,7 +108,7 @@ class Logs {
|
||||
}
|
||||
|
||||
public static function __showInConsole(text:Array<LogText>) {
|
||||
#if sys
|
||||
#if (sys && !mobile)
|
||||
while(__showing) {
|
||||
Sys.sleep(0.05);
|
||||
}
|
||||
@@ -89,20 +120,30 @@ class Logs {
|
||||
NativeAPI.setConsoleColors();
|
||||
Sys.print("\r\n");
|
||||
__showing = false;
|
||||
#elseif mobile
|
||||
while(__showing) {
|
||||
Sys.sleep(0.05);
|
||||
}
|
||||
__showing = true;
|
||||
@:privateAccess
|
||||
Sys.print([for(t in text) t.text].join(""));
|
||||
__showing = false;
|
||||
#else
|
||||
@:privateAccess
|
||||
nativeTrace([for(t in text) t.text].join(""));
|
||||
#end
|
||||
}
|
||||
|
||||
public static function traceColored(text:Array<LogText>, level:Level = INFO) {
|
||||
public static function traceColored(text:Array<LogText>, level:Level = INFO)
|
||||
__showInConsole(prepareColoredTrace(text, level));
|
||||
}
|
||||
|
||||
public static function trace(text:String, level:Level = INFO, color:ConsoleColor = LIGHTGRAY) {
|
||||
traceColored([{
|
||||
text: text,
|
||||
color: color
|
||||
}], level);
|
||||
traceColored([
|
||||
{
|
||||
text: text,
|
||||
color: color
|
||||
}
|
||||
], level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +154,8 @@ enum abstract Level(Int) {
|
||||
var TRACE = 3;
|
||||
var VERBOSE = 4;
|
||||
}
|
||||
|
||||
typedef LogText = {
|
||||
var text:String;
|
||||
var color:ConsoleColor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user