public static void SaveWorld(GameWorld world, string filePath)
 {
     lock (Lock)
     {
         File.WriteAllText(filePath, JsonConvert.SerializeObject(world, Formatting.Indented));
     }
 }
        private void ChangeGameWorld(string fileName, GameWorld newModel)
        {
            lock (_lock)
            {
                this.GameWorld = new GameWorldViewModel(newModel);
                _filePath = fileName;
                this.TitleFileName = Path.GetFileName(_filePath);

                ResetSaveTimer();
            }
        }
        public GameWorldViewModel(GameWorld originalWorld)
        {
            _worldSize = new WorldSizeViewModel(originalWorld.WorldSize);
            this.DefaultCellTemplateIndex = originalWorld.DefaultCell == null ? (byte)0 : originalWorld.DefaultCell.TemplateIndex;
            this.Templates = originalWorld.Templates;

            var cells = new ObservableCollection<CellViewModel>();

            foreach (var cell in originalWorld.Cells)
            {
                cells.Add(new CellViewModel(cell));
            }

            this.Cells = cells;

            var gameObjects = new ObservableCollection<GameObjectViewModel>();

            foreach (var gameObject in originalWorld.GameObjects)
            {
                gameObjects.Add(new GameObjectViewModel(gameObject));
            }

            this.GameObjects = gameObjects;
        }
        public GameWorld ToModel()
        {
            GameWorld result = new GameWorld();

            result.Templates = this.Templates;
            result.DefaultCell = new DefaultCell(){TemplateIndex = this.DefaultCellTemplateIndex};
            result.GameObjects = this.GameObjects.Select(x => x.ToModel()).ToArray();
            result.Cells = this.Cells.Where(x => x.TemplateIndex != this.DefaultCellTemplateIndex).Select(x => x.ToModel()).ToArray();
            result.WorldSize = this.WorldSize.ToModel();

            return result;
        }