Skip to content

Commit

Permalink
add FlxG.watch.addFunction (#2500)
Browse files Browse the repository at this point in the history
* add `FlxG.watch.addFunction`

* update changelog
  • Loading branch information
Geokureli authored May 10, 2022
1 parent 46956ca commit 3016dc1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
- `FlxPath`: added `immovable` bool (previously object were always immovable when following paths) ([#2480](https://github.com/HaxeFlixel/flixel/pull/2480))
- `FlxPathDrawData`: added `myFlxPath.debugDrawData` to allow custom colors and draw properties ([#2480](https://github.com/HaxeFlixel/flixel/pull/2480))
- `FlxAxes`: added `x` and `y` getters and `NONE` value ([#2480](https://github.com/HaxeFlixel/flixel/pull/2480))
- `FlxTween`: added `ShakeTween` and `FlxTween.shake()` helper ([#2549](https://github.com/HaxeFlixel/flixel/pull/2549))
- `FlxTween`: added `ShakeTween` and `FlxTween.shake()` helper ([#2549](https://github.com/HaxeFlixel/flixel/pull/2549))
- `WatchFrontEnd`: added `FlxG.watch.addFunction` ([#2500](https://github.com/HaxeFlixel/flixel/pull/2500))

#### Bugfixes:

Expand Down
2 changes: 2 additions & 0 deletions flixel/system/debug/watch/Watch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Watch extends Window
displayName.isNullOrEmpty();
case EXPRESSION(expression, _):
expression.isNullOrEmpty();
case FUNCTION(func):
func == null;
}
}

Expand Down
4 changes: 4 additions & 0 deletions flixel/system/debug/watch/WatchEntry.hx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class WatchEntry extends Sprite implements IFlxDestroyable
case FIELD(_, _): 0xFFFFFF;
case QUICK(_): 0xA5F1ED;
case EXPRESSION(_, _): 0xC4FE83;
case FUNCTION(_): 0xF1A5A5;
}
}

Expand Down Expand Up @@ -96,6 +97,7 @@ class WatchEntry extends Sprite implements IFlxDestroyable
case EXPRESSION(expression, _):
setNameText(expression);
case QUICK(_):
case FUNCTION(_):
}
}

Expand All @@ -120,6 +122,8 @@ class WatchEntry extends Sprite implements IFlxDestroyable
#end
case QUICK(value):
value;
case FUNCTION(func):
func();
}
}

Expand Down
5 changes: 5 additions & 0 deletions flixel/system/debug/watch/WatchEntryData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ enum WatchEntryData
* Haxe expression evaluated with hscript.
*/
EXPRESSION(expression:String, parsedExpr:#if hscript Expr #else String #end);

/**
* A function that returns the value to display.
*/
FUNCTION(func:()->Dynamic);
}
14 changes: 14 additions & 0 deletions flixel/system/frontEnds/WatchFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ class WatchFrontEnd
FlxG.game.debugger.watch.remove(displayName, null);
#end
}

public function addFunction(displayName:String, func:()->Dynamic):Void
{
#if FLX_DEBUG
FlxG.game.debugger.watch.add(displayName, FUNCTION(func));
#end
}

public function removeFunction(displayName:String):Void
{
#if FLX_DEBUG
FlxG.game.debugger.watch.remove(displayName, null);
#end
}

/**
* Add the mouse coords to the watch window. Useful for quickly
Expand Down

0 comments on commit 3016dc1

Please sign in to comment.