public async void SaveCamera(string updateExistingSavedCameraName = null) { DroneSaveInfo ci = new DroneSaveInfo() { gravityMult_ = gravityMult, timestepMult_ = timestepMult, dragMult_ = dragMult, accelerationMult_ = accelerationMult, rotationMult_ = rotationMult, maxVel_ = maxVel, tiltAngle_ = tiltAngle, droneFov_ = droneFov }; if (updateExistingSavedCameraName == null) { var saveName = await MainMenu.GetUserInput(windowTitle : "Enter a save name", defaultText : null, maxInputLength : 30); // If the name is not invalid. if (!string.IsNullOrEmpty(saveName)) { // Save everything from the dictionary into the client's kvp storage. // If the save was successfull: if (SaveCameraInfo("xdm_" + saveName, ci, false)) { MainMenu.Notify($"~g~~h~Info~h~~s~: Drone {saveName} saved."); LoadDroneCameras(); } // If the save was not successfull: else { MainMenu.Notify("~r~~h~Error~h~~s~: Save already exists: (" + saveName + ")"); } } // The user did not enter a valid name to use as a save name for this vehicle. else { MainMenu.Notify("~r~~h~Error~h~~s~: Invalid save name"); } } // We need to update an existing slot. else { SaveCameraInfo("xdm_" + updateExistingSavedCameraName, ci, true); } }
public async void SaveCamera(string updateExistingSavedCameraName = null) { DroneSaveInfo ci = new DroneSaveInfo() { gravityMult_ = gravityMult, timestepMult_ = timestepMult, dragMult_ = dragMult, accelerationMult_ = accelerationMult, rotationMult_ = rotationMult, maxVel_ = maxVel, tiltAngle_ = tiltAngle, droneFov_ = droneFov }; if (updateExistingSavedCameraName == null) { var saveName = await GetUserInput(windowTitle : "Enter a save name", maxInputLength : 30); // If the name is not invalid. if (!string.IsNullOrEmpty(saveName)) { // Save everything from the dictionary into the client's kvp storage. // If the save was successfull: if (SaveCameraInfo("xdm_" + saveName, ci, false)) { Notify.Success($"Drone {saveName} saved."); LoadDroneCameras(); } // If the save was not successfull: else { Notify.Error(CommonErrors.SaveNameAlreadyExists, placeholderValue: "(" + saveName + ")"); } } // The user did not enter a valid name to use as a save name for this vehicle. else { Notify.Error(CommonErrors.InvalidSaveName); } } // We need to update an existing slot. else { SaveCameraInfo("xdm_" + updateExistingSavedCameraName, ci, true); } }
private bool SaveCameraInfo(string saveName, DroneSaveInfo cameraInfo, bool overrideOldVersion) { if (string.IsNullOrEmpty(GetResourceKvpString(saveName)) || overrideOldVersion) { if (!string.IsNullOrEmpty(saveName) && saveName.Length > 4) { // convert string json = JsonConvert.SerializeObject(cameraInfo); // log Debug.WriteLine($"Saving!\nName: {saveName}\nDrone Data: {json}\n"); // save SetResourceKvp(saveName, json); // confirm return(GetResourceKvpString(saveName) == json); } } // if something isn't right, then the save is aborted and return false ("failed" state). return(false); }