Skip to content

Commit

Permalink
replace callback with onLog (#3307)
Browse files Browse the repository at this point in the history
* replace callback with onLog

* update changelog
  • Loading branch information
Geokureli authored Dec 9, 2024
1 parent b247edb commit 2f1e446
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- `FlxAnimationController`: Add `onLoop`, `onFrameChange` and `onFinish`, to replace `callback` and `finishCallback` ([#3205](https://github.com/HaxeFlixel/flixel/pull/3205)) ([#3216](https://github.com/HaxeFlixel/flixel/pull/3216))
- `FlxStrip`: Add support for blendmodes ([#3213](https://github.com/HaxeFlixel/flixel/pull/3213))
- `FlxTextBorderStyle`: Add SHADOW_XY, prevent border clipping ([#3236](https://github.com/HaxeFlixel/flixel/pull/3236))
- `LogStyle`: Add `callback` to replace `callbackFunction` ([#3239](https://github.com/HaxeFlixel/flixel/pull/3239))
- `LogStyle`: Add `onLog` signal to replace `callbackFunction` ([#3239](https://github.com/HaxeFlixel/flixel/pull/3239))([#3307](https://github.com/HaxeFlixel/flixel/pull/3307))
- `FlxBar`: Add custom border sizes ([#3234](https://github.com/HaxeFlixel/flixel/pull/3234))
- Gamepads: Add `acceptMode` and "mapped inputs" ([#3276](https://github.com/HaxeFlixel/flixel/pull/3276)) ([#3280](https://github.com/HaxeFlixel/flixel/pull/3280))
- Add `ACCEPT` and `CANCEL` input IDs that conditionally map to either `A` or `B` depending on `FlxG.gamepads.acceptMode`
Expand Down
9 changes: 7 additions & 2 deletions flixel/system/debug/log/LogStyle.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package flixel.system.debug.log;

import flixel.util.FlxSignal;

using flixel.util.FlxStringUtil;

/**
Expand Down Expand Up @@ -43,8 +45,10 @@ class LogStyle

/**
* A callback function that is called when this LogStyle is used
* **Note:** Unlike the deprecated `callbackFunction`, this is called every time,
* even when logged with `once = true` and even in release mode.
*/
public var callback:(data:Any)->Void;
public final onLog = new FlxTypedSignal<(data:Any)->Void>();

/**
* Whether an exception is thrown when this LogStyle is used.
Expand Down Expand Up @@ -81,7 +85,8 @@ class LogStyle
this.errorSound = errorSound;
this.openConsole = openConsole;
this.callbackFunction = callbackFunction;
this.callback = callback;
if (callback != null)
onLog.add(callback);
this.throwException = throwException;
}

Expand Down
14 changes: 6 additions & 8 deletions flixel/system/frontEnds/LogFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ class LogFrontEnd
if (style == null)
style = LogStyle.NORMAL;

if (!(data is Array))
data = [data];
final arrayData = (!(data is Array) ? [data] : cast 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);
_standardTraceFunction(arrayData);
}
else if (FlxG.game.debugger.log.add(data, style, fireOnce))
else if (FlxG.game.debugger.log.add(arrayData, style, fireOnce))
{
#if (FLX_SOUND_SYSTEM && !FLX_UNIT_TEST)
if (style.errorSound != null)
Expand All @@ -75,14 +74,13 @@ class LogFrontEnd

if (style.callbackFunction != null)
style.callbackFunction();

if (style.callback != null)
style.callback(data);
}
#end

style.onLog.dispatch(data);

if (style.throwException)
throw style.toLogString(data);
throw style.toLogString(arrayData);
}

/**
Expand Down

0 comments on commit 2f1e446

Please sign in to comment.