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

add SignalFrontEnd.preGameStart #2188

Merged
merged 11 commits into from
Nov 21, 2018
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
7 changes: 5 additions & 2 deletions flixel/FlxGame.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class FlxGame extends Sprite
public var filtersEnabled:Bool = true;

/**
* A flag for triggering the `gameStarted` "event".
* A flag for triggering the `preGameStart` and `postGameStart` "events".
*/
@:allow(flixel.system.FlxSplash)
var _gameJustStarted:Bool = false;
Expand Down Expand Up @@ -622,6 +622,9 @@ class FlxGame extends Sprite
// Finally assign and create the new state
_state = _requestedState;

if (_gameJustStarted)
FlxG.signals.preGameStart.dispatch();

FlxG.signals.preStateCreate.dispatch(_state);

_state.create();
Expand All @@ -636,7 +639,7 @@ class FlxGame extends Sprite

function gameStart():Void
{
FlxG.signals.gameStarted.dispatch();
FlxG.signals.postGameStart.dispatch();
_gameJustStarted = false;
}

Expand Down
4 changes: 2 additions & 2 deletions flixel/input/mouse/FlxMouse.hx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
#end

_cursorBitmapData = FlxDestroyUtil.dispose(_cursorBitmapData);
FlxG.signals.gameStarted.remove(onGameStart);
FlxG.signals.postGameStart.remove(onGameStart);
}

/**
Expand Down Expand Up @@ -422,7 +422,7 @@ class FlxMouse extends FlxPointer implements IFlxInputManager

_stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);

FlxG.signals.gameStarted.add(onGameStart);
FlxG.signals.postGameStart.add(onGameStart);
Mouse.hide();
}

Expand Down
13 changes: 12 additions & 1 deletion flixel/system/frontEnds/SignalFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ class SignalFrontEnd
public var gameResized(default, null):FlxTypedSignal<Int->Int->Void> = new FlxTypedSignal<Int->Int->Void>();
public var preGameReset(default, null):FlxSignal = new FlxSignal();
public var postGameReset(default, null):FlxSignal = new FlxSignal();
/**
* Gets dispatched just before the game is started (before the first state after the splash screen is created)
*/
public var preGameStart(default, null):FlxSignal = new FlxSignal();
/**
* Gets dispatched when the game is started (first state after the splash screen).
*/
public var gameStarted(default, null):FlxSignal = new FlxSignal();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks backwards compatibility. Perhaps we could keep a dummy gameStarted property with (get, never) access, marked as @:deprecated. The getter would simply "redirect" to postGameStart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I've added your suggestion to the branch.

public var postGameStart(default, null):FlxSignal = new FlxSignal();
@:deprecated("Use postGameStart instead of gameStarted")
public var gameStarted(get, never):FlxSignal;
public var preUpdate(default, null):FlxSignal = new FlxSignal();
public var postUpdate(default, null):FlxSignal = new FlxSignal();
public var preDraw(default, null):FlxSignal = new FlxSignal();
Expand All @@ -29,4 +35,9 @@ class SignalFrontEnd

@:allow(flixel.FlxG)
function new() {}

function get_gameStarted():FlxSignal
{
return postGameStart;
}
}