/// <summary> /// Loads input bindings from a file. /// </summary> public static void LoadConfig(string path) { InputManager.path = path; Default(); // Create default bindings file if no file exists. if (!File.Exists(path)) { // TODO: One downside of this method is that the config file will not automatically populate with new options when the game version is updated. SaveConfig(path); return; } // Else, load bindings from file. InputConfig inputConfig = JsonHelper <InputConfig> .Load(path); if (inputConfig.Version != inputConfigVersion) { SaveConfig(path); return; } AskSetControls = inputConfig.AskSetControls; foreach (InputNode inputNode in inputConfig.InputNodes) { inputNode.PostSet(); inputNodeList[(int)inputNode.GameCommand] = inputNode; } UpdateAliases(); }
/// <summary> /// Save input bindings to a file. /// </summary> public static void SaveConfig(string path) { InputConfig inputConfig = new InputConfig(); inputConfig.Version = inputConfigVersion; inputConfig.AskSetControls = AskSetControls; foreach (GameCommand command in Enum.GetValues(typeof(GameCommand))) { // Hacky way to prevent certain keys from being written to the XML file (so users don't change them). if ((int)command >= (int)GameCommand.MenuUp) { continue; } inputNodeList[(int)command].PreGet(); inputConfig.InputNodes.Add(inputNodeList[(int)command]); } JsonHelper <InputConfig> .Save(path, inputConfig); }