public override RedstoneSidekickProject AddStructureToProject(RedstoneSidekickProject project, string filePath, string fileName)
        {
            var addedStructureTree = CreateProjectFromFile(filePath, fileName).CraftingTree;

            if (addedStructureTree == null)
            {
                return(project);
            }

            foreach (var item in addedStructureTree.Items)
            {
                var itemInProject = project.CraftingTree.Items.FirstOrDefault(x => x.Item.Id == item.Item.Id);

                if (itemInProject != null)
                {
                    itemInProject.RequiredAmount += item.RequiredAmount;
                }
                else
                {
                    project.CraftingTree.Items.Add(item);
                }
            }

            return(project);
        }
Beispiel #2
0
        public static RedstoneSidekickProject Decode(string projectString)
        {
            RedstoneSidekickProject project = null;

            projectString = projectString.Trim();
            string[] projectSections = projectString.Split('|');

            try
            {
                var projectName         = DecodeProjectName(projectSections[0]);
                var projectCraftingTree = DecodeCraftingTreeItems(projectSections[1]);
                var projectShoppingList = DecodeShoppingList(projectSections[2]);

                project = new RedstoneSidekickProject
                {
                    ProjectName  = projectName,
                    CraftingTree = projectCraftingTree
                };
            }
            catch (Exception ex)
            {
                var message = ex;
            }


            return(project);
        }
Beispiel #3
0
        public static string SaveProjectToFile(RedstoneSidekickProject project)
        {
            string projectAsBase64String = ProjectStringEncoder.Encode(project, ProjectStringEncoder.CraftingTreeOptions.Full);
            string fileName = $"{project.ProjectName}.rsp";

            SaveFileDialog dialog = new SaveFileDialog
            {
                Filter           = "Redstone Sidekick Projects (*.rsp)|*.rsp",
                InitialDirectory = $"{GlobalDataVars.AppDirectory}",
                FileName         = fileName,
                ValidateNames    = true,
                DefaultExt       = ".rsp",
                AddExtension     = true
            };

            if (dialog.ShowDialog() == true)
            {
                fileName = dialog.FileName;

                File.WriteAllText(fileName, projectAsBase64String);

                return(dialog.SafeFileName);
            }

            return("Error");
        }
        public static string Encode(RedstoneSidekickProject project, CraftingTreeOptions craftingTree = CraftingTreeOptions.Light)
        {
            StringBuilder projectStringBuilder = new StringBuilder();

            projectStringBuilder.Append(AppendProjectName(project));

            projectStringBuilder.Append(AppendCraftingTree(project, craftingTree));

            projectStringBuilder.Append(AppendShoppingList(project));

            return(projectStringBuilder.ToString());
        }
        public override RedstoneSidekickProject CreateProjectFromFile(string filePath, string fileName)
        {
            RedstoneSidekickProject project = null;

            if (File.Exists(filePath))
            {
                project = new RedstoneSidekickProject();
                Schematic schematic = NBTConverter.ConvertToSchematic(filePath);

                string projectName = fileName;
                int    extPos      = projectName.LastIndexOf(".");

                project.ProjectName = projectName.Substring(0, extPos);
                var itemDictionary = CreateBlockList(schematic);
                project.CraftingTree = new ProjectCraftingTree(itemDictionary);
            }

            return(project);
        }
Beispiel #6
0
        public static RedstoneSidekickProject LoadProjectFromFile(string filePath, string fileName)
        {
            RedstoneSidekickProject project = null;

            string fileString = File.ReadAllText(filePath);

            project = ProjectStringDecoder.Decode(fileString);

            if (project == null)
            {
                return(project);
            }

            if (project.ProjectName == "Untitled Project")
            {
                string projectName = fileName;
                int    extPos      = projectName.LastIndexOf(".");
                project.ProjectName = projectName.Substring(0, extPos);
            }

            return(project);
        }
        private static string AppendCraftingTree(RedstoneSidekickProject project, CraftingTreeOptions craftingTree)
        {
            var craftingTreeString = "|";

            switch (craftingTree)
            {
            case CraftingTreeOptions.Full:
                craftingTreeString += "2";
                craftingTreeString += ConvertFullCraftingTreeToBase64(project.CraftingTree);
                break;

            case CraftingTreeOptions.Light:
                craftingTreeString += "1";
                craftingTreeString += ConvertLightCraftingTreeToBase64(project.CraftingTree);
                break;

            default:
                craftingTreeString += "0";
                break;
            }

            return(craftingTreeString);
        }
Beispiel #8
0
 public abstract RedstoneSidekickProject AddStructureToProject(RedstoneSidekickProject project, string filePath, string fileName);
Beispiel #9
0
 internal void NewProject()
 {
     _window.SwitchTabs(1);
     Project = new RedstoneSidekickProject();
 }
 private static string AppendShoppingList(RedstoneSidekickProject project)
 {
     return("|");
 }
 private static string AppendProjectName(RedstoneSidekickProject project)
 {
     return($"{project.ProjectName}");
 }