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

FlxSubState: fix close() if used in two different states #1971

Merged
merged 2 commits into from
Oct 3, 2016

Conversation

JoeCreates
Copy link
Member

If you have persistent substates which you open from multiple parent states, you want the parent state of the substate to change even if the state has already been created, otherwise _parentState will be incorrect when you open the substate from a second location.

If you have persistent substates which you open from multiple parent states, you want the parent state of the substate to change even if the state has already been created, otherwise _parentState will be incorrect when you open the substate from a second location.
@Gama11
Copy link
Member

Gama11 commented Oct 2, 2016

Unit test? :)

@JoeCreates
Copy link
Member Author

JoeCreates commented Oct 2, 2016

I think it would be something like this:

@Test
    @:access(flixel.FlxSubState)
    function testOpenPersistentSubStateFromNewParent()
    {
        var state1 = new FlxState();
        var state2 = new FlxState();
        state1.destroySubStates = false;
        FlxG.state.switchTo(state1);
        step();
        FlxG.state.openSubState(subState1);
        step();

        Assert.areEqual(subState1._parentState, state1);

        subState1.close();
        step();
        FlxG.state.switchTo(state2);
        step();
        FlxG.state.openSubState(subState1);
        step();

        Assert.areEqual(subState1._parentState, state2);
    }

Could you possibly check this over and add it in if it's correct? I can't run hamcrest (I think because I need to change haxe version, which I can't do at the moment).

@Gama11
Copy link
Member

Gama11 commented Oct 3, 2016

I think you meant to call FlxG.switchState() instead of FlxG.state.switchTo()? The latter doesn't really do anything by default / isn't supposed to be called manually.

With that fixed, the test works.

It's a bit unusual to check the value of private fields though.. I usually check whatever effect that would have on the public API, in this case close() not working correctly I guess.

@Gama11 Gama11 added the Bug label Oct 3, 2016
@Gama11 Gama11 changed the title Subsate's parent should always be set upon opening FlxSubState: fix close() if used in two different states Oct 3, 2016
@Gama11 Gama11 merged commit 51478ef into HaxeFlixel:dev Oct 3, 2016
@Gama11
Copy link
Member

Gama11 commented Oct 3, 2016

Thanks!

Aurel300 pushed a commit to larsiusprime/haxeflixel that referenced this pull request Apr 18, 2018
…1971)

If you have persistent substates which you open from multiple parent states, you want the parent state of the substate to change even if the state has already been created, otherwise _parentState will be incorrect when you open the substate from a second location.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants