/// <summary> /// Handles the <see cref="CommandLineSwitch.SaveMaps"/> switch. /// </summary> /// <param name="values">The values passed to the switch at the command line.</param> /// <returns>True if completed without errors; false if there were any errors.</returns> static bool HandleSwitch_SaveMaps(string[] values) { var ret = true; var camera = new Camera2D(GameData.ScreenSize); var dynamicEntityFactory = EditorDynamicEntityFactory.Instance; var contentPath = ContentPaths.Dev; // Get the maps var mapInfos = MapHelper.FindAllMaps(); // For each map, load it then save it foreach (var mapInfo in mapInfos) { // Load EditorMap map; try { map = new EditorMap(mapInfo.ID, camera, GetTimeDummy.Instance); map.Load(contentPath, true, dynamicEntityFactory); } catch (Exception ex) { const string errmsg = "Failed to load map ID `{0}`. Exception: {1}"; if (log.IsErrorEnabled) log.ErrorFormat(errmsg, mapInfo.ID, ex); Debug.Fail(string.Format(errmsg, mapInfo.ID, ex)); map = null; ret = false; } // Save try { if (map != null) MapHelper.SaveMap(map, false); } catch (Exception ex) { const string errmsg = "Failed to save map `{0}`. Exception: {1}"; if (log.IsErrorEnabled) log.ErrorFormat(errmsg, mapInfo, ex); Debug.Fail(string.Format(errmsg, mapInfo, ex)); ret = false; } } return ret; }
/// <summary> /// Derived classes override this to initialize their drawing code. /// </summary> protected override void Initialize() { base.Initialize(); if (DesignMode) return; m = new TransBoxManager(); _drawingManager = new DrawingManager(); _drawView = new View(); _camera = new Camera2D(new Vector2(400, 300)); _camera.Size = ScreenSize; _camera.Scale = 1.0f; }
/// <summary> /// Creates the preview of a map. /// </summary> /// <param name="map">The map to create the preview of.</param> /// <param name="drawExtensions">The collection of <see cref="IMapDrawingExtension"/>s applied to the map.</param> public Image CreatePreview(T map, ICollection <IMapDrawingExtension> drawExtensions) { // Set up the new camera var cam = new Camera2D(TextureSize); // Store the existing map values so we can restore them when done var oldCamera = map.Camera; var oldDrawFilter = map.DrawFilter; var oldDrawParticles = map.DrawParticles; var oldExtensions = drawExtensions != null?drawExtensions.ToArray() : new IMapDrawingExtension[0]; // Set the new values SetMapValues(map, cam, DrawFilter, false); if (drawExtensions != null) { drawExtensions.Clear(); } // Create the master image var master = new Bitmap((int)map.Width, (int)map.Height, _generatedImagePixelFormat); // Create the Graphics instance to draw to the master image using (var g = System.Drawing.Graphics.FromImage(master)) { // Create the RenderTarget to draw to using (var renderTarget = new RenderImage((uint)cam.Size.X, (uint)cam.Size.Y)) { // Create the SpriteBatch using (var sb = new SpriteBatch(renderTarget)) { // Loop through as many times as needed to cover the whole map for (var x = 0; x < map.Width; x += (int)renderTarget.Width) { for (var y = 0; y < map.Height; y += (int)renderTarget.Height) { // Clear the target with the background color renderTarget.Clear(BackgroundColor); // Move the camera cam.Min = new Vector2(x, y); // Draw the map sb.Begin(BlendMode.Alpha, cam); map.Draw(sb); sb.End(); // Finalize the rendering to the RenderTarget renderTarget.Display(); // Grab the segment image and copy it to the master image var sfmlImage = renderTarget.Image; var segmentImage = sfmlImage.ToBitmap(); ImageCopy(g, segmentImage, new Point(x, y)); } } } } } // Restore the map values SetMapValues(map, oldCamera, oldDrawFilter, oldDrawParticles); if (drawExtensions != null) { foreach (var ex in oldExtensions) { drawExtensions.Add(ex); } } return(master); }