예제 #1
0
        public SceneState(SceneState <TScene> state)
        {
            this.ActiveMap.Clear();

            foreach (var key in state.ActiveMap.Keys)
            {
                this.ActiveMap[key] = state.ActiveMap[key];
            }
        }
        public void ResetTest()
        {
            var reducer = new SceneDuck <SampleScene> .Reducer();

            var state = new SceneState <SampleScene>();

            // Adjust
            {
                var result = reducer.Reduce(
                    state,
                    SceneDuck <SampleScene> .ActionCreator.Adjust(new[] { SampleScene.Scene1 })
                    );
                Assert.AreEqual(2, result.ActiveMap.Count);
                Assert.IsTrue(result.ActiveMap[SampleScene.Scene1]);
                Assert.IsFalse(result.ActiveMap[SampleScene.Scene2]);
            }

            // Add
            {
                var result = reducer.Reduce(
                    state,
                    SceneDuck <SampleScene> .ActionCreator.Add(new[] { SampleScene.Scene1 })
                    );
                Assert.AreEqual(2, result.ActiveMap.Count);
                Assert.IsTrue(result.ActiveMap[SampleScene.Scene1]);
                Assert.IsFalse(result.ActiveMap[SampleScene.Scene2]);

                result = reducer.Reduce(
                    state,
                    SceneDuck <SampleScene> .ActionCreator.Add(new[] { SampleScene.Scene2 })
                    );
                Assert.AreEqual(2, result.ActiveMap.Count);
                Assert.IsTrue(result.ActiveMap[SampleScene.Scene1]);
                Assert.IsTrue(result.ActiveMap[SampleScene.Scene2]);
            }

            // Remove
            {
                var result = reducer.Reduce(
                    state,
                    SceneDuck <SampleScene> .ActionCreator.Remove(new[] { SampleScene.Scene1 })
                    );
                Assert.AreEqual(2, result.ActiveMap.Count);
                Assert.IsFalse(result.ActiveMap[SampleScene.Scene1]);
                Assert.IsTrue(result.ActiveMap[SampleScene.Scene2]);

                result = reducer.Reduce(
                    state,
                    SceneDuck <SampleScene> .ActionCreator.Remove(new[] { SampleScene.Scene2 })
                    );
                Assert.AreEqual(2, result.ActiveMap.Count);
                Assert.IsFalse(result.ActiveMap[SampleScene.Scene1]);
                Assert.IsFalse(result.ActiveMap[SampleScene.Scene2]);
            }
        }
예제 #3
0
            public PageState <TPage> ReduceReplace(
                PageState <TPage> pageState,
                SceneState <TScene> sceneState,
                IPageEntity <TPage> action
                )
            {
                if (pageState.Stack.Any())
                {
                    pageState.Stack.RemoveLast();
                }

                ReducePush(pageState, sceneState, action);
                return(pageState);
            }
예제 #4
0
            public PageState <TPage> ReducePop(
                PageState <TPage> pageState,
                SceneState <TScene> sceneState,
                PopAction action
                )
            {
                // don't remove last page
                if (pageState.Stack.Count > 1)
                {
                    pageState.Stack.RemoveLast();
                }

                pageState.SetStateChanged();

                ReduceAdjust(pageState, sceneState);
                return(pageState);
            }
예제 #5
0
            public PageState <TPage> ReduceAdjust(PageState <TPage> pageState, SceneState <TScene> sceneState)
            {
                SceneDuck <TScene> .Remove(sceneState, config.GetPageScenes());

                if (pageState.Stack.Any())
                {
                    var page = pageState.Current.Page;

                    if (!config.PageMap.ContainsKey(page))
                    {
                        Debug.LogWarning(
                            "Page adjust failed. Missing configuration in SceneConfig.PageMap: " + page);
                    }

                    var scenes = config.PageMap[page];

                    SceneDuck <TScene> .Add(sceneState, scenes);
                }

                sceneState.SetStateChanged();
                return(pageState);
            }
            public override SceneState <TScene> Reduce(SceneState <TScene> state, Action action)
            {
                switch (action.Type)
                {
                case ActionType.Adjust:
                    ResetAll(state);
                    Add(state, action.Scenes);
                    state.SetStateChanged();
                    break;

                case ActionType.Add:
                    Add(state, action.Scenes);
                    state.SetStateChanged();
                    break;

                case ActionType.Remove:
                    Remove(state, action.Scenes);
                    state.SetStateChanged();
                    break;
                }

                return(state);
            }
 public static void Remove(SceneState <TScene> state, IEnumerable <TScene> scenes)
 {
     Set(state.ActiveMap, scenes, false);
 }
 public static void Add(SceneState <TScene> state, IEnumerable <TScene> scenes)
 {
     Set(state.ActiveMap, scenes, true);
 }
 public static void ResetAll(SceneState <TScene> state)
 {
     Set(state.ActiveMap, EnumUtil.All <TScene>(), false);
 }
 public void Before()
 {
     this.state = new SceneState <SampleScene>();
 }