Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace callback with onLog #3307

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading