Example #1
0
        public static void OpenFile <T>(string defaultName, string extension, Action <T, string> loadedFileObjectCallback)
        {
            var extensionLowerCase = extension.ToLower();
            var extensionUpperCase = extension.ToUpper();
            var dialog             = new OpenFileDialog {
                FileName   = defaultName,
                DefaultExt = $"*.{extensionLowerCase}",
                Filter     = $"{extensionUpperCase}|*.{extensionLowerCase}"
            };
            var result = dialog.ShowDialog();

            if (result != true)
            {
                return;
            }

            T fileAsLoadedObject;

            try {
                fileAsLoadedObject = JsonService.LoadGet <T>(dialog.FileName, fullPathProvided: true);
            }
            catch (Exception e) {
                // throw new FileServiceException($"Could not load file from {dialog.FileName}", e);
                MessageBox.Show($"Could not load file from {dialog.FileName}: {e.InnerException?.Message}", "FileService returned an Error", MessageBoxButton.OK);
                return;
            }
            loadedFileObjectCallback.Invoke(fileAsLoadedObject, dialog.FileName);
        }
Example #2
0
        public TileSet GetTileset(string path)
        {
            if (Factory.TryGetValue(path, out var tileSet))
            {
                return(tileSet);
            }

            tileSet = JsonService.LoadGet <TileSet>(path);
            Factory.Add(path, tileSet);
            return(tileSet);
        }
Example #3
0
        public TileMap LoadMap(string path)
        {
            if (Factory.TryGetValue(path, out var map))
            {
                return(map);
            }

            var tileMap = JsonService.LoadGet <TileMap>(path);

            Factory.Add(path, tileMap);
            return(tileMap);
        }