コード例 #1
0
ファイル: Batch.cs プロジェクト: NCC-Lykos/Chisel
        private string SaveGenesisMap(Document document, string folder)
        {
            var filename = Path.Combine(folder, document.MapFileName);

            MapProvider.SaveMapToFile(filename, document.Map);
            return(filename);
        }
コード例 #2
0
ファイル: MapObjectActionTests.cs プロジェクト: xbloke/sledge
        private void Compare(bool checkDifferent)
        {
            if (File.Exists("after.vmf"))
            {
                File.Delete("after.vmf");
            }
            MapProvider.SaveMapToFile("after.vmf", _document.Map);

            var before = File.ReadAllLines("before.vmf");
            var after  = File.ReadAllLines("after.vmf");

            if (checkDifferent)
            {
                if (before.Length == after.Length)
                {
                    for (var i = 0; i < before.Length; i++)
                    {
                        if (before[i] != after[i])
                        {
                            return;
                        }
                    }
                    Assert.Fail("The two files are the same when they should differ.");
                }
            }
            else
            {
                Assert.AreEqual(before.Length, after.Length);
                for (var i = 0; i < before.Length; i++)
                {
                    Assert.AreEqual(before[i], after[i]);
                }
            }
        }
コード例 #3
0
ファイル: MapObjectActionTests.cs プロジェクト: xbloke/sledge
 private void SaveBefore()
 {
     if (File.Exists("before.vmf"))
     {
         File.Delete("before.vmf");
     }
     MapProvider.SaveMapToFile("before.vmf", _document.Map);
 }
コード例 #4
0
        public bool SaveFile(string path = null, bool forceOverride = false, bool switchPath = true)
        {
            path = forceOverride ? path : path ?? MapFile;
            if (path == null)
            {
                using (var sfd = new SaveFileDialog())
                {
                    var filter = String.Join("|", FileTypeRegistration.GetSupportedExtensions()
                                             .Where(x => x.IsPrimaryFormat).Select(x => x.Description + " (*" + x.Extension + ")|*" + x.Extension));
                    var all = FileTypeRegistration.GetSupportedExtensions().Where(x => x.IsPrimaryFormat).Select(x => "*" + x.Extension).ToArray();
                    sfd.Filter = "All supported formats (" + String.Join(", ", all) + ")|" + String.Join(";", all) + "|" + filter;
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        path = sfd.FileName;
                    }
                }
            }
            if (path == null)
            {
                return(false);
            }

            // Save the 3D camera position
            var cam = ViewportManager.Viewports.OfType <Viewport3D>().Select(x => x.Camera).FirstOrDefault();

            if (cam != null)
            {
                if (Map.ActiveCamera == null)
                {
                    Map.ActiveCamera = !Map.Cameras.Any() ? new Camera {
                        LookPosition = Coordinate.UnitX * Map.GridSpacing * 1.5m
                    } : Map.Cameras.First();
                    if (!Map.Cameras.Contains(Map.ActiveCamera))
                    {
                        Map.Cameras.Add(Map.ActiveCamera);
                    }
                }
                var dist = (Map.ActiveCamera.LookPosition - Map.ActiveCamera.EyePosition).VectorMagnitude();
                var loc  = cam.Location;
                var look = cam.LookAt - cam.Location;
                look.Normalize();
                look = loc + look * (float)dist;
                Map.ActiveCamera.EyePosition  = new Coordinate((decimal)loc.X, (decimal)loc.Y, (decimal)loc.Z);
                Map.ActiveCamera.LookPosition = new Coordinate((decimal)look.X, (decimal)look.Y, (decimal)look.Z);
            }
            Map.WorldSpawn.EntityData.SetPropertyValue("wad", string.Join(";", GetUsedTexturePackages().Select(x => x.PackageRoot).Where(x => x.EndsWith(".wad"))));
            MapProvider.SaveMapToFile(path, Map);
            if (switchPath)
            {
                MapFile     = path;
                MapFileName = Path.GetFileName(MapFile);
                History.TotalActionsSinceLastSave = 0;
                Mediator.Publish(EditorMediator.DocumentSaved, this);
            }
            return(true);
        }
コード例 #5
0
ファイル: InvalidSolidTest.cs プロジェクト: NCC-Lykos/Chisel
        public void GenerateInvalidSolidsTest()
        {
            var path = @"D:\Github\Chisel\_Resources\InvalidTest";

            MapProvider.Register(new RmfProvider());
            for (var i = 0.166m; i <= 0.167m; i += 0.0001m)
            {
                var map = GenerateInvalidSolidMap(i, 0, 1000);
                MapProvider.SaveMapToFile(System.IO.Path.Combine(path, i.ToString("#0.0000") + ".rmf"), map);
            }
        }
コード例 #6
0
        public void Autosave()
        {
            if (!Game.Autosave)
            {
                return;
            }
            var dir = GetAutosaveFolder();
            var fmt = GetAutosaveFormatString();

            // Only save on change if the game is configured to do so
            if (dir != null && fmt != null && (History.TotalActionsSinceLastAutoSave != 0 || !Game.AutosaveOnlyOnChanged))
            {
                var date     = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd-hh-mm-ss");
                var filename = String.Format(fmt, date);
                if (System.IO.File.Exists(filename))
                {
                    System.IO.File.Delete(filename);
                }

                // Save the file
                MapProvider.SaveMapToFile(Path.Combine(dir, filename), Map);

                // Delete extra autosaves if there is a limit
                if (Game.AutosaveLimit > 0)
                {
                    var asFiles = GetAutosaveFiles(dir);
                    foreach (var file in asFiles.OrderByDescending(x => x.Value).Skip(Game.AutosaveLimit))
                    {
                        if (System.IO.File.Exists(file.Key))
                        {
                            System.IO.File.Delete(file.Key);
                        }
                    }
                }

                // Publish event
                Mediator.Publish(EditorMediator.FileAutosaved, this);
                History.TotalActionsSinceLastAutoSave = 0;

                if (Game.AutosaveTriggerFileSave && MapFile != null)
                {
                    SaveFile();
                }
            }

            // Reschedule autosave
            var at = Math.Max(1, Game.AutosaveTime);

            Scheduler.Schedule(this, Autosave, TimeSpan.FromMinutes(at));
        }
コード例 #7
0
ファイル: Batch.cs プロジェクト: NCC-Lykos/Chisel
        private string SaveCordonMap(Document document, string folder)
        {
            var filename = Path.ChangeExtension(document.MapFileName, ".map");
            var map      = document.Map;

            if (document.Map.Cordon)
            {
                map = new Map();
                map.WorldSpawn.EntityData = document.Map.WorldSpawn.EntityData.Clone();
                var entities = document.Map.WorldSpawn.GetAllNodesContainedWithin(document.Map.CordonBounds);
                foreach (var mo in entities)
                {
                    var clone = mo.Clone();
                    clone.SetParent(map.WorldSpawn);
                }
                var outside = new Box(map.WorldSpawn.GetChildren().Select(x => x.BoundingBox).Union(new[] { document.Map.CordonBounds }));
                outside = new Box(outside.Start - Coordinate.One, outside.End + Coordinate.One);
                var inside = document.Map.CordonBounds;

                var brush = new Brushes.BlockBrush();

                var cordon = (Solid)brush.Create(map.IDGenerator, outside, null, 0).First();
                var carver = (Solid)brush.Create(map.IDGenerator, inside, null, 0).First();
                cordon.Faces.ForEach(x => x.Texture.Name = "BLACK");

                // Do a carve (TODO: move carve into helper method?)
                foreach (var plane in carver.Faces.Select(x => x.Plane))
                {
                    Solid back, front;
                    if (!cordon.Split(plane, out back, out front, map.IDGenerator))
                    {
                        continue;
                    }
                    front.SetParent(map.WorldSpawn);
                    cordon = back;
                }

                if (document.MapFileName.EndsWith(".map"))
                {
                    filename = Path.GetFileNameWithoutExtension(filename) + "_cordon.map";
                }
            }
            map.WorldSpawn.EntityData.SetPropertyValue("wad", string.Join(";", document.GetUsedTexturePackages().Select(x => x.PackageRoot).Where(x => x.EndsWith(".wad"))));
            filename = Path.Combine(folder, filename);
            MapProvider.SaveMapToFile(filename, map);
            return(filename);
        }