Skip to content

Commit

Permalink
mobile fixes on logs and some format (#423)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mcagabe19 and NexIsDumb authored Nov 3, 2024
1 parent 796d585 commit 72238d7
Showing 1 changed file with 66 additions and 24 deletions.
90 changes: 66 additions & 24 deletions source/funkin/backend/system/Logs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
}
};
Expand All @@ -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('] ')
];
Expand All @@ -77,7 +108,7 @@ class Logs {
}

public static function __showInConsole(text:Array<LogText>) {
#if sys
#if (sys && !mobile)
while(__showing) {
Sys.sleep(0.05);
}
Expand All @@ -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);
}
}

Expand All @@ -113,7 +154,8 @@ enum abstract Level(Int) {
var TRACE = 3;
var VERBOSE = 4;
}

typedef LogText = {
var text:String;
var color:ConsoleColor;
}
}

0 comments on commit 72238d7

Please sign in to comment.