Пример #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);
        }
Пример #2
0
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            IEventAggregator eventAggregator = containerRegistry.GetContainer().Resolve <IEventAggregator>();
            IConstants       constants       = new Constants();
            IAmeSession      session         = new AmeSession(constants);

            try
            {
                if (File.Exists(constants.SessionFileName))
                {
                    IAmeSessionJsonReader reader = new IAmeSessionJsonReader();
                    session = reader.Read(constants.SessionFileName);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            IActionHandler actionHandler = new ActionHandler(eventAggregator, session);

            containerRegistry.RegisterInstance(typeof(IConstants), constants);
            containerRegistry.RegisterInstance(typeof(IAmeSession), session);
            containerRegistry.RegisterInstance(typeof(IActionHandler), actionHandler);

            ViewModelLocationProvider.Register <MenuOptions, MenuOptionsViewModel>();
            ViewModelLocationProvider.Register <MapEditorDocument, MapEditorViewModel>();
            ViewModelLocationProvider.Register <MapEditorRibbon, MapEditorRibbonViewModel>();
            ViewModelLocationProvider.Register <WindowManager, WindowManagerViewModel>();

            ViewModelLocationProvider.Register <EditProjectWindow, ProjectPropertiesViewModel>();
            ViewModelLocationProvider.Register <NewProjectWindow, ProjectPropertiesViewModel>();
            ViewModelLocationProvider.Register <EditMapWindow, MapPropertiesViewModel>();
            ViewModelLocationProvider.Register <NewMapWindow, MapPropertiesViewModel>();
            ViewModelLocationProvider.Register <EditLayerWindow, LayerPropertiesViewModel>();
            ViewModelLocationProvider.Register <NewLayerWindow, LayerPropertiesViewModel>();
            ViewModelLocationProvider.Register <EditTilesetWindow, TilesetPropertiesViewModel>();
            ViewModelLocationProvider.Register <NewTilesetWindow, TilesetPropertiesViewModel>();
            ViewModelLocationProvider.Register <PreferencesMenu, PreferencesViewModel>();
        }