Esempio n. 1
0
        void LoadMaps(params string[] fileNames)
        {
            var items = new Dictionary <string, ListViewItem>();

            foreach (string f in fileNames)
            {
                items[f] = lvMaps.Items.Add(Path.GetFileName(f), "Loading");
            }

            bConvertAll.Enabled      = false;
            bConvertSelected.Enabled = false;

            Task.Run(() =>
            {
                foreach (string f in fileNames)
                {
                    MapsLoading.Add(f);

                    var containsMap = false;
                    try
                    {
                        var gbx = IslandConverter.LoadGBX(f, out TimeSpan? completionTime);

                        if (gbx != null)
                        {
                            containsMap = false;

                            var map    = gbx.MainNode;
                            var mapUid = map.MapUid;

                            if (Maps.ContainsKey(mapUid))
                            {
                                containsMap = true;
                            }

                            if (!Maps.ContainsKey(mapUid))
                            {
                                Maps.Add(mapUid, gbx);
                            }

                            Invoke(new Action(() =>
                            {
                                ListViewItem item = items[f];

                                item.Name = mapUid;

                                if (gbx.MainNode.Thumbnail == null)
                                {
                                    item.ImageKey = "";
                                }
                                else
                                {
                                    lvMaps.LargeImageList.Images.Add(mapUid, gbx.MainNode.GetThumbnailBitmap());
                                    item.ImageKey = mapUid;
                                }

                                item.Text = Formatter.Deformat(map.MapName);
                            }));
                        }
                        else
                        {
                            containsMap = true;
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Write(e.ToString());
                        MessageBox.Show(e.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    Invoke(new Action(() =>
                    {
                        ListViewItem item = items[f];

                        UpdateSelectedMap();
                        if (containsMap)
                        {
                            item.Remove();
                        }
                    }));

                    MapsLoading.RemoveAll(x => x == f);
                }

                Invoke(new Action(() =>
                {
                    if (MapsLoading.Count == 0 && Maps.Count > 0)
                    {
                        bConvertAll.Enabled = true;
                    }
                }));
            });
        }
Esempio n. 2
0
        void UpdateSelectedMap()
        {
            if (lvMaps.View == View.Tile || lvMaps.SelectedItems.Count == 0 || lvMaps.SelectedItems.Count > 1)
            {
                lMapName.Text         = "";
                lUID.Text             = "";
                lAuthor.Text          = "";
                lSize.Text            = "";
                lDecoration.Text      = "";
                lMedals.Text          = "";
                lAuthorM.Text         = "";
                lGoldM.Text           = "";
                lSilverM.Text         = "";
                lBronzeM.Text         = "";
                lMapType.Text         = "";
                lBlockRange.Text      = "";
                lBlockRange.BackColor = Color.Transparent;
                ttBlockRange.SetToolTip(lBlockRange, "");

                pbThumbnail.Image = null;
            }

            if (Maps.Count == 0)
            {
                bConvertAll.Enabled = false;
            }
            else if (MapsLoading.Count == 0)
            {
                bConvertAll.Enabled = true;
            }

            bConvertSelected.Enabled = false;

            if (lvMaps.SelectedItems.Count > 0)
            {
                if (MapsLoading.Count == 0)
                {
                    bConvertSelected.Enabled = true;
                }

                bConvertSelected.Text = "Convert selected maps";

                if (lvMaps.SelectedItems.Count == 1)
                {
                    bConvertSelected.Text = "Convert selected map";

                    var item = lvMaps.SelectedItems[0];
                    if (Maps.TryGetValue(item.Name, out GameBox <CGameCtnChallenge> gbx))
                    {
                        var map = gbx.MainNode;

                        lMapName.Text = Formatter.Deformat(map.MapName);
                        lUID.Text     = "UID: " + map.MapUid;
                        lAuthor.Text  = "Author: " + Formatter.Deformat(map.AuthorLogin);

                        lSize.Text = "Size: " + map.Size.ToString();
                        if (map.Size == (45, 36, 45))
                        {
                            lSize.Text += " (made in TMUF)";
                        }
                        else if (map.Size == (36, 36, 36))
                        {
                            lSize.Text += " (made in TMU or Sunrise)";
                        }
                        else
                        {
                            lSize.Text += " (made in China)";
                        }

                        lDecoration.Text = "Decoration: " + map.Decoration.ID;
                        lMedals.Text     = "Medals:";
                        lAuthorM.Text    = "Author: " + (map.ChallengeParameters.AuthorTime.HasValue ? map.ChallengeParameters.AuthorTime.Value.ToString("m':'ss':'fff") : "None");
                        lGoldM.Text      = "Gold: " + (map.ChallengeParameters.GoldTime.HasValue ? map.ChallengeParameters.GoldTime.Value.ToString("m':'ss':'fff") : "None");
                        lSilverM.Text    = "Silver: " + (map.ChallengeParameters.SilverTime.HasValue ? map.ChallengeParameters.SilverTime.Value.ToString("m':'ss':'fff") : "None");
                        lBronzeM.Text    = "Bronze: " + (map.ChallengeParameters.BronzeTime.HasValue ? map.ChallengeParameters.BronzeTime.Value.ToString("m':'ss':'fff") : "None");
                        lMapType.Text    = "Map type: " + map.Mode.ToString();

                        blockRange = IslandConverter.DefineMapRange(map.Blocks.ToArray(), out minCoord);

                        if (blockRange.X <= 32 && blockRange.Z <= 32)
                        {
                            lBlockRange.BackColor = Color.Lime;
                            ttBlockRange.SetToolTip(lBlockRange, "This map fits the default Stadium64x64 base! You can choose your map base size just fine without issues.");

                            x32Button.Text = "32x32 area with normal border with Island background, doesn\'t require OpenPlanet to work (recommended)";
                            x45Button.Text = "45x45 area with small border with Island background, requires OpenPlanet to work (also recommended)";
                        }
                        else
                        {
                            lBlockRange.BackColor = Color.Yellow;
                            ttBlockRange.SetToolTip(lBlockRange, "This map is bigger than the default Stadium64x64 base! Choose the map base size wisely.");

                            x32Button.Text = "32x32 area with normal border with Island background, doesn\'t require OpenPlanet to work";
                            x45Button.Text = "45x45 area with small border with Island background, requires OpenPlanet to work (recommended)";
                        }

                        lBlockRange.Text = "Block range: " + blockRange;

                        if (map.Thumbnail != null)
                        {
                            pbThumbnail.Image = map.GetThumbnailBitmap();
                        }
                    }
                }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var version  = assembly.GetName().Version;

            bool    wizard             = false;
            int?    seed               = default;
            MapSize?size               = default;
            bool?   cutoff             = default;
            bool?   noask              = default;
            bool?   ignoreMediaTracker = default;
            string  outputFolder       = null;

            string[] fileNames = new string[0];

            if (args.Length == 0)
            {
                Console.Write("Starting the Island Converter! ");

                Thread.Sleep(500);

                ShowWindow(GetConsoleWindow(), 0);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ConverterForm());

                return;
            }
            else
            {
                ShowWindow(GetConsoleWindow(), 5);

                Log.OnLogEvent  += LogConsoleMode;
                Log.OnPushEvent += PushConsoleMode;

                Console.Title = $"Island Converter {version}";

                if (args.Length == 1 && (args[0] == "-console" || args[0] == "-wizard"))
                {
                    wizard = true;

                    Console.WriteLine($"Island Converter {version} WIZARD");
                    Console.WriteLine();
                    Console.Write("Please select the map you want to convert to TM2 Island.");

                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Filter = "GBX (*.Gbx)|*.Gbx|All files (*.*)|*.*";

                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.WriteLine(ofd.FileName);
                        Console.Write($"Are you sure you want to convert this file? (Y/N) ");
                        if (Console.ReadKey().Key != ConsoleKey.Y)
                        {
                            return;
                        }
                        fileNames = new string[] { ofd.FileName };
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    var arguments = args.Skip(1);

                    Console.WriteLine();

                    if (arguments.Count() > 0)
                    {
                        Console.WriteLine($"Specified optional arguments: {string.Join(" ", arguments)}");

                        var enumerator = arguments.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            switch (enumerator.Current)
                            {
                            case "-seed":
                                if (enumerator.MoveNext())
                                {
                                    var seedParam = enumerator.Current;
                                    if (int.TryParse(seedParam, out int num))
                                    {
                                        seed = num;
                                    }
                                    else
                                    {
                                        seed = seedParam.GetHashCode();
                                    }

                                    Console.WriteLine($"- Seed: {seedParam} {(Convert.ToInt32(seedParam) != seed ? $"({seed})" : "")}");
                                }
                                break;

                            case "-size":
                                if (enumerator.MoveNext())
                                {
                                    var sizeParam = enumerator.Current;
                                    switch (sizeParam)
                                    {
                                    case "x31":
                                        size = MapSize.X31WithSmallBorder;
                                        break;

                                    case "x32":
                                        size = MapSize.X32WithBigBorder;
                                        break;

                                    case "x45":
                                        size = MapSize.X45WithSmallBorder;
                                        break;
                                    }

                                    Console.WriteLine($"- Size: {size}");
                                }
                                break;

                            case "-cutoff":
                                cutoff = true;
                                Console.WriteLine($"- Cutoff: {cutoff}");
                                break;

                            case "-noask":
                                noask = true;
                                Console.WriteLine($"- No ask: {noask}");
                                break;

                            case "-ignoremt":
                                ignoreMediaTracker = true;
                                Console.WriteLine($"- Ignore MediaTracker: {ignoreMediaTracker}");
                                break;

                            case "-out":
                                if (enumerator.MoveNext())
                                {
                                    outputFolder = enumerator.Current;
                                    Console.WriteLine($"- Output folder: {outputFolder}");
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine($"No specified optional arguments.");
                    }

                    if (!seed.HasValue)
                    {
                        seed = Environment.TickCount;
                        Console.WriteLine($"- Seed: {seed}");
                    }

                    if (!size.HasValue)
                    {
                        size = MapSize.X45WithSmallBorder;
                        Console.Write($"- Size: {size} ");
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("(will require OpenPlanet)");
                        Console.ResetColor();
                    }

                    if (!cutoff.HasValue)
                    {
                        cutoff = false;
                        Console.WriteLine($"- Cutoff: {cutoff}");
                    }

                    if (!noask.HasValue)
                    {
                        noask = false;
                        Console.WriteLine($"- No ask: {noask}");
                    }

                    if (!ignoreMediaTracker.HasValue)
                    {
                        ignoreMediaTracker = false;
                        Console.WriteLine($"- Ignore MediaTracker: {ignoreMediaTracker}");
                    }

                    if (outputFolder == null)
                    {
                        outputFolder = "output";
                        Console.WriteLine($"- Output folder: output");
                    }

                    Console.WriteLine();

                    var fileOrDirectory = args[0];

                    if (File.Exists(fileOrDirectory))
                    {
                        fileNames = new string[] { fileOrDirectory };
                        if (!noask.Value)
                        {
                            Console.Write($"Are you sure you want to convert {fileOrDirectory}? (Y/N) ");
                        }
                    }
                    else if (Directory.Exists(fileOrDirectory))
                    {
                        fileNames = Directory.GetFiles(fileOrDirectory, "*", SearchOption.AllDirectories);
                        if (!noask.Value)
                        {
                            Console.Write($"Are you sure you want to convert everything in the directory {fileOrDirectory}? (Y/N) ");
                        }
                    }
                    else
                    {
                        Console.Write("File or directory not found.");
                        Console.ReadKey();

                        return;
                    }

                    if (!noask.Value && Console.ReadKey().Key != ConsoleKey.Y)
                    {
                        return;
                    }
                }
            }

            Console.Clear();

            Random random = new Random(seed.GetValueOrDefault());

            foreach (var f in fileNames)
            {
                Log.Write(f);

                var gbx = IslandConverter.LoadGBX(f, out TimeSpan? finishMapLoad);
                if (gbx == null)
                {
                    continue;
                }

                var map = gbx.MainNode;

                var blocks = map.Blocks.ToArray();

                Int3 mapRange = IslandConverter.DefineMapRange(blocks, out Int3? minCoord);

                if (wizard)
                {
                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine($"Selected valid map:\n{Path.GetFileName(f)} (loaded in {finishMapLoad.Value.TotalMilliseconds}ms)\n");

                        Console.Write($"- Name: ");
                        Console.WriteLine(Formatter.Deformat(map.MapName));

                        Console.WriteLine($"- UID: {map.MapUid}");
                        Console.WriteLine($"- Author: {map.AuthorLogin}");

                        Console.Write($"- Size: {map.Size} ");
                        if (map.Size == (45, 36, 45))
                        {
                            Console.WriteLine("(made in TMUF)");
                        }
                        else if (map.Size == (36, 36, 36))
                        {
                            Console.WriteLine("(made in Sunrise or TMU)");
                        }