Exemple #1
0
        public static MyObjectBuilder_Definitions SaveBlockName(string path, MyObjectBuilder_Definitions definitions, long entityid, string name)
        {
            try
            {
                string backup = String.Format("{0}.bak", path);
                if (!File.Exists(backup))
                {
                    File.Copy(path, backup);
                }
                else
                {
                    FileInfo source = new FileInfo(path);
                    FileInfo dest = new FileInfo(path);

                    if (source.LastWriteTime > dest.LastWriteTime)
                    {
                        File.Copy(path, backup, true);
                    }
                }

                foreach (MyObjectBuilder_ShipBlueprintDefinition blueprints in definitions.ShipBlueprints)
                {
                    foreach (MyObjectBuilder_CubeGrid cubegrid in blueprints.CubeGrids)
                    {
                        foreach (MyObjectBuilder_CubeBlock block in cubegrid.CubeBlocks)
                        {
                            if (block is MyObjectBuilder_TerminalBlock)
                            {
                                if (block.EntityId == entityid)
                                {
                                    MyObjectBuilder_TerminalBlock term = (MyObjectBuilder_TerminalBlock)block;
                                    term.CustomName = name;
                                }
                            }
                        }
                    }
                }

                MyObjectBuilderSerializer.SerializeXML(path, false, definitions);
            }
            catch (Exception ex)
            {
                string message = String.Format(
                    "{0} ({1}){2}{2}{3}",
                    "There was an error saving the blueprint",
                    ex.Message,
                    Environment.NewLine,
                    ex.StackTrace
                );

                System.Windows.MessageBox.Show(
                    message,
                    "SE Workbench",
                    System.Windows.MessageBoxButton.OK,
                    System.Windows.MessageBoxImage.Error
                );
            }

            return definitions;
        }
Exemple #2
0
        public void LoadDefinitions(string path)
        {
            bool result = false;
            MyObjectBuilder_Definitions builder = null;

            using (var fileStream = MyFileSystem.OpenRead(path))
            {
                if (fileStream != null)
                {
                    using (var readStream = fileStream.UnwrapGZip())
                    {
                        if (readStream != null)
                        {
                            MyObjectBuilder_Base obj;
                            result  = MyObjectBuilderSerializer.DeserializeXML(readStream, out obj, typeof(MyObjectBuilder_Definitions), m_overrideMap);
                            builder = obj as MyObjectBuilder_Definitions;
                        }
                    }
                }
            }

            if (!result)
            {
                throw new Exception("Error while reading \"" + path + "\"");
            }

            if (builder.Definitions != null)
            {
                foreach (MyObjectBuilder_DefinitionBase definitionBuilder in builder.Definitions)
                {
                    MyObjectBuilderType.RemapType(ref definitionBuilder.Id, m_overrideMap);
                    MyDefinitionBase definition = GetObjectFactory().CreateInstance(definitionBuilder.TypeId);
                    definition.Init(builder.Definitions[0], new MyModContext());
                    m_definitions.AddDefinition(definition);
                }
            }
        }
 public GridItemViewModel(GridItem item, MyObjectBuilder_Definitions definition, string path)
     : this(item, null)
 {
     _Definitions = definition;
     _Path = path;
 }
Exemple #4
0
 public Grid(MyObjectBuilder_Definitions definitions)
 {
     _Definitions = definitions;
 }
Exemple #5
0
        public static void SaveEnvironmentDefinition()
        {
            EnvironmentDefinition.SunProperties = SunProperties;
            EnvironmentDefinition.FogProperties = FogProperties;
            EnvironmentDefinition.SSAOSettings = SSAOSettings;
            EnvironmentDefinition.HBAOSettings = HBAOSettings;
            EnvironmentDefinition.PostProcessSettings = MyPostprocessSettingsWrapper.Settings;
            EnvironmentDefinition.ShadowSettings.CopyFrom(ShadowSettings);

            var save = new MyObjectBuilder_Definitions();
            save.Environments = new MyObjectBuilder_EnvironmentDefinition[] { (MyObjectBuilder_EnvironmentDefinition)EnvironmentDefinition.GetObjectBuilder() };
            save.Save(Path.Combine(MyFileSystem.ContentPath, "Data", "Environment.sbc"));
        }
 /// <summary>
 /// Method to serialize a configuration file.
 /// </summary>
 /// <param name="definitions">The definition to serialize.</param>
 public void Serialize(MyObjectBuilder_Definitions definitions)
 {
     MyObjectBuilderSerializer.SerializeXML( _configFileInfo.FullName, false, definitions );
 }
        public void ExportPrefabObjectToFile(bool blankOwnerAndMedBays, params IStructureViewBase[] viewModels)
        {
            var saveFileDialog = _saveFileDialogFactory();
            saveFileDialog.Filter = Res.DialogExportPrefabObjectFilter;
            saveFileDialog.Title = Res.DialogExportSandboxObjectTitle;
            saveFileDialog.FileName = "export prefab.sbc";
            saveFileDialog.OverwritePrompt = true;

            if (_dialogService.ShowSaveFileDialog(this, saveFileDialog) == DialogResult.OK)
            {
                var definition = new MyObjectBuilder_Definitions();
                definition.Prefabs = new MyObjectBuilder_PrefabDefinition[1];
                MyObjectBuilder_PrefabDefinition prefab;
                prefab = new MyObjectBuilder_PrefabDefinition();
                prefab.Id.TypeId = new MyObjectBuilderType(typeof(MyObjectBuilder_PrefabDefinition));
                prefab.Id.SubtypeId = Path.GetFileNameWithoutExtension(saveFileDialog.FileName);

                var grids = new List<MyObjectBuilder_CubeGrid>();

                foreach (var viewModel in viewModels)
                {
                    if (viewModel is StructureCubeGridViewModel)
                    {
                        var cloneEntity = (MyObjectBuilder_CubeGrid)viewModel.DataModel.EntityBase.Clone();

                        if (blankOwnerAndMedBays)
                        {
                            // Call to ToArray() to force Linq to update the value.

                            // Clear Medical room SteamId.
                            cloneEntity.CubeBlocks.Where(c => c.TypeId == SpaceEngineersTypes.MedicalRoom).Select(c => { ((MyObjectBuilder_MedicalRoom)c).SteamUserId = 0; return c; }).ToArray();

                            // Clear Owners.
                            cloneEntity.CubeBlocks.Select(c => { c.Owner = 0; c.ShareMode = MyOwnershipShareModeEnum.None; return c; }).ToArray();
                        }

                        // Remove any pilots.
                        cloneEntity.CubeBlocks.Where(c => c.TypeId == SpaceEngineersTypes.Cockpit).Select(c =>
                        {
                            ((MyObjectBuilder_Cockpit)c).ClearPilotAndAutopilot();
                            ((MyObjectBuilder_Cockpit)c).PilotRelativeWorld = null;
                            return c;
                        }).ToArray();

                        grids.Add(cloneEntity);
                    }
                }

                prefab.CubeGrids = grids.ToArray();
                definition.Prefabs[0] = prefab;

                SpaceEngineersApi.WriteSpaceEngineersFile(definition, saveFileDialog.FileName);
            }
        }