diff --git a/director_test.go b/director_test.go index f91d3bb..a131ca8 100644 --- a/director_test.go +++ b/director_test.go @@ -78,3 +78,48 @@ func TestSceneDirector_ProcessTriggerWithTransitionAwareness(t *testing.T) { rule.Transition.End() assert.Equal(t, rule.Dest, director.current) } + +func TestSceneDirector_ProcessTriggerCancelling(t *testing.T) { + mockScene := &MockScene{} + mockTransition := &baseTransitionImplementation{} + ruleSet := make(map[Scene[int]][]Directive[int]) + + director := NewSceneDirector[int](mockScene, 1, ruleSet) + + rule := Directive[int]{Dest: &MockScene{}, Trigger: 2, Transition: mockTransition} + ruleSet[mockScene] = []Directive[int]{rule} + director.ProcessTrigger(2) + + // Assert transition is running + assert.Equal(t, rule.Transition, director.current) + + director.ProcessTrigger(1) + assert.Equal(t, rule.Dest, director.current) +} + +func TestSceneDirector_ProcessTriggerCancellingToNewTransition(t *testing.T) { + mockSceneA := &MockScene{} + mockSceneB := &MockScene{} + mockTransitionA := &baseTransitionImplementation{} + mockTransitionB := &baseTransitionImplementation{} + ruleSet := make(map[Scene[int]][]Directive[int]) + + director := NewSceneDirector[int](mockSceneA, 1, ruleSet) + + ruleSet[mockSceneA] = []Directive[int]{ + Directive[int]{Dest: mockSceneB, Trigger: 2, Transition: mockTransitionA}, + } + ruleSet[mockSceneB] = []Directive[int]{ + Directive[int]{Dest: mockSceneA, Trigger: 2, Transition: mockTransitionB}, + } + director.ProcessTrigger(2) + + // Assert transition is running + assert.Equal(t, mockTransitionA, director.current) + + director.ProcessTrigger(2) + assert.Equal(t, mockTransitionB, director.current) + + mockTransitionB.End() + assert.Equal(t, mockSceneA, director.current) +} diff --git a/transition_test.go b/transition_test.go index 3c32e71..872dfc6 100644 --- a/transition_test.go +++ b/transition_test.go @@ -104,6 +104,35 @@ func TestBaseTransition_Awareness(t *testing.T) { assert.True(t, to.postTransitionCalled) } +func TestBaseTransition_SwitchCanceling(t *testing.T) { + from := &MockScene{} + to := &MockScene{} + trans := &baseTransitionImplementation{} + sm := NewSceneManager[int](from, 0) + sm.SwitchWithTransition(to, trans) + + // Assert transition is running + assert.Equal(t, trans, sm.current) + + sm.SwitchTo(to) + assert.Equal(t, to, sm.current) +} + +func TestBaseTransition_TransitionCanceling(t *testing.T) { + from := &MockScene{} + to := &MockScene{} + transA := &baseTransitionImplementation{} + transB := &baseTransitionImplementation{} + sm := NewSceneManager[int](from, 0) + sm.SwitchWithTransition(to, transA) + + // Assert transition is running + assert.Equal(t, transA, sm.current) + + sm.SwitchWithTransition(to, transB) + assert.Equal(t, transB, sm.current) +} + func TestFadeTransition_UpdateOncePerFrame(t *testing.T) { var value float32 = .6 from := &MockScene{}