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); }
// Utility public static List <SortDefinitionItem> CreateFromEntity(IMyEntity entity) { List <SortDefinitionItem> result = new List <SortDefinitionItem>(); try { if (!(entity is IMyCubeBlock)) { return(result); } IMyCubeBlock block = (IMyCubeBlock)entity; MyObjectBuilder_TerminalBlock terminal = (MyObjectBuilder_TerminalBlock)block.GetObjectBuilderCubeBlock(); String customName = terminal.CustomName; if (customName == null || customName == "") { return(result); } Regex regexObj = new Regex(".*[[|(](.*)[]|)]", RegexOptions.Singleline); Match matchResults = regexObj.Match(customName); while (matchResults.Success) { if (matchResults.Groups.Count < 2 || matchResults.Groups[1].Value == "") { matchResults = matchResults.NextMatch(); continue; } String componentList = matchResults.Groups[1].Value; Regex splitRegexObj = new Regex("\"(?:[^\"]|\"\")*\"|[^,]*", RegexOptions.Singleline); Match splitResults = splitRegexObj.Match(componentList); while (splitResults.Success) { if (splitResults.Value == "") { splitResults = splitResults.NextMatch(); continue; } String componentName = splitResults.Value.Replace(" ", ""); if (componentName != "") { TryParseSortItem(result, componentName, entity); } splitResults = splitResults.NextMatch(); } matchResults = matchResults.NextMatch(); } } catch (Exception ex) { Logging.Instance.WriteLine(String.Format("BuildSortListFromEntity(): {0}", ex.ToString())); } return(result); }
public TerminalBlockEntity(CubeGridEntity parent, MyObjectBuilder_TerminalBlock definition, Object backingObject) : base(parent, definition, backingObject) { m_customName = definition.CustomName; }
public static void Import(string filename, out string name, out Interop.Grid grid) { name = string.Empty; grid = null; MyObjectBuilder_Definitions loaded = null; if (File.Exists(filename)) { using (FileStream stream = File.Open(filename, FileMode.Open)) { MyObjectBuilderSerializer.DeserializeXML <MyObjectBuilder_Definitions>(stream, out loaded); } } if (loaded != null) { foreach (MyObjectBuilder_ShipBlueprintDefinition blueprints in loaded.ShipBlueprints) { name = blueprints.Id.SubtypeId; grid = new Grid(loaded) { Name = name, Path = filename, }; foreach (MyObjectBuilder_CubeGrid cubegrid in blueprints.CubeGrids) { foreach (MyObjectBuilder_CubeBlock block in cubegrid.CubeBlocks) { if (block is MyObjectBuilder_TerminalBlock) { MyObjectBuilder_TerminalBlock terminalblock = (MyObjectBuilder_TerminalBlock)block; long entityid = terminalblock.EntityId; string type = GetBlockType(terminalblock.TypeId.ToString()); // TODO Use MyTexts.GetString(MyStringId id) to get default blocks names from MyTexts.resx (for localization) string customname = String.IsNullOrEmpty(terminalblock.CustomName) ? type : terminalblock.CustomName; if (block is MyObjectBuilder_MyProgrammableBlock) { MyObjectBuilder_MyProgrammableBlock prog = (MyObjectBuilder_MyProgrammableBlock)block; grid.AddBlock(type, new TerminalBlock() { Name = customname, EntityID = entityid, IsProgram = true, Program = prog.Program }); } else { grid.AddBlock(type, new TerminalBlock() { Name = customname, EntityID = entityid, IsProgram = false }); } } } } } } }
public TerminalBlockEntity(CubeGridEntity parent, MyObjectBuilder_TerminalBlock definition) : base(parent, definition) { }
public TerminalBlockEntity( CubeGridEntity parent, MyObjectBuilder_TerminalBlock definition, Object backingObject ) : base(parent, definition, backingObject) { m_customName = definition.CustomName; }