Ejemplo n.º 1
0
        public bool LoadMap(string fileName, bool decode)
        {
            if (!this.ConfirmMapChange())
            {
                return(false);
            }

            var mapContents = TCDEncodeDecode.ReadTextFile(fileName, decode);

            if (mapContents == null)
            {
                return(false);
            }

            var openedMap = new Map {
                StringValue = mapContents, Name = Path.GetFileNameWithoutExtension(fileName)
            };

            if (openedMap.HasErrors)
            {
                MessageBox.Show($"Map contains errors, please find and resolve with View > Errors", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            this.CurrentMap    = openedMap;
            this.LoadedMapPath = fileName;
            this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            //var mapLoadSuccess = !openedMap.HasErrors;
            //if (mapLoadSuccess)
            //{
            //    this.CurrentMap = openedMap;
            //    this.LoadedMapPath = fileName;
            //    this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            //}
            //else
            //{
            //    var filteredErrors = openedMap.Errors.Distinct();
            //    if (filteredErrors.Count() < 25)
            //    {
            //        MessageBox.Show($"Map failed to parse, with the following errors:{Environment.NewLine}{string.Join(Environment.NewLine, filteredErrors)}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            //    }
            //    else
            //    {
            //        MessageBox.Show($"Map failed to parse, with many errors.{Environment.NewLine}Please check that you've chosen the right file:{Environment.NewLine}{string.Join(Environment.NewLine, filteredErrors.Take(25))}{Environment.NewLine}...", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            //    }

            //    this.CurrentMap = Constants.BlankMapCreator();
            //    this.LoadedMapPath = null;
            //    this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            //}

            MapRenderer.Refresh();
            MainWindowViewModel.MapLoadProgressEvent?.Invoke();

            return(true);
        }
Ejemplo n.º 2
0
        private Map LoadMap(string fileName, bool decode)
        {
            var mapContents = TCDEncodeDecode.ReadTextFile(fileName, decode);

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

            return(new Map {
                StringValue = mapContents, Name = Path.GetFileNameWithoutExtension(fileName)
            });
        }
Ejemplo n.º 3
0
        public static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Invalid arguments, expected \"ResourcePackingBuildStep.exe <pack|encode> <packed directory> <output file prefix|directory>\"");
                return(-1);
            }

            if (args[0] == "pack")
            {
                var packComplete = false;
                TCDEncodeDecode.PackTCDFile(
                    args[1],
                    args[2],
                    (fileName, progress) =>
                {
                    if (fileName != null)
                    {
                        Console.WriteLine($"({100 * progress:F1}%) {fileName}");
                    }
                    else
                    {
                        packComplete = true;
                    }
                });

                while (!packComplete)
                {
                    Thread.Sleep(1);
                }

                Console.WriteLine($"(100.0%) Directory packed into:");
                Console.WriteLine($"         > {args[1]}Resource.tcd");
                Console.WriteLine($"         > {args[1]}Pattern.tcd");
            }
            else if (args[0] == "encode")
            {
                Directory.CreateDirectory(args[2]);

                var mapfiles = Directory.GetFiles(args[1]);

                for (int i = 0; i < mapfiles.Length; i++)
                {
                    var map             = mapfiles[i];
                    var contents        = TCDEncodeDecode.ReadTextFile(map, false);
                    var encodedContents = TCDEncodeDecode.EncodeMap(contents);

                    var filename = Path.GetFileNameWithoutExtension(map);
                    var newPath  = Path.Combine(args[2], Path.ChangeExtension(filename, ".she"));
                    TCDEncodeDecode.SaveFile(newPath, encodedContents);

                    Console.WriteLine($"({100 * ((double)i / mapfiles.Length):F1}%) {filename}");
                }

                Console.WriteLine($"(100.0%) Map files encoded to directory:");
                Console.WriteLine($"         > {args[2]}");
            }
            else
            {
                Console.Error.WriteLine($"Invalid operation \"{args[0]}\", expected \"pack\" or \"encode\"");
                return(-1);
            }


            return(0);
        }