using System.Collections; using System.Collections.Generic; using System.Text; using System; using System.Linq; using Godot; namespace Rokojori { public class RJLog { static void Stringify( object obj, StringBuilder output ) { if ( obj == null ) { output.Append( "" ); return; } if ( obj is float || obj is double ) { output.Append( RegexUtility.WriteDouble( (double)obj ) ); return; } output.Append( obj.ToString() ); } static void LogMessage( string message ) { var trace = GetTrace(); GD.PrintRich("\n[b]" + message + "[/b]"); GD.PrintRich( trace ); } static void LogErrorMessage( string message ) { var trace = GetTrace(); GD.PrintErr( "\n"+ message ); GD.PrintRich( trace ); } static string GetTrace() { var stackTrace = new System.Diagnostics.StackTrace( true ); var frameIndex = 3; var frame = stackTrace.GetFrame( frameIndex ); var className = frame.GetFileName(); if ( className != null ) { var slashIndex = -1; for ( int i = className.Length - 1; i >= 0 && slashIndex == -1; i-- ) { if ( className[ i ] == '\\' || className[ i ] == '/' ) { slashIndex = i; } } if ( slashIndex != -1 ) { var end = className.EndsWith( ".cs" ) ? className.Length - 3 : className.Length; className = className.Substring( slashIndex + 1, end - ( slashIndex + 1 ) ); } } if ( className == null ) { className =""; } var trace = className + "." + frame.GetMethod().Name + "() ln."+ frame.GetFileLineNumber(); return "[color=gray] " + trace + "[/color]" ; } public static void Log( params object[] objects) { var sb = new StringBuilder(); for ( int i = 0; i < objects.Length; i++ ) { if ( i != 0 ) { sb.Append( " " ); } Stringify( objects[ i ], sb ); } LogMessage( sb.ToString() ); } public static void Error( params object[] objects) { var sb = new StringBuilder(); for ( int i = 0; i < objects.Length; i++ ) { if ( i != 0 ) { sb.Append( " " ); } Stringify( objects[ i ], sb ); } LogErrorMessage( sb.ToString() ); } } }