public TilesetImporterViewModel(TilesetDocument tileset)
        {
            _importer = new TilesetImporter(tileset);
            SetTileset(tileset);
            ImportImagesCommand = new RelayCommand(x => ImportImages());
            ExtractCommand = new RelayCommand(x => ExtractImages());
            CompactSheetCommand = new RelayCommand(x => CompactSheet());

            RefreshSheet();
        }
Пример #2
0
        public StageDocument(ProjectDocument project, StageInfo info, StageLinkInfo linkInfo)
        {
            Project  = project;
            History  = new History();
            _map     = info;
            Tileset  = new TilesetDocument(_map.Tileset);
            LinkName = linkInfo.Name;

            // wrap all map screens in screendocuments
            // this should be the only time MegaMan.Screen's are touched directly
            foreach (var pair in _map.Screens)
            {
                WrapScreen(pair.Value);
            }
        }
Пример #3
0
        public StageDocument(ProjectDocument project, StageInfo info, StageLinkInfo linkInfo)
        {
            Project = project;
            History = new History();
            _map = info;
            Tileset = new TilesetDocument(_map.Tileset);
            LinkName = linkInfo.Name;

            // wrap all map screens in screendocuments
            // this should be the only time MegaMan.Screen's are touched directly
            foreach (var pair in _map.Screens)
            {
                WrapScreen(pair.Value);
            }
        }
Пример #4
0
        public StageDocument(ProjectDocument project, StageLinkInfo linkInfo)
        {
            Project = project;
            History = new History();
            var stageReader = new StageXmlReader();
            map = stageReader.LoadStageXml(linkInfo.StagePath);
            Tileset = new TilesetDocument(map.Tileset);
            LinkName = linkInfo.Name;

            // wrap all map screens in screendocuments
            // this should be the only time MegaMan.Screen's are touched directly
            foreach (var pair in map.Screens)
            {
                WrapScreen(pair.Value);
            }
        }
Пример #5
0
        public StageDocument(ProjectDocument project, StageLinkInfo linkInfo)
        {
            Project = project;
            History = new History();
            var stageReader = new StageXmlReader();

            map      = stageReader.LoadStageXml(linkInfo.StagePath);
            Tileset  = new TilesetDocument(map.Tileset);
            LinkName = linkInfo.Name;

            // wrap all map screens in screendocuments
            // this should be the only time MegaMan.Screen's are touched directly
            foreach (var pair in map.Screens)
            {
                WrapScreen(pair.Value);
            }
        }
        public void SaveTileset(TilesetDocument tileset)
        {
            var tilesetWriter = _writerProvider.GetTilesetWriter();
            tilesetWriter.Save(tileset.Tileset);
            SaveBrushes(tileset);

            if (tileset.IsSheetDirty)
            {
                var sheet = SpriteBitmapCache.GetOrLoadImage(tileset.SheetPath.Absolute);

                using (var fileStream = new FileStream(tileset.SheetPath.Absolute, FileMode.OpenOrCreate))
                {
                    BitmapEncoder encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(sheet));
                    encoder.Save(fileStream);
                }

                tileset.IsSheetDirty = false;
            }
        }
Пример #7
0
 public void ChangeTileset(TilesetDocument tileset)
 {
     Tileset = tileset;
     map.ChangeTileset(tileset.Tileset);
     Dirty = true;
 }
        private void AddStageToProject(TilesetDocument tileset)
        {
            var stage = _project.AddStage(Name);
            stage.ChangeTileset(tileset);
            _dataService.SaveProject(_project);

            var args = new StageChangedEventArgs(stage);
            ViewModelMediator.Current.GetEvent<StageChangedEventArgs>().Raise(this, args);
        }
Пример #9
0
 public void ChangeTileset(TilesetDocument tileset)
 {
     Tileset = tileset;
     _map.ChangeTileset(tileset.Tileset);
     Dirty = true;
 }
        protected override void SetTileset(TilesetDocument tileset)
        {
            base.SetTileset(tileset);

            if (tileset == null)
            {
                _observedBrushes = new ObservableCollection<MultiTileBrush>();
            }
            else
            {
                _observedBrushes = new ObservableCollection<MultiTileBrush>(_tileset.Brushes);
            }

            OnPropertyChanged("Brushes");
        }
Пример #11
0
        private void SetTileset(TilesetDocument tileset)
        {
            _tileset = tileset;

            if (tileset == null)
            {
                _observedBrushes = new ObservableCollection<MultiTileBrush>();
            }
            else
            {
                _observedBrushes = new ObservableCollection<MultiTileBrush>(_tileset.Brushes);
            }

            OnPropertyChanged("Brushes");
        }
 protected override void SetTileset(TilesetDocument tileset)
 {
     base.SetTileset(tileset);
     _importer = new TilesetImporter(tileset);
     RefreshSheet();
 }
        protected virtual void SetTileset(TilesetDocument tileset)
        {
            if (_tileset != null)
                _tileset.TilesetModified -= Update;

            _tileset = tileset;

            if (_tileset != null)
            {
                _observedTiles = new ObservableCollection<Tile>(_tileset.Tiles);

                if (_tileset.Tiles.Any())
                    ChangeTile(_tileset.Tiles.First());
                else
                    ChangeTile(null);

                _tileset.TilesetModified += Update;
                ((App)App.Current).AnimateTileset(_tileset.Tileset);
            }
            else
            {
                _observedTiles = new ObservableCollection<Tile>();
                ChangeTile(null);
            }

            OnPropertyChanged("Tiles");
            OnPropertyChanged("SheetPath");
        }
 private string GetBrushFilePath(TilesetDocument tileset)
 {
     string dir = Path.GetDirectoryName(tileset.Tileset.FilePath.Absolute);
     string file = Path.GetFileNameWithoutExtension(tileset.Tileset.FilePath.Absolute);
     string path = Path.Combine(dir, file + "_brushes.xml");
     return path;
 }
        private void SaveBrushes(TilesetDocument tileset)
        {
            string path = GetBrushFilePath(tileset);

            using (var stream = new StreamWriter(path, false))
            {
                foreach (var brush in tileset.Brushes)
                {
                    stream.Write(brush.Width);
                    stream.Write(' ');
                    stream.Write(brush.Height);
                    foreach (var cell in brush.Cells.SelectMany(a => a))
                    {
                        stream.Write(' ');
                        if (cell.tile == null) stream.Write(-1);
                        else stream.Write(cell.tile.Id);
                    }
                    stream.WriteLine();
                }
            }
        }
        private void LoadBrushes(TilesetDocument tileset)
        {
            var path = GetBrushFilePath(tileset);

            if (!File.Exists(path)) return;

            using (var stream = new StreamReader(path))
            {
                while (!stream.EndOfStream)
                {
                    string line = stream.ReadLine();
                    if (line == null) break;

                    string[] info = line.Split(' ');

                    var brush = new MultiTileBrush(int.Parse(info[0]), int.Parse(info[1]));

                    int x = 0; int y = 0;
                    for (int i = 2; i < info.Length; i++)
                    {
                        int id = int.Parse(info[i]);
                        if (id >= 0) brush.AddTile(tileset.Tileset[id], x, y);

                        y++;
                        if (y >= brush.Height)
                        {
                            y = 0;
                            x++;
                        }
                    }

                    tileset.AddBrush(brush);
                }
            }
        }