Skip to content

Commit

Permalink
Log pos (#3338)
Browse files Browse the repository at this point in the history
* change logs to include posInfos

* fix flash errors

* D'oh
  • Loading branch information
Geokureli authored Jan 25, 2025
1 parent b5a40eb commit 71c1d3e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
17 changes: 9 additions & 8 deletions flixel/graphics/frames/bmfont/BMFontXml.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flixel.graphics.frames.bmfont;

import flixel.FlxG;
import flixel.system.debug.log.LogStyle;
import haxe.PosInfos;

/**
* Helps providing a fast dot-syntax access to the most common `Xml` methods.
Expand Down Expand Up @@ -83,7 +84,7 @@ abstract BMFontXml(Xml) from Xml

private abstract NodeAccess(Xml) from Xml to Xml
{
inline function getHelper(name:String, ?invalid:(String)->Void):BMFontXml
inline function getHelper(name:String, ?invalid:(String, ?PosInfos)->Void):BMFontXml
{
final xml = this.elementsNamed(name).next();
if (xml == null)
Expand All @@ -102,7 +103,7 @@ private abstract NodeAccess(Xml) from Xml to Xml

public function get(name:String):BMFontXml
{
return getHelper(name, (msg)->throw msg);
return getHelper(name, (msg, ?_)->throw msg);
}

public function getWarn(name:String)
Expand All @@ -118,7 +119,7 @@ private abstract NodeAccess(Xml) from Xml to Xml

private abstract AttribAccess(Xml) from Xml to Xml
{
inline function stringHelper(name:String, ?invalid:(String)->Void, ?backup:String):String
inline function stringHelper(name:String, ?invalid:(String, ?PosInfos)->Void, ?backup:String):String
{
var value = backup;
if (this.nodeType == Xml.Document)
Expand All @@ -144,7 +145,7 @@ private abstract AttribAccess(Xml) from Xml to Xml

public function string(name:String)
{
return stringHelper(name, (msg)->throw msg);
return stringHelper(name, (msg, ?_)->throw msg);
}

public function stringWarn(name:String, ?backup:String)
Expand All @@ -157,7 +158,7 @@ private abstract AttribAccess(Xml) from Xml to Xml
return stringHelper(name, FlxG.log.error, backup);
}

inline function intHelper(name:String, ?invalid:(String)->Void, backup:Int):Int
inline function intHelper(name:String, ?invalid:(String, ?PosInfos)->Void, backup:Int):Int
{
var value = backup;
if (this.nodeType == Xml.Document)
Expand All @@ -183,7 +184,7 @@ private abstract AttribAccess(Xml) from Xml to Xml

public function int(name:String)
{
return intHelper(name, (msg)->throw msg, 0);
return intHelper(name, (msg, ?_)->throw msg, 0);
}

public function intWarn(name:String, backup:Int)
Expand All @@ -196,7 +197,7 @@ private abstract AttribAccess(Xml) from Xml to Xml
return intHelper(name, FlxG.log.error, backup);
}

inline function boolHelper(name:String, ?invalid:(String)->Void, backup:Bool):Bool
inline function boolHelper(name:String, ?invalid:(String, ?PosInfos)->Void, backup:Bool):Bool
{
var value = backup;
if (this.nodeType == Xml.Document)
Expand All @@ -222,7 +223,7 @@ private abstract AttribAccess(Xml) from Xml to Xml

public function bool(name:String)
{
return boolHelper(name, (msg)->throw msg, false);
return boolHelper(name, (msg, ?_)->throw msg, false);
}

public function boolWarn(name:String, backup:Bool)
Expand Down
7 changes: 4 additions & 3 deletions flixel/system/debug/log/LogStyle.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flixel.system.debug.log;

import flixel.util.FlxSignal;
import haxe.PosInfos;

using flixel.util.FlxStringUtil;

Expand Down Expand Up @@ -48,8 +49,8 @@ class LogStyle
* **Note:** Unlike the deprecated `callbackFunction`, this is called every time,
* even when logged with `once = true` and even in release mode.
*/
public final onLog = new FlxTypedSignal<(data:Any)->Void>();

public final onLog = new FlxTypedSignal<(data:Any, ?pos:PosInfos) -> Void>();
/**
* Whether an exception is thrown when this LogStyle is used.
* **Note**: Unlike other log style properties, this happens even in release mode.
Expand All @@ -74,7 +75,7 @@ class LogStyle
*/
@:haxe.warning("-WDeprecated")
public function new(prefix = "", color = "FFFFFF", size = 12, bold = false, italic = false, underlined = false,
?errorSound:String, openConsole = false, ?callbackFunction:()->Void, ?callback:(Any)->Void, throwException = false)
?errorSound:String, openConsole = false, ?callbackFunction:()->Void, ?callback:(Any, ?PosInfos)->Void, throwException = false)
{
this.prefix = prefix;
this.color = color;
Expand Down
30 changes: 15 additions & 15 deletions flixel/system/frontEnds/LogFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ class LogFrontEnd
public var redirectTraces(default, set):Bool = false;

var _standardTraceFunction:(Dynamic, ?PosInfos)->Void;

public inline function add(data:Dynamic):Void
public inline function add(data:Dynamic, ?pos:PosInfos):Void
{
advanced(data, LogStyle.NORMAL);
advanced(data, LogStyle.NORMAL, false, pos);
}

public inline function warn(data:Dynamic):Void
public inline function warn(data:Dynamic, ?pos:PosInfos):Void
{
advanced(data, LogStyle.WARNING, true);
advanced(data, LogStyle.WARNING, true, pos);
}

public inline function error(data:Dynamic):Void
public inline function error(data:Dynamic, ?pos:PosInfos):Void
{
advanced(data, LogStyle.ERROR, true);
advanced(data, LogStyle.ERROR, true, pos);
}

public inline function notice(data:Dynamic):Void
public inline function notice(data:Dynamic, ?pos:PosInfos):Void
{
advanced(data, LogStyle.NOTICE);
advanced(data, LogStyle.NOTICE, false, pos);
}

/**
* 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().
*
Expand All @@ -45,7 +45,7 @@ class LogFrontEnd
* @param fireOnce Whether you only want to log the Data in case it hasn't been added already
*/
@:haxe.warning("-WDeprecated")
public function advanced(data:Any, ?style:LogStyle, fireOnce = false):Void
public function advanced(data:Any, ?style:LogStyle, fireOnce = false, ?pos:PosInfos):Void
{
if (style == null)
style = LogStyle.NORMAL;
Expand Down Expand Up @@ -77,7 +77,7 @@ class LogFrontEnd
}
#end

style.onLog.dispatch(data);
style.onLog.dispatch(data, pos);

if (style.throwException)
throw style.toLogString(arrayData);
Expand Down

0 comments on commit 71c1d3e

Please sign in to comment.