Exemple #1
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (controllerChip.GetKeyDown(Keys.LeftControl) ||
                controllerChip.GetKeyDown(Keys.LeftControl))
            {
                if (controllerChip.GetKeyUp(Keys.R) || controllerChip.GetKeyUp(Keys.D4))
                {
                    ResetGame();
                }
            }
        }
        protected override void Update(GameTime gameTime)
        {
            if (activeEngine == null || shutdown)
            {
                return;
            }

            // TODO make sure this order is correct or maybe it can be cleaned up
            if (screenShotActive)
            {
                screenshotTime += timeDelta;

                if (screenshotTime > screenshotDelay)
                {
                    screenShotActive = false;
                    screenshotTime   = 0;
                }
            }

            // Save any gifs that have been encoded
            // if (gifEncoders.Count > 0)
            //     for (var i = gifEncoders.Count - 1; i >= 0; i--)
            //     {
            //         var encoder = gifEncoders[i];
            //
            //         // Do processing here, then...
            //         if (encoder.ExportingFinished)
            //         {
            //             // Get the gif directory
            //             var gifDirectory = WorkspacePath.Root.AppendDirectory("Workspace")
            //                 .AppendDirectory("Recordings");
            //
            //             // Create the directory if it doesn't exist
            //             if (!workspaceService.Exists(gifDirectory))
            //                 workspaceServicePlus.CreateDirectoryRecursive(gifDirectory);
            //
            //             // Get the path to the new file
            //             var path = workspaceService.UniqueFilePath(gifDirectory.AppendFile("recording.gif"));
            //
            //             // Create a new file in the workspace
            //             var fileStream = workspaceService.CreateFile(path);
            //
            //             // Get the memory stream from the gif encoder
            //             var memoryStream = new MemoryStream(encoder.bytes);
            //
            //             memoryStream.Position = 0;
            //             memoryStream.CopyTo(fileStream);
            //
            //             // Close the file stream
            //             fileStream.Close();
            //             fileStream.Dispose();
            //
            //             // Close the memory stream
            //             memoryStream.Close();
            //             memoryStream.Dispose();
            //
            //             // Remove the encoder
            //             gifEncoders.RemoveAt(i);
            //         }
            //     }

            if (controllerChip.GetKeyDown(Keys.LeftControl) ||
                controllerChip.GetKeyDown(Keys.LeftControl))
            {
                if (controllerChip.GetKeyUp(actionKeys[ActionKeys.ScreenShotKey]))
                {
                    // Only take a screenshot when one isn't being saved
                    if (!screenShotActive)
                    {
                        //                            Console.WriteLine("Take Picture");

                        screenShotActive = screenshotService.TakeScreenshot(activeEngine);
                    }
                }
                else if (controllerChip.GetKeyUp(actionKeys[ActionKeys.RecordKey]))
                {
                    if (recording)
                    {
                        StopRecording();
                    }
                    else
                    {
                        StartRecording();
                    }
                }
                else if (controllerChip.GetKeyUp(actionKeys[ActionKeys.RestartKey]))
                {
                    if (controllerChip.GetKeyDown(Keys.LeftShift) || controllerChip.GetKeyDown(Keys.RightShift))
                    {
                        AutoLoadDefaultGame();
                    }
                    else
                    {
                        ResetGame();
                    }
                }
            }
            else if (controllerChip.GetKeyUp(Keys.Escape) && backKeyEnabled)
            {
                Back();
            }
            else
            {
                if (controllerChip.GetKeyUp(Keys.D1))
                {
                    ToggleLayers(2);
                }
                else if (controllerChip.GetKeyUp(Keys.D2))
                {
                    ToggleLayers(3);
                }
                else if (controllerChip.GetKeyUp(Keys.D3))
                {
                    ToggleLayers(4);
                }
                else if (controllerChip.GetKeyUp(Keys.D4))
                {
                    ToggleLayers(5);
                }
                else if (controllerChip.GetKeyUp(Keys.D5))
                {
                    ToggleLayers(6);
                }
                else if (controllerChip.GetKeyUp(Keys.D6))
                {
                    ToggleLayers(7);
                }
                else if (controllerChip.GetKeyUp(Keys.D7))
                {
                    ToggleLayers(Enum.GetNames(typeof(DrawMode)).Length);
                }
            }

            // Capture Script errors
            try
            {
                base.Update(gameTime);
            }
            catch (Exception e)
            {
                DisplayError(ErrorCode.Exception,
                             new Dictionary <string, string>
                {
                    { "@{error}", e is ScriptRuntimeException error ? error.DecoratedMessage : e.Message }
                },