Exemple #1
0
 public ActionResult ApiSessionRecorderToggle()
 {
     ViewBag.LastSessionId = _clientStorage.Get("ApiSessionId");
     if (_clientStorage.Get("ApiSessionId") == null)
     {
         ViewBag.SessionId = _clientStorage.Save("ApiSessionId", Guid.NewGuid().ToString("N"));
     }
     else
     {
         ViewBag.SessionId = _clientStorage.Save("ApiSessionId", null);
     }
     return(View("ApiSessionRecorder"));
 }
        /// <summary>
        /// Save settings in ClientStorage.
        /// </summary>
        public static void SaveSettings()
        {
            // Check if content settings changed.
            if (tempView != settingsInstance.View)
            {
                settingsInstance.View = tempView;
                isSettingsChanged     = true;
                ChangeCurrentView();
            }

            // Check if type visibility changed.
            if (IsTypeVisible != settingsInstance.IsTypeVisible)
            {
                settingsInstance.IsTypeVisible = IsTypeVisible;
                isSettingsChanged = true;
                CurrentView.Refresh();
            }

            // Check if HideUnreachableObjects changed.
            if (HideUnreachableObjects != settingsInstance.HideUnreachableObjects)
            {
                settingsInstance.HideUnreachableObjects = HideUnreachableObjects;
                isSettingsChanged = true;
                ChangeCurrentView();
            }

            // If settings changed - save to local storage.
            if (isSettingsChanged)
            {
                settingsStorage.Save(settingsInstance);
                isSettingsChanged = false;
            }
        }
        public static void LoadDefaultViewPresetFromClientStorage()
        {
            defaultViewStorage = Api.Client.Storage.GetStorage("Mods/" + ModId + "/DefaultView");
            bool settingExist = true;

            // Force reload preset if saved version is too old.
            if (VersionFromClientStorage.CompareTo(new Version("0.4.7")) < 0 ||
                !defaultViewStorage.TryLoad(out defaultViewPresetFromSettings))
            {
                // Default settings.
                defaultViewPresetFromSettings = new List <string>()
                {
                    "ProtoCharacterMob",
                    "ProtoItem",
                    "ProtoObjectHackableContainer",
                    "ProtoObjectLoot",
                    "ProtoObjectLootContainer",
                    "ProtoObjectMineral",
                    "ProtoObjectStructure",
                    "ProtoObjectVegetation",
                    "ProtoStatusEffect",
                    "ProtoVehicle"
                };
                settingExist = false;
            }

            LoadDefaultViewFromSettings();

            if (!settingExist)
            {
                defaultViewStorage.Save(defaultViewPresetFromSettings);
            }
        }
Exemple #4
0
        private static void SaveCharacterProgress(ushort slotId)
        {
            var data = new CharacterProgressData(ClientCurrentCharacterHelper.Character, slotId);

            ClientStoredCharacterData.Save(data);
            Logger.Important("Saved character progress: slotId=" + slotId);
        }
        /// <summary>
        /// Save default view preset to settings (convert list from TypeHierarchy to string).
        /// </summary>
        private static void SaveDefaultViewToSettings()
        {
            var tempList = DefaultViewPreset.Select(t => t.ShortName).ToList();

            // tempList already sorted, as DefaultViewPreset sorted by ShortName
            if (!tempList.SequenceEqual(defaultViewPresetFromSettings))
            {
                defaultViewPresetFromSettings = tempList;
                defaultViewStorage.Save(defaultViewPresetFromSettings);
            }
        }
Exemple #6
0
        /// <summary>
        /// Try to load mod version from client storage.
        /// </summary>
        private static void LoadVersionFromClientStorage()
        {
            // Load settings.
            versionStorage = Api.Client.Storage.GetStorage("Mods/Automaton/Version");
            versionStorage.RegisterType(typeof(Version));
            versionStorage.TryLoad(out VersionFromClientStorage);

            // Version changes handeling.
            // if (VersionFromClientStorage.CompareTo(CurrentVersion) > 0)

            versionStorage.Save(CurrentVersion);
        }
Exemple #7
0
        public static void SetConfirmedForCurrentServer()
        {
            if (!Storage.TryLoad(
                    out Dictionary <ServerAddress, bool> dictionary))
            {
                dictionary = new Dictionary <ServerAddress, bool>();
            }

            var serverAddress = Api.Client.CurrentGame.ServerInfo.ServerAddress;

            dictionary[serverAddress] = true;
            Storage.Save(dictionary);
        }
        /// <summary>
        /// Try to load mod version from client storage.
        /// </summary>
        private static void LoadVersionFromClientStorage()
        {
            // Load settings.
            versionStorage = Api.Client.Storage.GetStorage("Mods/" + ModId + "/Version");
            versionStorage.RegisterType(typeof(Version));
            if (!versionStorage.TryLoad(out VersionFromClientStorage))
            {
                VersionFromClientStorage = new Version("0.0.1");
            }

            // Version changes handling.
            // if (VersionFromClientStorage.CompareTo(CurrentVersion) > 0)

            // Or should I wait until all migration work is done?
            versionStorage.Save(CurrentVersion);
        }
        private void SaveOptionsToStorage()
        {
            if (optionsWithValue.Count == 0)
            {
                return;
            }

            var snapshot = new Dictionary <string, object>();

            foreach (var option in optionsWithValue)
            {
                snapshot[option.Id] = option.GetAbstractValue();
            }

            clientStorage.Save(snapshot);
        }
        private static async void RefreshWelcomeMessage()
        {
            if (Api.IsEditor)
            {
                return;
            }

            var gameServerInfo = Client.CurrentGame.ServerInfo;

            var serverAddress = gameServerInfo.ServerAddress;

            lastGetWelcomeMessageTask = Instance.CallServer(_ => _.ServerRemote_GetWelcomeMessage());

            var welcomeMessage = await lastGetWelcomeMessageTask;

            if (string.IsNullOrWhiteSpace(welcomeMessage))
            {
                if (!Client.CurrentGame.IsConnectedToOfficialServer)
                {
                    return;
                }

                welcomeMessage = OfficialServerWelcomeMessage.Trim();
            }

            // load the last messages from storage
            if (!ClientStorageLastServerMessage.TryLoad(out Dictionary <ServerAddress, string> dictLastMessages))
            {
                dictLastMessages = new Dictionary <ServerAddress, string>();
            }

            if (dictLastMessages.TryGetValue(serverAddress, out var lastMessage) &&
                lastMessage == welcomeMessage)
            {
                // the player already saw this welcome message
                return;
            }

            dictLastMessages[serverAddress] = welcomeMessage;
            ClientStorageLastServerMessage.Save(dictLastMessages);
            ClientShowWelcomeMessageInternal(welcomeMessage);
        }
        private void UpdateInput()
        {
            var move     = None;
            var angleRad = this.characterInput.RotationAngleRad;

            if (CheckIsInputSuppressed() ||
                !Api.Client.CurrentGame.IsSuccessfullyProcessingPhysics)
            {
                // set default input
                this.SetInput(move, angleRad);
                return;
            }

            if (IsButtonHeld(GameButton.MoveUp))
            {
                move |= Up;
            }

            if (IsButtonHeld(GameButton.MoveDown))
            {
                move |= Down;
            }

            if (IsButtonHeld(GameButton.MoveLeft))
            {
                move |= Left;
            }

            if (IsButtonHeld(GameButton.MoveRight))
            {
                move |= Right;
            }

            if (IsButtonDown(GameButton.RunToggle))
            {
                this.runToggle = !this.runToggle;
                StorageRunMode.Save(this.runToggle, writeToLog: false);
            }

            if (this.runToggle)
            {
                move |= ModifierRun;
            }

            if (IsButtonHeld(GameButton.RunTemporary))
            {
                move ^= ModifierRun;
            }

            ConsumeButton(GameButton.MoveUp);
            ConsumeButton(GameButton.MoveDown);
            ConsumeButton(GameButton.MoveLeft);
            ConsumeButton(GameButton.MoveRight);
            ConsumeButton(GameButton.RunToggle);
            ConsumeButton(GameButton.RunTemporary);

            if ((move & Up) != 0 &&
                (move & Down) != 0)
            {
                // cannot move up and down simultaneously
                move &= ~(Up | Down);
            }

            if ((move & Left) != 0 &&
                (move & Right) != 0)
            {
                // cannot move left and right simultaneously
                move &= ~(Left | Right);
            }

            if ((move & (Left | Up | Right | Down))
                == None)
            {
                // cannot run when not moving
                move = None;
            }

            angleRad = this.GetRotationAngleRad();

            this.SetInput(move, angleRad);
        }
Exemple #12
0
 private void Save()
 {
     Storage.Save(this.entries, writeToLog: false);
 }