/*! */ protected bool getBlocks <BlockType>(string name, bool isGroup, GetBlockDelegate <BlockType> callback, string typeId = "") where BlockType : class { Func <IMyTerminalBlock, bool, bool> check = (terminalBlock, ignoreTypeErr) => { BlockType type = terminalBlock as BlockType; if (type != null) { if ((typeId == "" || (typeId != "" && terminalBlock.BlockDefinition.TypeIdString == typeId)) && terminalBlock.IsSameConstructAs(ReferenceGrid)) { callback(type); return(true); } else if (!ignoreTypeErr) { log(Console.LogType.Error, $"Block isn't of type {typeId}"); } } else if (!ignoreTypeErr) { log(Console.LogType.Error, $"Block \"{name}\" has type missmatch"); } return(false); }; if (isGroup == true) { IMyBlockGroup group = App.GridTerminalSystem.GetBlockGroupWithName(name); if (group != null) { group.GetBlocks(null, (block) => { check(block, true); return(false); }); } } else { IMyTerminalBlock block = App.GridTerminalSystem.GetBlockWithName(name); if (block == null) { log(Console.LogType.Error, $"Block \"{name}\" dosen't exists"); } else { return(check(block, false)); } } return(false); }
/*! * Get all blocks of type x */ protected bool getBlocks <BlockType>(GetBlockDelegate <BlockType> callback, string typeId = "") where BlockType : class { App.GridTerminalSystem.GetBlocksOfType <IMyTerminalBlock>(null, (block) => { BlockType type = block as BlockType; if (type != null) { if (!block.IsSameConstructAs(ReferenceGrid)) { return(false); } if (typeId == "" || (typeId != "" && block.BlockDefinition.TypeIdString == typeId)) { callback(type); } } //log(Console.LogType.Error, $"Failed to find blocks of type {typeId}"); return(false); }); return(true); }