예제 #1
0
 public void Run()
 {
     currentContainer = content.contents;
     UpdateContentKeys();
     while (true)
     {
         overflow = -1;
         //buffer = "";
         moreItems = 0;
         Draw("", "", content.contents, 0, false, false);
         if (moreItems > 0)
         {
             MCUtilsConsole.WriteLine("[" + moreItems + " more]");
         }
         //Console.Write(buffer);
         if (cursorBufferLoc > 1)
         {
             while (cursorBufferLoc - Console.WindowTop < 1)
             {
                 Console.WindowTop--;
             }
             while (cursorBufferLoc - Console.WindowTop + Console.WindowHeight < 3)
             {
                 Console.WindowTop++;
             }
         }
         var key = Console.ReadKey().Key;
         if (key == ConsoleKey.Escape)
         {
             break;
         }
         else if (key == ConsoleKey.DownArrow)
         {
             cursorChildPos++;
         }
         else if (key == ConsoleKey.UpArrow)
         {
             cursorChildPos--;
         }
         else if (key == ConsoleKey.RightArrow)
         {
             EnterContainer(currentContentKeys[cursorChildPos].Split(sep).Last());
         }
         else if (key == ConsoleKey.LeftArrow)
         {
             ExitContainer();
         }
         cursorChildPos = Math.Max(0, Math.Min(currentContentKeys.Length - 1, cursorChildPos));
         Console.Clear();
     }
 }
예제 #2
0
        public void Run()
        {
            MCUtilsConsole.WriteLine("Size of block patches (1-4):");
            size = int.Parse(MCUtilsConsole.GetInput());
            size = Math.Max(1, Math.Min(4, size));
            MCUtilsConsole.WriteLine("Enter path to output file:");
            string savepath = GetFilePath(true);

            MCUtilsConsole.WriteLine("Starting...");
            region = new Region(0, 0);
            FillWithRandomBlocks();
            MCUtilsConsole.WriteLine("Writing file...");
            FileStream stream = new FileStream(savepath, FileMode.Create);

            RegionSerializer.WriteRegionToStream(region, stream, Version.DefaultVersion);
            stream.Close();
            MCUtilsConsole.WriteLine("Done");
        }
예제 #3
0
        private string GetFilePath(bool isSaveLocation)
        {
            bool exit = false;

            while (!exit)
            {
                string file = MCUtilsConsole.GetInput();
                if (file.StartsWith("exit"))
                {
                    break;
                }
                if (!isSaveLocation)
                {
                    if (File.Exists(file))
                    {
                        return(file);
                    }
                    else
                    {
                        MCUtilsConsole.WriteWarning("Path is invalid. Try again.");
                    }
                }
                else
                {
                    if (Directory.Exists(Path.GetDirectoryName(file)))
                    {
                        return(file);
                    }
                    else
                    {
                        MCUtilsConsole.WriteWarning("Directory does not exist. Try again.");
                    }
                }
            }
            return(null);
        }
예제 #4
0
        public void Run()
        {
            MCUtilsConsole.WriteLine("Enter path to world 1's region files:");
            world1Path = GetFilePath(true);
            if (world1Path == null)
            {
                return;
            }
            MCUtilsConsole.WriteLine("Enter path to world 2's region files:");
            world2Path = GetFilePath(true);
            if (world2Path == null)
            {
                return;
            }

            MCUtilsConsole.WriteLine("Enter the lower coordinate for the merge (inclusive):");
            lowerBound = ParseCoordinates(MCUtilsConsole.GetInput());
            MCUtilsConsole.WriteLine("Enter the upper coordinate for the merge (inclusive):");
            upperBound = ParseCoordinates(MCUtilsConsole.GetInput());

            int sizeX = upperBound.x - lowerBound.x + 1;
            int sizeZ = upperBound.z - lowerBound.z + 1;

            MCUtilsConsole.WriteLine($"Enter path to map image (Must be {sizeX * 512}x{sizeZ * 512} or {sizeX * 32}x{sizeZ * 32}:");
            string map = GetFilePath(false);

            if (map == null)
            {
                return;
            }
            Bitmap worldMergeMap = new Bitmap(map);
            byte   mergeMode     = 0;

            if (worldMergeMap.Width == sizeX * 512 && worldMergeMap.Height == sizeZ * 512)
            {
                mergeMode = 1;
            }
            if (worldMergeMap.Width == sizeX * 32 && worldMergeMap.Height == sizeZ * 32)
            {
                mergeMode = 2;
            }
            if (mergeMode == 0)
            {
                MCUtilsConsole.WriteError("Map was not the correct size!");
                return;
            }

            MCUtilsConsole.WriteLine("Enter path to output file:");
            outputPath = GetFilePath(true);

            List <RegionRecord> records = new List <RegionRecord>();

            for (int rz = lowerBound.z; rz <= upperBound.z; rz++)
            {
                for (int rx = lowerBound.x; rx <= upperBound.x; rx++)
                {
                    records.Add(new RegionRecord(this, rx, rz));
                }
            }

            int w1only    = 0;
            int w2only    = 0;
            int mergeable = 0;

            foreach (var r in records)
            {
                if (r.CanMerge)
                {
                    mergeable++;
                }
                else
                {
                    if (r.existsInWorld1)
                    {
                        w1only++;
                    }
                    else if (r.existsInWorld2)
                    {
                        w2only++;
                    }
                }
            }

            if (w1only > 0)
            {
                MCUtilsConsole.WriteWarning($"There are {w1only} regions that only exist in world 1.");
            }
            if (w2only > 0)
            {
                MCUtilsConsole.WriteWarning($"There are {w2only} regions that only exist in world 2.");
            }
            MCUtilsConsole.WriteLine($"{mergeable} out of {records.Count} can be merged. Press any key to start.");
            Console.ReadKey();

            MCUtilsConsole.WriteLine("Starting world merge...");
            foreach (var r in records)
            {
                int    localX  = r.loc.x - lowerBound.x;
                int    localZ  = r.loc.z - lowerBound.z;
                int    scale   = mergeMode == 1 ? 512 : 32;
                Bitmap section = worldMergeMap.Clone(new Rectangle(localX * scale, localZ * scale, scale, scale), worldMergeMap.PixelFormat);

                MCUtilsConsole.WriteLine($"Merging {r.loc.x}.{r.loc.z}.mca ...");
                var region1      = RegionLoader.LoadRegion(Path.Combine(world1Path, r.filename));
                var region2      = RegionLoader.LoadRegion(Path.Combine(world2Path, r.filename));
                var merger       = new RegionMerger(region1, region2, section);
                var mergedRegion = merger.Merge();

                MCUtilsConsole.WriteLine("Writing file...");
                FileStream stream = new FileStream(Path.Combine(outputPath, r.filename), FileMode.Create);
                RegionSerializer.WriteRegionToStream(mergedRegion, stream, Version.DefaultVersion);
                stream.Close();
            }
        }
예제 #5
0
        void Draw(string tree, string name, object obj, int indent, bool drawAll, bool isLast)
        {
            if (overflow > 20)
            {
                moreItems++;
                return;
            }
            if (!string.IsNullOrEmpty(tree))
            {
                tree += sep;
            }
            tree += name;
            string s = "";

            for (int i = 0; i < indent; i++)
            {
                if (i == indent - 1)
                {
                    if (isLast)
                    {
                        s += "└ ";
                    }
                    else
                    {
                        s += "│ ";
                    }
                }
                else
                {
                    s += "│ ";
                }
            }
            var  pc             = SplitParentAndChild(tree);
            bool enterContainer = ContainsPath(tree, cursorParent);

            if (IsContainer(obj))
            {
                s += enterContainer ? "▼ " : "► ";
            }
            s += (string.IsNullOrEmpty(name) ? filename : name + "[" + GetTag(obj) + "] = " + obj);
            ChangeState state;

            if (changes.ContainsKey(tree))
            {
                state = changes[tree];
            }
            else
            {
                state = defaultState;
            }
            if (cursorChildPos < currentContentKeys.Length && currentContentKeys[cursorChildPos] == tree)
            {
                overflow = 0;
                //Console.Write(buffer);
                //buffer = "";
                cursorBufferLoc = Console.CursorTop;
                MCUtilsConsole.WriteLine(s, ConsoleColor.White, state.GetColor(true));
            }
            else
            {
                if (overflow >= 0)
                {
                    overflow++;
                }
                if (overflow > 20)
                {
                    moreItems++;
                    return;
                }
                MCUtilsConsole.WriteLine(s, state.GetColor(false));
                //buffer += s + "\n";
            }
            if (obj is CompoundContainer)
            {
                var content = ((CompoundContainer)obj).cont;
                if (enterContainer)
                {
                    var keys = content.Keys.ToArray();
                    for (int i = 0; i < keys.Length; i++)
                    {
                        Draw(tree, keys[i], content[keys[i]], indent + 1, drawAll, i == keys.Length - 1);
                    }
                }
            }
            else if (obj is ListContainer)
            {
                var content = ((ListContainer)obj).cont;
                if (enterContainer)
                {
                    for (int i = 0; i < content.Count; i++)
                    {
                        Draw(tree, i.ToString(), content[i], indent + 1, drawAll, i == content.Count - 1);
                    }
                }
            }
        }