示例#1
0
        public async void WriteStringToAppData(string data, string path, bool skipDevPath = false,
                                               Action onComplete = null)
        {
            var fullPath = Path.Combine(this.AppDataPath, path);

            Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
            await File.WriteAllTextAsync(fullPath, data);

#if DEBUG
            // In development mode we do this wacky thing where we want to write the file to the repo, no other scenario needs to worry about this
            if (GamePlatform.IsDesktop)
            {
                if (!skipDevPath)
                {
                    var fullContentPath = Path.Combine(this.devPath, path);
                    Directory.CreateDirectory(Path.GetDirectoryName(fullContentPath));
                    await File.WriteAllTextAsync(fullContentPath, data);

                    MachinaClient.Print("Saved:", fullContentPath);
                }
            }
#endif
            MachinaClient.Print("Saved:", fullPath);

            onComplete?.Invoke();
        }
示例#2
0
        private string GetArgumentValueFromInitialString(string argName)
        {
            var index = this.argsStrings.IndexOf(ConvertToCommandToken(argName));

            if (index == -1)
            {
                MachinaClient.Print("Command line switch", argName, "not found");
                return(null);
            }

            if (this.argsStrings.Count == index + 1)
            {
                MachinaClient.Print("Argument value missing for", argName);
                return(null);
            }

            var val = this.argsStrings[index + 1];

            if (IsStringACommand(val))
            {
                MachinaClient.Print("Argument value missing for", argName);
                return(null);
            }

            return(val);
        }
示例#3
0
        public SoundEffectInstance PlaySound(string soundEffectName, float baseVolume = 0.5f, float pitch = 0f,
                                             bool useCache = true)
        {
            SoundEffectInstance soundEffect;

            if (useCache)
            {
                // Grab the cached sound effect and reset it
                soundEffect = MachinaClient.Assets.GetSoundEffectInstance(soundEffectName);
                soundEffect.Stop();
            }
            else
            {
                // Build a new sound effect here and now
                soundEffect = MachinaClient.Assets.CreateSoundEffectInstance(soundEffectName);
            }

            soundEffect.Volume = baseVolume * this.settings.SFXVolumeAsFloat;
            soundEffect.Pitch  = pitch;
            try
            {
                soundEffect.Play();
            }
            catch (InstancePlayLimitException e)
            {
                MachinaClient.Print("Caught InstancePlayLimitException", e.Message);
            }

            return(soundEffect);
        }
示例#4
0
 public void SetWindowSize(Point windowSize)
 {
     MachinaClient.Print("Window size changed to", windowSize);
     if (!GamePlatform.IsAndroid)
     {
         this.graphics.PreferredBackBufferWidth  = windowSize.X;
         this.graphics.PreferredBackBufferHeight = windowSize.Y;
         this.graphics.ApplyChanges();
         Resized?.Invoke(windowSize);
     }
 }
示例#5
0
        private void InsertGameCartridgeAndRun(GameCartridge gameCartridge)
        {
            this.specification.commandLineArgs.ExecuteEarlyArgs();
            InsertCartridge(gameCartridge);
            this.specification.commandLineArgs.ExecuteArgs();

            if (DebugLevel >= DebugLevel.Passive)
            {
                MachinaClient.Print("Debug build detected");
            }
        }
示例#6
0
 public void RunDemo(string demoName)
 {
     if (CurrentCartridge is GameCartridge gameCartridge)
     {
         var demoActor             = CurrentCartridge.SceneLayers.DebugScene.AddActor("DebugActor");
         var demoPlaybackComponent = new DemoPlaybackComponent(demoActor);
         DemoPlayback = demoPlaybackComponent.SetDemo(gameCartridge, Demo.FromDisk_Sync(demoName, MachinaClient.FileSystem), demoName, 1);
         demoPlaybackComponent.ShowGui = false;
     }
     else
     {
         MachinaClient.Print("Demo loading is only supported on GameCartridges");
     }
 }
示例#7
0
        public MachinaFileSystem(string gameTitle, string contentDirectory = "")
        {
            this.AppDataPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                         "NotExplosive", gameTitle);

            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            if (baseDirectory == null)
            {
                // This should literally never happen but on android it does
                baseDirectory = "";
            }

            this.devPath = Path.GetFullPath(Path.Combine(baseDirectory, "..", "..", "..", "..", contentDirectory, "Content"));
            MachinaClient.Print(this.devPath, Directory.Exists(this.devPath));
        }
示例#8
0
        public void Update(float dt, Matrix mouseTransformMatrix, InputFrameState inputFrameState,
                           bool allowMouseUpdate = true, bool allowKeyboardEvents = true)
        {
#if DEBUG
#else
            try
            {
#endif
            if (!this.hasDoneFirstUpdate)
            {
                DoFirstUpdate();
                this.hasDoneFirstUpdate = true;
            }

            CurrentInputFrameState = inputFrameState;
            var scenes = AllScenes();

            var rawMousePos = Vector2.Transform(inputFrameState.mouseFrameState.RawWindowPosition.ToVector2(),
                                                mouseTransformMatrix);

            foreach (var scene in scenes)
            {
                scene.FlushBuffers();

                if (!scene.IsFrozen)
                {
                    if (allowKeyboardEvents)
                    {
                        if (this.pendingTextInput.HasValue)
                        {
                            scene.OnTextInput(this.pendingTextInput.Value);
                        }

                        foreach (var key in inputFrameState.keyboardFrameState.Released)
                        {
                            scene.OnKey(key, ButtonState.Released, inputFrameState.keyboardFrameState.Modifiers);
                        }

                        foreach (var key in inputFrameState.keyboardFrameState.Pressed)
                        {
                            scene.OnKey(key, ButtonState.Pressed, inputFrameState.keyboardFrameState.Modifiers);
                        }
                    }

                    if (allowMouseUpdate)
                    {
                        if (inputFrameState.mouseFrameState.ScrollDelta != 0)
                        {
                            scene.OnScroll(inputFrameState.mouseFrameState.ScrollDelta);
                        }

                        // Pressed
                        if (inputFrameState.mouseFrameState.ButtonsPressedThisFrame.left)
                        {
                            scene.OnMouseButton(MouseButton.Left, rawMousePos, ButtonState.Pressed);
                        }

                        if (inputFrameState.mouseFrameState.ButtonsPressedThisFrame.middle)
                        {
                            scene.OnMouseButton(MouseButton.Middle, rawMousePos, ButtonState.Pressed);
                        }

                        if (inputFrameState.mouseFrameState.ButtonsPressedThisFrame.right)
                        {
                            scene.OnMouseButton(MouseButton.Right, rawMousePos, ButtonState.Pressed);
                        }

                        // Released
                        if (inputFrameState.mouseFrameState.ButtonsReleasedThisFrame.left)
                        {
                            scene.OnMouseButton(MouseButton.Left, rawMousePos, ButtonState.Released);
                        }

                        if (inputFrameState.mouseFrameState.ButtonsReleasedThisFrame.middle)
                        {
                            scene.OnMouseButton(MouseButton.Middle, rawMousePos, ButtonState.Released);
                        }

                        if (inputFrameState.mouseFrameState.ButtonsReleasedThisFrame.right)
                        {
                            scene.OnMouseButton(MouseButton.Right, rawMousePos, ButtonState.Released);
                        }

                        // At this point the raw and processed deltas are equal, downstream (Scene and below) they will differ
                        scene.OnMouseUpdate(rawMousePos, inputFrameState.mouseFrameState.PositionDelta,
                                            inputFrameState.mouseFrameState.PositionDelta);
                    }
                }
            }

            this.pendingTextInput = null;

            foreach (var scene in scenes)
            {
                if (!scene.frameStep.IsPaused && !scene.IsFrozen)
                {
                    scene.Update(dt);
                }
            }

            HitTestResult.ApproveTopCandidate(scenes);
#if DEBUG
#else
        }

        catch (System.Exception exception)
        {
            MachinaClient.Print("caught exception");
            OnError?.Invoke(exception);
        }
#endif
        }
示例#9
0
        private void FinishLoadingContent(GameCartridge gameCartridge)
        {
#if DEBUG
            DebugLevel = DebugLevel.Passive;
#endif

            // Most cartridges get setup automatically but since the gamecartridge hasn't been inserted yet we have to do it early here
            gameCartridge.SetupSceneLayers(this, specification, WindowInterface);

            var debugActor            = gameCartridge.SceneLayers.DebugScene.AddActor("DebugActor");
            var demoPlaybackComponent = new DemoPlaybackComponent(debugActor);

            var demoName           = Demo.MostRecentlySavedDemoPath;
            var demoSpeed          = 1;
            var shouldSkipSnapshot = DebugLevel == DebugLevel.Off;

            void SetRandomSeedFromString(string seed)
            {
                gameCartridge.Random.Seed = (int)NoiseBasedRNG.SeedFromString(seed);
            }

            this.specification.commandLineArgs.RegisterEarlyFlagArg("skipsnapshot", () => { shouldSkipSnapshot = true; });
            this.specification.commandLineArgs.RegisterEarlyValueArg("randomseed", SetRandomSeedFromString);
            this.specification.commandLineArgs.RegisterEarlyValueArg("demopath", arg => { demoName = arg; });
            this.specification.commandLineArgs.RegisterEarlyValueArg("demospeed", arg => { demoSpeed = int.Parse(arg); });
            this.specification.commandLineArgs.RegisterEarlyValueArg("demo", arg =>
            {
                switch (arg)
                {
                case "record":
                    new DemoRecorderComponent(debugActor, new Demo.Recorder(gameCartridge, demoName));
                    break;

                case "playback":
                    DemoPlayback = demoPlaybackComponent.SetDemo(gameCartridge, Demo.FromDisk_Sync(demoName, MachinaClient.FileSystem), demoName, demoSpeed);
                    break;

                case "playback-nogui":
                    DemoPlayback = demoPlaybackComponent.SetDemo(gameCartridge, Demo.FromDisk_Sync(demoName, MachinaClient.FileSystem), demoName, demoSpeed);
                    demoPlaybackComponent.ShowGui = false;
                    break;

                default:
                    MachinaClient.Print("Unknown demo mode", arg);
                    break;
                }
            });

            this.specification.commandLineArgs.RegisterEarlyFlagArg("debug",
                                                                    () => { DebugLevel = DebugLevel.Active; });

#if DEBUG
            // PlayIntroAndLoadGame(gameCartridge);
            InsertGameCartridgeAndRun(gameCartridge);
#else
            if (SkipIntro)
            {
                InsertGameCartridgeAndRun(gameCartridge);
            }
            else
            {
                PlayIntroAndLoadGame(gameCartridge);
            }
#endif
            // Currently we go [SetupDebugScene] -> [LoadGame] -> [LateSetup], hopefully the cartridge system will mitigate the need for this.
            if (GamePlatform.IsDesktop)
            {
                // NOTE: If we play the intro in a debug build this flag will not be honored, tech debt.
                new SnapshotTaker(debugActor, shouldSkipSnapshot);
            }
        }