Example #1
0
 public static Future <Either <ErrorMsg, A> > load <A>(
     ScenePath scenePath, LoadSceneMode loadSceneMode = LoadSceneMode.Single
     ) where A : Component =>
 Future.successful(
     F.doTry(() => SceneManager.LoadSceneAsync(scenePath, loadSceneMode))
     .toEitherStr.mapLeft(err => new ErrorMsg($"Error while loading scene '{scenePath}': {err}"))
     ).flatMapT(op => op.toFuture().map(_ =>
                                        SceneManager.GetSceneByPath(scenePath).findComponentOnRootGameObjects <A>()
                                        ));
Example #2
0
        public Scene() : base(content.rooms.basement.scene)
        {
            this.AutoAddEntities();

            ScenePath
            .Create(this)
            .SetPathFile(content.rooms.basement.path);

            DrawOrder = 20;
        }
Example #3
0
        public void DoNotUseScenePathEnterSceneTest()
        {
            Entity Entity = new Entity();

            Navigation.Create(Entity).SetUseScenePath(false);
            Scene Scene = new Scene("s1");

            ScenePath.Create(Scene).SetPath(ScriptsTest.CreateRectangularPath(100));
            Scene.Push(Entity);
            Entity.EnterScene(Scene);
            Assert.AreEqual(null, Entity.Get <Navigation>().Path);
        }
Example #4
0
        public static A withScene <A>(ScenePath scenePath, Fn <Scene, A> f)
        {
            var isLoaded = SceneManagerUtils.loadedScenes.Any(s => s.path == scenePath);
            var scene    = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
            var ret      = f(scene);

            if (!isLoaded)
            {
                SceneManager.UnloadSceneAsync(scene);
            }
            return(ret);
        }
Example #5
0
        public void UseScenePathScenePathChangesTest()
        {
            Entity Entity = new Entity();

            Navigation.Create(Entity).SetUseScenePath(true);
            Scene Scene = new Scene("s1");

            ScenePath.Create(Scene).SetPath(ScriptsTest.CreateRectangularPath(100));
            Scene.Push(Entity);
            Scene.Initialize(false);
            Scene.Get <ScenePath>().Path = ScriptsTest.CreateRectangularPath(50);
            Assert.AreEqual(Scene.Get <ScenePath>().Path, Entity.Get <Navigation>().Path);
        }
    public void changeScene(ref ScenePath <Properties> currentScene)
    {
        //ScenePath<Properties> startScene = new ScenePath<Properties>();

        //startScene.properties.positionMaze.x = 0;
        //startScene.properties.positionMaze.y = 0;

        generateScene(ref currentScene, Sides.LEFT);
        generateScene(ref currentScene, Sides.TOP);
        generateScene(ref currentScene, Sides.RIGHT);
        generateScene(ref currentScene, Sides.BOTTOM);

        //return startScene;
    }
Example #7
0
        public Scene()
        {
            this.AutoAddEntities();

            InputDispatcher
            .Create(this)
            .SetOnMouseUpFn(OnMouseUp);

            ScenePath
            .Create(this);

            Enabled = false;

            DrawOrder = 125;
        }
Example #8
0
        public Scene()
        {
            Enabled = true;
            Visible = true;

            InputDispatcher
            .Create(this)
            .SetOnMouseUpFn(OnMouseUp)
            .SetOnMouseMoveFn(OnMouseMove)
            .SetOnKeyDownFn(OnKeyDown);

            ScenePath
            .Create(this)
            .SetPath(CreatePath());

            Push(new Mouse());
        }
Example #9
0
        public void RestrictPositionTest()
        {
            Entity Entity = new Entity();

            Navigation.Create(Entity).SetUseScenePath(true).SetRestrictPosition(true);
            Transform.Create(Entity).SetPosition(200, 200);
            Scene Scene = new Scene("s1");

            ScenePath.Create(Scene);
            Scene.Push(Entity);
            Scene.Initialize(false);
            var Path = ScriptsTest.CreateRectangularPath(50);

            Assert.IsFalse(Path.Contains(Entity.Get <Transform>().Position));
            Scene.Get <ScenePath>().Path = Path;
            Assert.IsTrue(Path.Contains(Entity.Get <Transform>().Position));
        }
Example #10
0
            public void LoadItems()
            {
                XmlDocument doc1 = new XmlDocument();

                if (!File.Exists(Program.AppDataShellCommonDicPath))
                {
                    File.WriteAllText(Program.AppDataShellCommonDicPath, Properties.Resources.ShellCommonDic, Encoding.UTF8);
                }
                doc1.Load(Program.AppDataShellCommonDicPath);

                if (File.Exists(Program.ShellCommonDicPath))
                {
                    XmlDocument doc2 = new XmlDocument();
                    doc2.Load(Program.ShellCommonDicPath);
                    foreach (XmlNode xn in doc2.DocumentElement.ChildNodes)
                    {
                        XmlNode node = doc1.ImportNode(xn, true);
                        doc1.DocumentElement.AppendChild(node);
                    }
                }

                foreach (XmlElement groupXE in doc1.DocumentElement.ChildNodes)
                {
                    string scenePath = groupXE.GetAttribute("RegPath");
                    if (ScenePath.Equals(scenePath, StringComparison.OrdinalIgnoreCase))
                    {
                        shellXE   = (XmlElement)groupXE.SelectSingleNode("Shell");
                        shellExXE = (XmlElement)groupXE.SelectSingleNode("ShellEx");
                        if (shellXE != null)
                        {
                            LoadShellItems();
                        }
                        if (ShellExPath != null && shellExXE != null)
                        {
                            LoadShellExItems();
                        }
                    }
                }
            }
Example #11
0
    // This method is called from AStarTest or NPCScheduler to build the path. This method then calls NPCManager.BuildPath(), which in turn calls AStar.BuildPath()
    // To ultimately find the path taken and populate npcMovementStepStack with steps to take.
    public void BuildPath(NPCScheduleEvent npcScheduleEvent)
    {
        // First clear out the npcMovementStepStack in case it has extra steps from earlier builds
        ClearPath();

        // If the scheduled event is for the same scene as the current NPC scene. For now, we are only moving the NPC within the current scene. If it's not, go to the
        // next else if statement to move to a new scene
        if (npcScheduleEvent.toSceneName == npcMovement.npcCurrentScene)
        {
            // If we are in the same scene as the scheduled event, get the current (start) and target grid positions for the movement event, the former from the npcMovement, and
            // the latter from the scheduleEvent
            Vector2Int npcCurrentGridPosition = (Vector2Int)npcMovement.npcCurrentGridPosition;

            Vector2Int npcTargetGridPosition = (Vector2Int)npcScheduleEvent.toGridCoordinate;

            // Build the path with NPCManager -> AStar and add the corresponding movement steps to the movement step stack
            NPCManager.Instance.BuildPath(npcScheduleEvent.toSceneName, npcCurrentGridPosition, npcTargetGridPosition, npcMovementStepStack);
        }
        // Else, if the movement event is for a location in another scene, we need to build Paths from the current NPC position, to the scene exit position specified in
        // the SceneRoute, then a new path from the new scene entrance position to where the NPC targets (or to another scene if there is a 3-scene scene route between the scenes)
        else if (npcScheduleEvent.toSceneName != npcMovement.npcCurrentScene)
        {
            SceneRoute sceneRoute;

            // Get the corresponding sceneRoute for the matching schedule
            sceneRoute = NPCManager.Instance.GetSceneRoute(npcMovement.npcCurrentScene.ToString(), npcScheduleEvent.toSceneName.ToString());

            // Check if a valid SceneRoute has been found in the NPCManager SceneRouteDictionary
            if (sceneRoute != null)
            {
                // Loop through all of the scene paths the NPC will need to traverse to get to the toSceneName, backwards
                // For each ScenePath in the SceneRoute, calculate the to and from grid positions (if it's a starting scene, fromGrid is the NPCs current position, and toGrid is that scenes
                // exit point specified in the scenePath. If it's a middle scene, fromGrid is the scene entrance point, and toGrid is the scene exit point. If it's the ending scene, the
                // fromGrid is the scene entrance point, and the toGrid is the target destination specified in the NPCScheduleEvent
                for (int i = sceneRoute.scenePathList.Count - 1; i >= 0; i--)
                {
                    int toGridX, toGridY, fromGridX, fromGridY;

                    ScenePath scenePath = sceneRoute.scenePathList[i];

                    // Check if this current ScenePath is the final destination (we set it up so final destinations have toGridCells of (999999, 999999), while the maxGridDims are smaller at 99999)
                    // - when this happens we know to suibstitute the final destination as the one the NPCScheduleEvent wants
                    if (scenePath.toGridCell.x >= Settings.maxGridWidth || scenePath.toGridCell.y >= Settings.maxGridHeight)
                    {
                        // If so, set up the toGrid cell as the final destination of the NPCScheduleEvent we are looking at
                        toGridX = npcScheduleEvent.toGridCoordinate.x;
                        toGridY = npcScheduleEvent.toGridCoordinate.y;
                    }
                    else
                    {
                        // If it's not the final destination, use the specified scenePath to position to move to (i.e. the scene exit position the NPC will move to to transfer to the next scene)
                        toGridX = scenePath.toGridCell.x;
                        toGridY = scenePath.toGridCell.y;
                    }

                    // Check if this current ScenePath is the  starting position (we set it up so starting positions have toGridCells of (999999, 999999), while the maxGridDims are smaller at 99999)
                    // - when this happens we know to suibstitute the starting position as the one the NPCs current position
                    if (scenePath.fromGridCell.x >= Settings.maxGridWidth || scenePath.fromGridCell.y >= Settings.maxGridHeight)
                    {
                        // If so, set up the NPCs current position cell as the starting location of the first path
                        fromGridX = npcMovement.npcCurrentGridPosition.x;
                        fromGridY = npcMovement.npcCurrentGridPosition.y;
                    }
                    else
                    {
                        // If it's not the starting position, use the specified scenePath to position to move from (i.e. the scene entrance position the NPC will move to to transfer to the next scene)
                        fromGridX = scenePath.fromGridCell.x;
                        fromGridY = scenePath.fromGridCell.y;
                    }

                    // To and From grid positions in THIS current Scene (computed above from the current scene path we're looking at)
                    Vector2Int fromGridPosition = new Vector2Int(fromGridX, fromGridY);
                    Vector2Int toGridPosition   = new Vector2Int(toGridX, toGridY);

                    // Build the path for this current ScenePath in the sceneRoute, and add the steps to the movementStepStack (not cleared inbetween scenePaths! All of the scenes
                    // will get added onto the top of the movementStepStack). So our movementStepStack will have multiple built paths stacked on top of eachother,
                    // one for each scene we need to traverse. Then the NPCmovement will take all of the steps in turn, from each scene in order to get to the destination
                    // scene and grid position
                    NPCManager.Instance.BuildPath(scenePath.sceneName, fromGridPosition, toGridPosition, npcMovementStepStack);

                    // Then move on to the next ScenePath (for the next scene) in the loop and repeat all of the steps to add more to the Step Stack under a new step name
                }
            }
        }

        // If stack count is > 1 (i.e. has steps beyond the starting one), update the times and the pop off the 1st item which is the starting position
        if (npcMovementStepStack.Count > 1)
        {
            // This method will loop through all of the steps in the npcMovementStepStack, and populate the gameTime that the NPC needs to
            // be to that step by.
            UpdateTimesOnPath();

            // discard starting step (we're already on the starting step)
            //npcMovementStepStack.Pop();  // I removed this line so the NPC doesn't jump a square for the very first step...

            // Set the schedule event details in NPC movement, so it knows how to move the NPC, and what facing direction/animation to play when they get there
            npcMovement.SetScheduleEventDetails(npcScheduleEvent);
        }
    }
Example #12
0
    public void BuildPath(NPCScheduleEvent npcScheduleEvent)
    {
        ClearPath();

        //If schedule event is for the same scene as the current NPC scene
        if (npcScheduleEvent.toSceneName == npcMovement.npcCurrentScene)
        {
            Vector2Int npcCurrentGridPosition = (Vector2Int)npcMovement.npcCurrentGridPosition;

            Vector2Int npcTargetGridPosition = (Vector2Int)npcScheduleEvent.toGridCoordinate;

            //Build path and add movement steps to movement step stack
            NPCManager.Instance.BuildPath(npcScheduleEvent.toSceneName, npcCurrentGridPosition, npcTargetGridPosition, npcMovementStepStack);
        }
        //else if the schedule event is for a location in another scene
        else if (npcScheduleEvent.toSceneName != npcMovement.npcCurrentScene)
        {
            SceneRoute sceneRoute;

            //Get scene route matchingSchedule
            sceneRoute = NPCManager.Instance.GetSceneRoute(npcMovement.npcCurrentScene.ToString(), npcScheduleEvent.toSceneName.ToString());

            //Has a valid scene route been found?
            if (sceneRoute != null)
            {
                //Loop through scene paths in reverse order

                for (int i = sceneRoute.scenePathList.Count - 1; i >= 0; i--)
                {
                    int toGridX, toGridY, fromGridX, fromGridY;

                    ScenePath scenePath = sceneRoute.scenePathList[i];

                    //Check if this is the final destination
                    if (scenePath.toGridCell.x >= Settings.maxGridWidth || scenePath.toGridCell.y >= Settings.maxGridHeight)
                    {
                        //If so use final destination grid cell
                        toGridX = npcScheduleEvent.toGridCoordinate.x;
                        toGridY = npcScheduleEvent.toGridCoordinate.y;
                    }
                    else
                    {
                        //else use scene path to position
                        toGridX = scenePath.toGridCell.x;
                        toGridY = scenePath.toGridCell.y;
                    }

                    //Check if this is the starting position
                    if (scenePath.fromGridCell.x >= Settings.maxGridWidth || scenePath.fromGridCell.y >= Settings.maxGridHeight)
                    {
                        //if so use npc position
                        fromGridX = npcMovement.npcCurrentGridPosition.x;
                        fromGridY = npcMovement.npcCurrentGridPosition.y;
                    }
                    else
                    {
                        //else use scene path from position
                        fromGridX = scenePath.fromGridCell.x;
                        fromGridY = scenePath.fromGridCell.y;
                    }

                    Vector2Int fromGridPosition = new Vector2Int(fromGridX, fromGridY);

                    Vector2Int toGridPosition = new Vector2Int(toGridX, toGridY);

                    //Build path and add movement steps to movement step stack
                    NPCManager.Instance.BuildPath(scenePath.sceneName, fromGridPosition, toGridPosition, npcMovementStepStack);
                }
            }
        }

        //If stack count >1, update times and then pop off 1st item which is the starting position
        if (npcMovementStepStack.Count > 1)
        {
            UpdateTimesOnPath();
            npcMovementStepStack.Pop();//discard starting step

            //Set schedule event details in NPC movement
            npcMovement.SetScheduleEventDetails(npcScheduleEvent);
        }
    }
Example #13
0
    void generateScene(ref ScenePath <Properties> currentScene, int createToSide)
    {
        switch (createToSide)
        {
        case Sides.LEFT:
        {
            ScenePath <Properties> newSceneLeft = new ScenePath <Properties>();
            newSceneLeft.right = currentScene;
            newSceneLeft.properties.positionMaze.x = currentScene.properties.positionMaze.x - 1;
            newSceneLeft.properties.positionMaze.y = currentScene.properties.positionMaze.y;


            if (currentScene.top != null)
            {
                if (currentScene.top.left != null)
                {
                    if (currentScene.top.left.bottom != null)
                    {
                        return;        // currentScene.top.left.bottom;
                    }
                    else
                    {
                        newSceneLeft.top             = currentScene.top.left;
                        currentScene.top.left.bottom = newSceneLeft;
                    }
                }
            }

            if (currentScene.bottom != null)
            {
                if (currentScene.bottom.left != null)
                {
                    if (currentScene.bottom.left.top != null)
                    {
                        return;        // currentScene.bottom.left.top;
                    }
                    else
                    {
                        newSceneLeft.bottom          = currentScene.bottom.left;
                        currentScene.bottom.left.top = newSceneLeft;
                    }
                }
            }

            currentScene.left = newSceneLeft;
            break;
        }

        case Sides.TOP:
        {
            ScenePath <Properties> newSceneTop = new ScenePath <Properties>();
            newSceneTop.bottom = currentScene;
            newSceneTop.properties.positionMaze.x = currentScene.properties.positionMaze.x;
            newSceneTop.properties.positionMaze.y = currentScene.properties.positionMaze.y + 1;

            if (currentScene.left != null)
            {
                if (currentScene.left.top != null)
                {
                    if (currentScene.left.top.right != null)
                    {
                        return;        // currentScene.left.top.right;
                    }
                    else
                    {
                        newSceneTop.left            = currentScene.left.top;
                        currentScene.left.top.right = newSceneTop;
                    }
                }
            }

            if (currentScene.right != null)
            {
                if (currentScene.right.top != null)
                {
                    if (currentScene.right.top.left != null)
                    {
                        return;        // currentScene.right.top.left;
                    }
                    else
                    {
                        newSceneTop.right           = currentScene.right.top;
                        currentScene.right.top.left = newSceneTop;
                    }
                }
            }

            currentScene.top = newSceneTop;
            break;
        }

        case Sides.RIGHT:
        {
            ScenePath <Properties> newSceneRight = new ScenePath <Properties>();
            newSceneRight.left = currentScene;
            newSceneRight.properties.positionMaze.x = currentScene.properties.positionMaze.x + 1;
            newSceneRight.properties.positionMaze.y = currentScene.properties.positionMaze.y;


            if (currentScene.top != null)
            {
                if (currentScene.top.right != null)
                {
                    if (currentScene.top.right.bottom != null)
                    {
                        return;        // currentScene.top.right.bottom;
                    }
                    else
                    {
                        newSceneRight.top             = currentScene.top.right;
                        currentScene.top.right.bottom = newSceneRight;
                    }
                }
            }

            if (currentScene.bottom != null)
            {
                if (currentScene.bottom.right != null)
                {
                    if (currentScene.bottom.right.top != null)
                    {
                        return;        // currentScene.bottom.right.top;
                    }
                    else
                    {
                        newSceneRight.bottom          = currentScene.bottom.right;
                        currentScene.bottom.right.top = newSceneRight;
                    }
                }
            }

            currentScene.right = newSceneRight;
            break;
        }

        case Sides.BOTTOM:
        {
            ScenePath <Properties> newSceneBottom = new ScenePath <Properties>();
            newSceneBottom.top = currentScene;
            newSceneBottom.properties.positionMaze.x = currentScene.properties.positionMaze.x;
            newSceneBottom.properties.positionMaze.y = currentScene.properties.positionMaze.y - 1;

            if (currentScene.left != null)
            {
                if (currentScene.left.bottom != null)
                {
                    if (currentScene.left.bottom.right != null)
                    {
                        return;         // currentScene.left.bottom.right;
                    }
                    else
                    {
                        newSceneBottom.left            = currentScene.left.bottom;
                        currentScene.left.bottom.right = newSceneBottom;
                    }
                }
            }

            if (currentScene.right != null)
            {
                if (currentScene.right.bottom != null)
                {
                    if (currentScene.right.bottom.left != null)
                    {
                        return;         // currentScene.right.bottom.left;
                    }
                    else
                    {
                        newSceneBottom.right           = currentScene.right.bottom;
                        currentScene.right.bottom.left = newSceneBottom;
                    }
                }
            }

            currentScene.bottom = newSceneBottom;

            break;
        }

        default:
        {
            break
            ;
        }
        }
    }