private void Button_Click(object sender, RoutedEventArgs e) { // Create new project SaveFileDialog newProjectDialog = new SaveFileDialog(); newProjectDialog.Filter = "PestControl Engine Animation Project (*.animproj)|*.animproj|All files (*.*)|*.*"; if (newProjectDialog.ShowDialog() == true) { FileStream stream = File.Create(newProjectDialog.FileName); stream.Close(); Stream projectStream; if ((projectStream = newProjectDialog.OpenFile()) != null) { string jsonOutput = ""; ProjectInfoJson projectInfo = new ProjectInfoJson() { ContentPath = $"{new FileInfo(newProjectDialog.FileName).Directory.FullName}\\content", ProjectSaveIncrement = 0, ProjectName = newProjectDialog.SafeFileName.Substring(0, newProjectDialog.SafeFileName.Length - 9) }; MainWindow.project.ProjectPath = $"{newProjectDialog.FileName}"; jsonOutput = JsonConvert.SerializeObject(projectInfo); projectStream.Dispose(); File.WriteAllText(newProjectDialog.FileName, jsonOutput); } Close(); } }
public ProjectInfoJson GetProjectInfo() { string jsonOutput = ""; jsonOutput = File.ReadAllText(ProjectPath); ProjectInfoJson projectInfo = JsonConvert.DeserializeObject <ProjectInfoJson>(jsonOutput); return(projectInfo); }
/// <summary> /// This returns the content path for the current project and also makes sure the content path exists. /// </summary> /// <returns></returns> public string GetContentPath() { ProjectInfoJson projInfo = GetProjectInfo(); if (!Directory.Exists(projInfo.ContentPath)) { try { Directory.CreateDirectory(projInfo.ContentPath); } catch (UnauthorizedAccessException) { return(""); } } return(projInfo.ContentPath); }
public void SaveProject(string path, MainWindow window) { if (window == null) { return; } TimeLine TimeLine = window.MainTimeline; ProjectInfoJson projectInfo = GetProjectInfo(); projectInfo.animations.Clear(); foreach (Keyframe keyFrame in TimeLine.GetKeyframes()) { Dictionary <string, SpriteboxJson> spriteBoxes = new Dictionary <string, SpriteboxJson>(); foreach (KeyValuePair <string, Spritebox> spr in keyFrame.GetSpriteBoxes()) { spriteBoxes.Add(spr.Key, Spritebox.ToJsonElement(spr.Value)); } Animation animation = new Animation { timelineX = keyFrame.PositionX, spriteBoxes = spriteBoxes }; projectInfo.animations.Add(animation); } projectInfo.TimelineEnd = TimeLine.TimeLineEnd; projectInfo.ProjectSaveIncrement += 1; SaveJSON(projectInfo, path); }
public static void WriteAnimationFile(string filePath, ProjectManager projectManager) { FileInfo file = new FileInfo(filePath); // Null checking if (file == null) { return; } if (projectManager == null) { return; } BinaryWriter binaryWriter = new BinaryWriter(file.Open(FileMode.OpenOrCreate)); // HEADER // PestControlAnimationBinaryFile{version number} binaryWriter.Write(headerName); binaryWriter.Write(currentVersion); // Project info binaryWriter.Write(projectManager.GetProjectInfo().Loop); binaryWriter.Write(projectManager.GetProjectInfo().LoopToFrame); binaryWriter.Write(projectManager.GetProjectInfo().ProjectName); binaryWriter.Write(projectManager.GetProjectInfo().TimelineEnd); // Keyframes // First write amount of keyframes ProjectInfoJson projectInfo = projectManager.GetProjectInfo(); List <Animation> animations = projectInfo.animations; binaryWriter.Write(animations.Count); foreach (Animation frame in animations) { binaryWriter.Write(frame.timelineX); // Write spritebox info // First write amount of SpriteBoxes binaryWriter.Write(frame.spriteBoxes.Count); foreach (KeyValuePair <string, SpriteboxJson> pair in frame.spriteBoxes) { SpriteboxJson spriteBox = pair.Value; // Name of SpriteBox binaryWriter.Write(pair.Key); // Other info of SpriteBox binaryWriter.Write(spriteBox.posX); binaryWriter.Write(spriteBox.posY); binaryWriter.Write(spriteBox.width); binaryWriter.Write(spriteBox.height); binaryWriter.Write(spriteBox.textureKey); binaryWriter.Write(spriteBox.rotation); binaryWriter.Write(spriteBox.sourceX); binaryWriter.Write(spriteBox.sourceY); binaryWriter.Write(spriteBox.sourceWidth); binaryWriter.Write(spriteBox.sourceHeight); binaryWriter.Write(spriteBox.layer); binaryWriter.Write(spriteBox.visible); } } binaryWriter.Dispose(); }
private void SaveJSON(ProjectInfoJson projectInfo, string path) { string output = JsonConvert.SerializeObject(projectInfo); File.WriteAllText(path, output); }