From 1b567cf6e1d85bb21eca7aca60c3a264a2a48b7b Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 15 Jun 2023 14:25:54 -0500 Subject: [PATCH 1/6] docs + formatting --- flixel/system/debug/log/LogStyle.hx | 56 +++++++++++----------- flixel/system/frontEnds/LogFrontEnd.hx | 66 +++++++++++++------------- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/flixel/system/debug/log/LogStyle.hx b/flixel/system/debug/log/LogStyle.hx index e7c955a0da..5ca2d30976 100644 --- a/flixel/system/debug/log/LogStyle.hx +++ b/flixel/system/debug/log/LogStyle.hx @@ -1,7 +1,7 @@ package flixel.system.debug.log; /** - * A class that allows you to create a custom style for FlxG.log.advanced(). + * A class that allows you to create a custom style for `FlxG.log.advanced()`. * Also used internally for the pre-defined styles. */ class LogStyle @@ -13,7 +13,7 @@ class LogStyle public static var CONSOLE:LogStyle = new LogStyle("> ", "5A96FA", 12, false); /** - * A prefix which is always attached to the start of the logged data. + * A prefix which is always attached to the start of the logged data */ public var prefix:String; @@ -24,44 +24,46 @@ class LogStyle public var underlined:Bool; /** - * A sound to be played when this LogStyle is used. + * A sound to be played when this LogStyle is used */ public var errorSound:String; /** - * Whether the console should be forced to open when this LogStyle is used. + * Whether the console should be forced to open when this LogStyle is used */ public var openConsole:Bool; /** - * A callback function that is called when this LogStyle is used. + * A callback function that is called when this LogStyle is used */ - public var callbackFunction:Void->Void; + public var callbackFunction:()->Void; /** - * Create a new LogStyle to be used in conjunction with FlxG.log.advanced() + * Create a new LogStyle to be used in conjunction with `FlxG.log.advanced()` * - * @param Prefix A prefix which is always attached to the start of the logged data. - * @param Color The text color. - * @param Size The text size. - * @param Bold Whether the text is bold or not. - * @param Italic Whether the text is italic or not. - * @param Underlined Whether the text is underlined or not. - * @param ErrorSound A sound to be played when this LogStyle is used. - * @param OpenConsole Whether the console should be forced to open when this LogStyle is used. - * @param CallbackFunction A callback function that is called when this LogStyle is used. + * @param prefix A prefix which is always attached to the start of the logged data + * @param color The text color + * @param size The text size + * @param bold Whether the text is bold or not + * @param italic Whether the text is italic or not + * @param underlined Whether the text is underlined or not + * @param errorSound A sound to be played when this LogStyle is used + * @param openConsole Whether the console should be forced to open when this LogStyle is used + * @param callback A callback function that is called when this LogStyle is used + * @param throwError Whether an error is thrown when this LogStyle is used */ - public function new(Prefix:String = "", Color:String = "FFFFFF", Size:Int = 12, Bold:Bool = false, Italic:Bool = false, Underlined:Bool = false, - ?ErrorSound:String, OpenConsole:Bool = false, ?CallbackFunction:Void->Void) + public function new(prefix = "", color = "FFFFFF", size = 12, bold = false, italic = false, underlined = false, + ?errorSound:String, openConsole = false, ?callback:()->Void, throwError = false) { - prefix = Prefix; - color = Color; - size = Size; - bold = Bold; - italic = Italic; - underlined = Underlined; - errorSound = ErrorSound; - openConsole = OpenConsole; - callbackFunction = CallbackFunction; + this.prefix = prefix; + this.color = color; + this.size = size; + this.bold = bold; + this.italic = italic; + this.underlined = underlined; + this.errorSound = errorSound; + this.openConsole = openConsole; + this.callbackFunction = callback; + this.throwError = throwError; } } diff --git a/flixel/system/frontEnds/LogFrontEnd.hx b/flixel/system/frontEnds/LogFrontEnd.hx index 05cc1b1012..bdc3f9d6bc 100644 --- a/flixel/system/frontEnds/LogFrontEnd.hx +++ b/flixel/system/frontEnds/LogFrontEnd.hx @@ -16,69 +16,69 @@ class LogFrontEnd */ public var redirectTraces(default, set):Bool = false; - var _standardTraceFunction:Dynamic->?PosInfos->Void; + var _standardTraceFunction:(Dynamic, ?PosInfos)->Void; - public inline function add(Data:Dynamic):Void + public inline function add(data:Dynamic):Void { #if FLX_DEBUG - advanced(Data, LogStyle.NORMAL); + advanced(data, LogStyle.NORMAL); #end } - public inline function warn(Data:Dynamic):Void + public inline function warn(data:Dynamic):Void { #if FLX_DEBUG - advanced(Data, LogStyle.WARNING, true); + advanced(data, LogStyle.WARNING, true); #end } - public inline function error(Data:Dynamic):Void + public inline function error(data:Dynamic):Void { #if FLX_DEBUG - advanced(Data, LogStyle.ERROR, true); + advanced(data, LogStyle.ERROR, true); #end } - public inline function notice(Data:Dynamic):Void + public inline function notice(data:Dynamic):Void { #if FLX_DEBUG - advanced(Data, LogStyle.NOTICE); + advanced(data, LogStyle.NOTICE); #end } /** * Add an advanced log message to the debugger by also specifying a LogStyle. Backend to FlxG.log.add(), FlxG.log.warn(), FlxG.log.error() and FlxG.log.notice(). * - * @param Data Any Data to log. - * @param Style The LogStyle to use, for example LogStyle.WARNING. You can also create your own by importing the LogStyle class. - * @param FireOnce Whether you only want to log the Data in case it hasn't been added already + * @param data Any Data to log. + * @param style The LogStyle to use, for example LogStyle.WARNING. You can also create your own by importing the LogStyle class. + * @param fireOnce Whether you only want to log the Data in case it hasn't been added already */ - public function advanced(Data:Dynamic, ?Style:LogStyle, FireOnce:Bool = false):Void + public function advanced(data:Dynamic, ?style:LogStyle, fireOnce:Bool = false):Void { #if FLX_DEBUG // Check null game since `FlxG.save.bind` may be called before `new FlxGame` if (FlxG.game == null || FlxG.game.debugger == null) { - _standardTraceFunction(Data); + _standardTraceFunction(data); return; } - if (Style == null) + if (style == null) { - Style = LogStyle.NORMAL; + style = LogStyle.NORMAL; } - if (!(Data is Array)) + if (!(data is Array)) { - Data = [Data]; + data = [data]; } - if (FlxG.game.debugger.log.add(Data, Style, FireOnce)) + if (FlxG.game.debugger.log.add(data, style, fireOnce)) { #if (FLX_SOUND_SYSTEM && !FLX_UNIT_TEST) - if (Style.errorSound != null) + if (style.errorSound != null) { - var sound = FlxAssets.getSound(Style.errorSound); + var sound = FlxAssets.getSound(style.errorSound); if (sound != null) { FlxG.sound.load(sound).play(); @@ -86,14 +86,14 @@ class LogFrontEnd } #end - if (Style.openConsole) + if (style.openConsole) { FlxG.debugger.visible = true; } - if (Style.callbackFunction != null) + if (style.callbackFunction != null) { - Style.callbackFunction(); + style.callbackFunction(); } } #end @@ -115,25 +115,25 @@ class LogFrontEnd _standardTraceFunction = haxe.Log.trace; } - inline function set_redirectTraces(Redirect:Bool):Bool + inline function set_redirectTraces(redirect:Bool):Bool { - Log.trace = (Redirect) ? processTraceData : _standardTraceFunction; - return redirectTraces = Redirect; + Log.trace = (redirect) ? processTraceData : _standardTraceFunction; + return redirectTraces = redirect; } /** * Internal function used as a interface between trace() and add(). * - * @param Data The data that has been traced - * @param Inf Information about the position at which trace() was called + * @param data The data that has been traced + * @param info Information about the position at which trace() was called */ - function processTraceData(Data:Dynamic, ?Info:PosInfos):Void + function processTraceData(data:Dynamic, ?info:PosInfos):Void { - var paramArray:Array = [Data]; + var paramArray:Array = [data]; - if (Info.customParams != null) + if (info.customParams != null) { - for (i in Info.customParams) + for (i in info.customParams) { paramArray.push(i); } From b97ed3434f47a5aee0f9874ec860c2c761b3c9fb Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 15 Jun 2023 15:35:39 -0500 Subject: [PATCH 2/6] docs + formatting --- flixel/system/debug/log/Log.hx | 38 ++++++++++---------------- flixel/system/debug/log/LogStyle.hx | 32 ++++++++++++++++++++++ flixel/system/frontEnds/LogFrontEnd.hx | 10 +++---- 3 files changed, 51 insertions(+), 29 deletions(-) diff --git a/flixel/system/debug/log/Log.hx b/flixel/system/debug/log/Log.hx index cad862e7f6..fa1bc8230c 100644 --- a/flixel/system/debug/log/Log.hx +++ b/flixel/system/debug/log/Log.hx @@ -17,7 +17,7 @@ class Log extends Window var _lines:Array; /** - * Creates a log window object. + * Creates a log window object */ public function new() { @@ -37,7 +37,7 @@ class Log extends Window } /** - * Clean up memory. + * Clean up memory */ override public function destroy():Void { @@ -53,37 +53,27 @@ class Log extends Window /** * Adds a new line to the log window. - * @param Data The data being logged. - * @param Style The LogStyle to be used for the log - * @param FireOnce Whether you only want to log the Data in case it hasn't been added already + * + * @param data The data being logged + * @param style The LogStyle to be used + * @param fireOnce If true, the log history is checked for matching logs */ - public function add(Data:Array, Style:LogStyle, FireOnce:Bool = false):Bool + public function add(data:Array, style:LogStyle, fireOnce = false):Bool { - if (Data == null) + if (data == null) { return false; } - - var texts:Array = new Array(); - - // Format FlxPoints, Arrays, Maps or turn the Data entry into a String - for (i in 0...Data.length) - { - texts[i] = Std.string(Data[i]); - - // Make sure you can't insert html tags - texts[i] = StringTools.htmlEscape(texts[i]); - } - - var text:String = Style.prefix + texts.join(" "); - + // Apply text formatting #if (!js && !lime_console) - text = flixel.util.FlxStringUtil.htmlFormat(text, Style.size, Style.color, Style.bold, Style.italic, Style.underlined); + final text = style.toHtmlString(data); + #else + final text = style.toLogString(data); #end - + // Check if the text has been added yet already - if (FireOnce) + if (fireOnce) { for (line in _lines) { diff --git a/flixel/system/debug/log/LogStyle.hx b/flixel/system/debug/log/LogStyle.hx index 5ca2d30976..bc64dee55f 100644 --- a/flixel/system/debug/log/LogStyle.hx +++ b/flixel/system/debug/log/LogStyle.hx @@ -1,5 +1,7 @@ package flixel.system.debug.log; +using flixel.util.FlxStringUtil; + /** * A class that allows you to create a custom style for `FlxG.log.advanced()`. * Also used internally for the pre-defined styles. @@ -66,4 +68,34 @@ class LogStyle this.callbackFunction = callback; this.throwError = throwError; } + + /** + * Converts the data into a log message according to this style. + * + * @param data The data being logged + */ + public function toLogString(data:Array) + { + // Format FlxPoints, Arrays, Maps or turn the data entry into a String + final texts = new Array(); + for (i in 0...data.length) + { + final text = Std.string(data[i]); + + // Make sure you can't insert html tags + texts.push(StringTools.htmlEscape(text)); + } + + return prefix + texts.join(" "); + } + + /** + * Converts the data into an html log message according to this style. + * + * @param data The data being logged + */ + public inline function toHtmlString(data:Array) + { + return toLogString(data).htmlFormat(size, color, bold, italic, underlined); + } } diff --git a/flixel/system/frontEnds/LogFrontEnd.hx b/flixel/system/frontEnds/LogFrontEnd.hx index bdc3f9d6bc..b106725a5e 100644 --- a/flixel/system/frontEnds/LogFrontEnd.hx +++ b/flixel/system/frontEnds/LogFrontEnd.hx @@ -49,9 +49,9 @@ class LogFrontEnd /** * Add an advanced log message to the debugger by also specifying a LogStyle. Backend to FlxG.log.add(), FlxG.log.warn(), FlxG.log.error() and FlxG.log.notice(). * - * @param data Any Data to log. - * @param style The LogStyle to use, for example LogStyle.WARNING. You can also create your own by importing the LogStyle class. - * @param fireOnce Whether you only want to log the Data in case it hasn't been added already + * @param data Any Data to log. + * @param style The LogStyle to use, for example LogStyle.WARNING. You can also create your own by importing the LogStyle class. + * @param fireOnce Whether you only want to log the Data in case it hasn't been added already */ public function advanced(data:Dynamic, ?style:LogStyle, fireOnce:Bool = false):Void { @@ -124,8 +124,8 @@ class LogFrontEnd /** * Internal function used as a interface between trace() and add(). * - * @param data The data that has been traced - * @param info Information about the position at which trace() was called + * @param data The data that has been traced + * @param info Information about the position at which trace() was called */ function processTraceData(data:Dynamic, ?info:PosInfos):Void { From e70ff456e260fad7c13c1e45959a5981663a91ea Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 15 Jun 2023 15:37:33 -0500 Subject: [PATCH 3/6] add logStyle.throwError --- flixel/system/debug/log/LogStyle.hx | 6 ++++++ flixel/system/frontEnds/LogFrontEnd.hx | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/flixel/system/debug/log/LogStyle.hx b/flixel/system/debug/log/LogStyle.hx index bc64dee55f..6fa5fae864 100644 --- a/flixel/system/debug/log/LogStyle.hx +++ b/flixel/system/debug/log/LogStyle.hx @@ -40,6 +40,12 @@ class LogStyle */ public var callbackFunction:()->Void; + /** + * Whether an error is thrown when this LogStyle is used + * @since 5.4.0 + */ + public var throwError:Bool = false; + /** * Create a new LogStyle to be used in conjunction with `FlxG.log.advanced()` * diff --git a/flixel/system/frontEnds/LogFrontEnd.hx b/flixel/system/frontEnds/LogFrontEnd.hx index b106725a5e..cee0a9df18 100644 --- a/flixel/system/frontEnds/LogFrontEnd.hx +++ b/flixel/system/frontEnds/LogFrontEnd.hx @@ -95,6 +95,11 @@ class LogFrontEnd { style.callbackFunction(); } + + if (style.throwError) + { + throw style.toLogString(data); + } } #end } From 9a1fa1dc42a7fc97f6a865e570326505721dc4a3 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 15 Jun 2023 15:54:39 -0500 Subject: [PATCH 4/6] remove import --- flixel/system/frontEnds/LogFrontEnd.hx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flixel/system/frontEnds/LogFrontEnd.hx b/flixel/system/frontEnds/LogFrontEnd.hx index cee0a9df18..12b73d8e74 100644 --- a/flixel/system/frontEnds/LogFrontEnd.hx +++ b/flixel/system/frontEnds/LogFrontEnd.hx @@ -3,7 +3,6 @@ package flixel.system.frontEnds; import flixel.FlxG; import flixel.system.debug.log.LogStyle; import flixel.system.FlxAssets; -import haxe.Log; import haxe.PosInfos; /** @@ -122,7 +121,7 @@ class LogFrontEnd inline function set_redirectTraces(redirect:Bool):Bool { - Log.trace = (redirect) ? processTraceData : _standardTraceFunction; + haxe.Log.trace = (redirect) ? processTraceData : _standardTraceFunction; return redirectTraces = redirect; } From 5e228af4bc6d89401a5c38b38fbb79efaba190d6 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 15 Jun 2023 16:12:28 -0500 Subject: [PATCH 5/6] throw even on release mode --- flixel/system/frontEnds/LogFrontEnd.hx | 50 ++++++++------------------ 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/flixel/system/frontEnds/LogFrontEnd.hx b/flixel/system/frontEnds/LogFrontEnd.hx index 12b73d8e74..689778b291 100644 --- a/flixel/system/frontEnds/LogFrontEnd.hx +++ b/flixel/system/frontEnds/LogFrontEnd.hx @@ -19,30 +19,22 @@ class LogFrontEnd public inline function add(data:Dynamic):Void { - #if FLX_DEBUG advanced(data, LogStyle.NORMAL); - #end } public inline function warn(data:Dynamic):Void { - #if FLX_DEBUG advanced(data, LogStyle.WARNING, true); - #end } public inline function error(data:Dynamic):Void { - #if FLX_DEBUG advanced(data, LogStyle.ERROR, true); - #end } public inline function notice(data:Dynamic):Void { - #if FLX_DEBUG advanced(data, LogStyle.NOTICE); - #end } /** @@ -52,55 +44,41 @@ class LogFrontEnd * @param style The LogStyle to use, for example LogStyle.WARNING. You can also create your own by importing the LogStyle class. * @param fireOnce Whether you only want to log the Data in case it hasn't been added already */ - public function advanced(data:Dynamic, ?style:LogStyle, fireOnce:Bool = false):Void + public function advanced(data:Dynamic, ?style:LogStyle, fireOnce = false):Void { + if (style == null) + style = LogStyle.NORMAL; + + if (!(data is Array)) + data = [data]; + #if FLX_DEBUG // Check null game since `FlxG.save.bind` may be called before `new FlxGame` if (FlxG.game == null || FlxG.game.debugger == null) { _standardTraceFunction(data); - return; - } - - if (style == null) - { - style = LogStyle.NORMAL; } - - if (!(data is Array)) - { - data = [data]; - } - - if (FlxG.game.debugger.log.add(data, style, fireOnce)) + else if (FlxG.game.debugger.log.add(data, style, fireOnce)) { #if (FLX_SOUND_SYSTEM && !FLX_UNIT_TEST) if (style.errorSound != null) { - var sound = FlxAssets.getSound(style.errorSound); + final sound = FlxAssets.getSound(style.errorSound); if (sound != null) - { FlxG.sound.load(sound).play(); - } } #end - + if (style.openConsole) - { FlxG.debugger.visible = true; - } - + if (style.callbackFunction != null) - { style.callbackFunction(); - } - - if (style.throwError) - { - throw style.toLogString(data); - } } #end + + if (style.throwError) + throw style.toLogString(data); } /** From 7b825694cf1d3727a568d33dbdaeddfa3849f0de Mon Sep 17 00:00:00 2001 From: George FunBook Date: Thu, 15 Jun 2023 16:16:27 -0500 Subject: [PATCH 6/6] rename error to exception, throw on release --- flixel/system/debug/log/LogStyle.hx | 9 +++++---- flixel/system/frontEnds/LogFrontEnd.hx | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/flixel/system/debug/log/LogStyle.hx b/flixel/system/debug/log/LogStyle.hx index 6fa5fae864..99d0efcb18 100644 --- a/flixel/system/debug/log/LogStyle.hx +++ b/flixel/system/debug/log/LogStyle.hx @@ -41,10 +41,11 @@ class LogStyle public var callbackFunction:()->Void; /** - * Whether an error is thrown when this LogStyle is used + * Whether an exception is thrown when this LogStyle is used. + * **Note**: Unlike other log style properties, this happens even in release mode. * @since 5.4.0 */ - public var throwError:Bool = false; + public var throwException:Bool = false; /** * Create a new LogStyle to be used in conjunction with `FlxG.log.advanced()` @@ -61,7 +62,7 @@ class LogStyle * @param throwError Whether an error is thrown when this LogStyle is used */ public function new(prefix = "", color = "FFFFFF", size = 12, bold = false, italic = false, underlined = false, - ?errorSound:String, openConsole = false, ?callback:()->Void, throwError = false) + ?errorSound:String, openConsole = false, ?callback:()->Void, throwException = false) { this.prefix = prefix; this.color = color; @@ -72,7 +73,7 @@ class LogStyle this.errorSound = errorSound; this.openConsole = openConsole; this.callbackFunction = callback; - this.throwError = throwError; + this.throwException = throwException; } /** diff --git a/flixel/system/frontEnds/LogFrontEnd.hx b/flixel/system/frontEnds/LogFrontEnd.hx index 689778b291..05765bb39b 100644 --- a/flixel/system/frontEnds/LogFrontEnd.hx +++ b/flixel/system/frontEnds/LogFrontEnd.hx @@ -77,7 +77,7 @@ class LogFrontEnd } #end - if (style.throwError) + if (style.throwException) throw style.toLogString(data); }