Ejemplo n.º 1
0
        public IAmeSession Generate()
        {
            ResourceLoader loader = ResourceLoader.Instance;

            IList <Project>   projects      = new List <Project>();
            ProjectJsonReader projectReader = new ProjectJsonReader();

            foreach (string projectPath in this.OpenedProjectFiles)
            {
                try
                {
                    projects.Add(loader.Load <Project>(projectPath, projectReader));
                }
                catch (Exception e)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append("Error reading project ");
                    builder.Append(projectPath);
                    builder.Append(" ");
                    builder.Append(e.Message);
                    Console.Error.WriteLine(builder);
                }
            }

            IList <Map>   maps      = new List <Map>();
            MapJsonReader mapReader = new MapJsonReader();

            foreach (string mapPath in this.OpenedMapFiles)
            {
                try
                {
                    maps.Add(loader.Load <Map>(mapPath, mapReader));
                }
                catch (Exception e)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append("Error reading map ");
                    builder.Append(mapPath);
                    builder.Append(" ");
                    builder.Append(e.Message);
                    Console.Error.WriteLine(builder);
                }
            }
            // TODO Bug: the current map index is incorrect when a map editor is closed.
            // TODO store the current tileset
            AmeSession session = new AmeSession(maps, projects, this.WorkspaceDirectory, this.LastTilesetDirectory, this.LastMapDirectory, this.Version);

            if (session.MapCount > 0)
            {
                session.CurrentMap.Value = maps[this.CurrentMapIndex];
                if (session.CurrentMap.Value.Tilesets.Count > 0)
                {
                    session.CurrentTileset.Value = session.CurrentMap.Value.Tilesets[0];
                }
                session.CurrentProject = session.CurrentMap.Value.Project;
            }

            return(session);
        }
Ejemplo n.º 2
0
        public void RaiseNotification(DependencyObject parent)
        {
            OpenFileDialog openMapDialog = new OpenFileDialog();

            openMapDialog.Title            = "Open Map";
            openMapDialog.Filter           = SaveMapExtension.GetOpenMapSaveExtensions();
            openMapDialog.InitialDirectory = this.session.LastMapDirectory.Value;
            if (openMapDialog.ShowDialog().Value)
            {
                string file = openMapDialog.FileName;
                if (File.Exists(file))
                {
                    MapJsonReader  reader      = new MapJsonReader();
                    ResourceLoader loader      = ResourceLoader.Instance;
                    Map            importedMap = loader.Load <Map>(file, reader);

                    this.session.LastMapDirectory.Value = Directory.GetParent(file).FullName;
                    this.session.Maps.Add(importedMap);
                }
            }
        }
Ejemplo n.º 3
0
        public Project Generate(string path)
        {
            Project project = new Project(this.Name, this.Version);

            project.DefaultPixelScale.Value = this.DefaultPixelScale;
            project.DefaultTileWidth.Value  = this.DefaultTileWidth;
            project.DefaultTileHeight.Value = this.DefaultTileHeight;
            project.Description.Value       = this.Description;
            project.SourcePath.Value        = Directory.GetParent(path).FullName;
            project.ProjectFilename.Value   = Path.GetFileName(path);

            ResourceLoader loader    = ResourceLoader.Instance;
            MapJsonReader  mapReader = new MapJsonReader();

            foreach (string mapPath in this.MapFiles)
            {
                Map map = loader.Load <Map>(mapPath, mapReader);
                project.Maps.Add(map);
            }

            return(project);
        }