Exemplo n.º 1
0
def test_pushing_substage():
    global entry_data
    entry_data = None
    global exit_data
    exit_data = None

    class TestStage(Stage):
        def enter(self, data):
            global entry_data
            entry_data = 'stage'

        def exit(self, data):
            global exit_data
            exit_data = 'stage'

        def exit_to_substage(self, substage, data):
            global exit_data
            exit_data = 'stage'

        def reenter_from_substage(self, substage, data):
            global entry_data
            entry_data = 'stage'

    class TestSubstage(Stage):
        def enter(self, data):
            global entry_data
            entry_data = 'substage'

        def exit(self, data):
            global exit_data
            exit_data = 'substage'

        def exit_to_substage(self, data):
            global exit_data
            exit_data = 'substage'

        def reenter_from_substage(self, substage, data):
            global entry_data
            entry_data = 'substage'

    flow = Flow(
        stages=dict(test=TestStage()),
        substages=dict(test_substage=TestSubstage()),
        initial_stage='test',
    )
    assert exit_data is None
    assert entry_data == 'stage'
    assert flow.get_current_substage() is None

    flow.push_substage('test_substage')
    assert exit_data == 'stage'
    assert entry_data == 'substage'
    assert flow.get_current_substage() == 'test_substage'

    flow.pop_substage()
    assert exit_data == 'substage'
    assert entry_data == 'stage'
    assert flow.get_current_substage() is None
Exemplo n.º 2
0
def test_create_flow_with_initial_stage():
    class TestStage():
        def enter(self, data):
            pass

        def exit(self):
            pass

    flow = Flow(
        stages=dict(test=TestStage()),
        initial_stage='test',
    )

    assert flow.get_current_stage() is 'test'
    assert set(flow.get_stages()) == set(['test'])
Exemplo n.º 3
0
def test_transition_entry():
    test_data = 'foo'
    global passed_data
    passed_data = None

    class TestStage(Stage):
        def enter(self, data):
            global passed_data
            passed_data = data

    flow = Flow(
        stages=dict(test=TestStage()),
        initial_stage='test',
        initial_stage_data=test_data,
    )

    assert passed_data == test_data
    assert flow.get_current_stage() == 'test'
Exemplo n.º 4
0
def test_transition_entry():
    global has_exited
    has_exited = False

    exit_data = 'foo_bar_baz'
    global entry_data
    entry_data = None

    class TestStage(Stage):
        def enter(self, data):
            global entry_data
            entry_data = data

        def exit(self, data):
            global has_exited
            has_exited = True
            return exit_data

    flow = Flow(
        stages=dict(
            test_a=TestStage(),
            test_b=TestStage(),
        ),
        initial_stage='test_a',
    )

    assert flow.get_current_stage() == 'test_a'
    assert entry_data is None
    assert not has_exited

    flow.transition('test_b')

    assert flow.get_current_stage() == 'test_b'
    assert entry_data == exit_data
    assert has_exited
Exemplo n.º 5
0
def test_create_flow_bare():
    flow = Flow()

    assert flow.get_current_stage() is None
    assert set(flow.get_stages()) == set([])
Exemplo n.º 6
0
def test_create_flow_with_stage():
    flow = Flow(stages=dict(test=Stage()))

    assert flow.get_current_stage() is None
    assert set(flow.get_stages()) == set(['test'])
Exemplo n.º 7
0
def test_create_flow_and_add_stage():
    flow = Flow()
    flow.add_stage('test', Stage())

    assert flow.get_current_stage() is None
    assert set(flow.get_stages()) == set(['test'])
Exemplo n.º 8
0
    def main(self):
        base.flow.push_substage('are_you_sure', 'main')

    def quit(self):
        base.flow.push_substage('are_you_sure', 'quit')

    def back(self):
        base.flow.pop_substage()


base.flow = Flow(
    stages=dict(
        splashes=StartupSplashes(exit_stage='main_menu'),
        main_menu=MainMenu(),
        main_game_loop=MainGameLoop(),
        main_credits=StartupSplashes(exit_stage='main_menu'),
        quit=Quit(),
    ),
    substages=dict(
        are_you_sure=AreYouSure(),
        ingame_menu=IngameMenu(),
    ),
    initial_stage='splashes',
)
## Alternative to the above:
#base.flow = Flow()
#base.flow.add_stage('splashes', StartupSplashes(exit_stage='quit'))
#base.flow.add_stage('quit', Quit())
#base.flow.transition('splashes', None)
base.run()
Exemplo n.º 9
0
        exit_stage='main_game_stage',
        splash_args=dict(
            pattern=Pattern.WHEEL,
            colors=Colors.RAINBOW,
            pattern_freq=1,
            cycle_freq=5,
        ),
    ),
    main_game_stage=MainGameStage(),
    quit=Quit(),
    debug=BorderlessFullscreenMouseHidden(exit_stage='main_game_stage', ),
)

parser = argparse.ArgumentParser(
    description="",  # STARTPROJECT: Textual description for --help
)
parser.add_argument(
    "-s",
    "--stage",
    type=str,
    default='start',
    help="Name of the stage to start the game on",
    choices=stages.keys(),
)
args = parser.parse_args()

base.flow = Flow(
    stages=stages,
    initial_stage=args.stage,
)
Exemplo n.º 10
0
    def exit(self, data):
        for btn in self.buttons:
            btn.destroy()
        return data

    def repeat(self):
        base.flow.transition('splashes')

    def quit(self):
        base.flow.transition('quit')


ShowBase()
base.flow = Flow(
    stages=dict(
        splashes=Panda3DSplash(
            exit_stage='repeat',
            splash_args=dict(
                pattern=Pattern.WHEEL,
                colors=Colors.RAINBOW,
                pattern_freq=1,
                cycle_freq=5,
            ),
        ),
        repeat=Repeat(),
        quit=Quit(),
    ),
    initial_stage='splashes',
)
base.run()