Esempio n. 1
0
 private void AddDefaultTileProperties(TilesetDocument tileset)
 {
     tileset.AddBlockProperty();
     tileset.AddSpikeProperty();
     tileset.AddLadderProperty();
     tileset.AddWaterProperty();
 }
        public TilesetDocument Load(FilePath filePath)
        {
            var tileset         = _reader.Load(filePath);
            var tilesetDocument = new TilesetDocument(tileset);

            return(tilesetDocument);
        }
        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 void AddDefaultTileProperties(TilesetDocument tileset)
 {
     tileset.AddBlockProperty();
     tileset.AddSpikeProperty();
     tileset.AddLadderProperty();
     tileset.AddWaterProperty();
 }
        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();
                }
            }
        }
Esempio n. 6
0
        private void ChangeTileset(TilesetDocument tileset)
        {
            if (_tileset != null)
            {
                _tileset.TilesheetModified -= RefreshSheet;
            }

            SetTileset(tileset);

            if (_tileset != null)
            {
                _observedProperties = new ObservableCollection <TileProperties>(_tileset.Properties);

                if (!File.Exists(_tileset.SheetPath.Absolute))
                {
                    ChangeSheet();
                }

                _tileset.TilesheetModified += RefreshSheet;
            }
            else
            {
                _observedProperties = new ObservableCollection <TileProperties>();
            }

            OnPropertyChanged("TileProperties");
            OnPropertyChanged("RelSheetPath");
            OnPropertyChanged("Tileset");
        }
 public TilesetDocument Load(FilePath filePath)
 {
     var tilesetReader = _core.Reader.GetTilesetReader(filePath);
     var tileset = tilesetReader.Load(filePath);
     var tilesetDocument = new TilesetDocument(tileset);
     return tilesetDocument;
 }
Esempio n. 8
0
        public TilesetDocument Load(FilePath filePath)
        {
            var tilesetReader   = _core.Reader.GetTilesetReader(filePath);
            var tileset         = tilesetReader.Load(filePath);
            var tilesetDocument = new TilesetDocument(tileset);

            return(tilesetDocument);
        }
Esempio n. 9
0
 public TilesetImporter(TilesetDocument tileset)
 {
     Tileset = tileset;
     if (Tileset != null)
     {
         Tilesheet = SpriteBitmapCache.GetOrLoadImage(Tileset.SheetPath.Absolute);
     }
 }
 public TilesetImporter(TilesetDocument tileset)
 {
     Tileset = tileset;
     if (Tileset != null)
     {
         Tilesheet = SpriteBitmapCache.GetOrLoadImage(Tileset.SheetPath.Absolute);
     }
 }
        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);
        }
Esempio n. 12
0
        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();
        }
        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);
        }
Esempio n. 14
0
        public TilesetDocument CreateNew(FilePath filePath)
        {
            var tileset = new Tileset()
            {
                FilePath = filePath,
                TileSize = 16
            };

            var document = new TilesetDocument(tileset);
            AddDefaultTileProperties(document);

            return document;
        }
Esempio n. 15
0
        public TilesetDocument CreateNew(FilePath filePath)
        {
            var tileset = new Tileset()
            {
                FilePath = filePath,
                TileSize = 16
            };

            var document = new TilesetDocument(tileset);

            AddDefaultTileProperties(document);

            return(document);
        }
Esempio n. 16
0
        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");
        }
Esempio n. 17
0
        private void SetTileset(TilesetDocument tileset)
        {
            _tileset = tileset;

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

            OnPropertyChanged("Brushes");
        }
        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);
                }
            }
        }
        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;
            }
        }
Esempio n. 20
0
 public TilesetDocument Load(FilePath filePath)
 {
     var tileset = _reader.Load(filePath);
     var tilesetDocument = new TilesetDocument(tileset);
     return tilesetDocument;
 }
Esempio n. 21
0
 protected override void SetTileset(TilesetDocument tileset)
 {
     base.SetTileset(tileset);
     _importer = new TilesetImporter(tileset);
     RefreshSheet();
 }