// The miscellaneous assortment of random methods that every lazy programmer // inevitably creates. // // Do not rely on any of these functions hanging around long-term! // See https://www.jeromethibaud.com/en/blog/utils-considered-harmful/ for why; // when we're feeling less lazy these will probably get refactored, but this is // just a fun personal project so, for now, YOLO. using Sandbox.ModAPI.Ingame; using System.Collections.Generic; using System.Text.RegularExpressions; namespace IngameScript { partial class Program { public class Utils { public static List GetBlocksNameContains( IMyGridTerminalSystem gridSystem, string name) { List allBlocks = new List(); List result = new List(); gridSystem.GetBlocks(allBlocks); foreach (IMyTerminalBlock block in allBlocks) { if (block.CustomName.Contains(name)) result.Add(block); } return result; } public static void GetBlocksOfTypeNameContains( IMyGridTerminalSystem gridSystem, List result, string name) where T : class { List allBlocks = new List(); gridSystem.GetBlocksOfType(allBlocks); foreach (T block in allBlocks) { if (((IMyTerminalBlock)block).CustomName.Contains(name)) result.Add(block); } } public static string ExtractTag(IMyTerminalBlock block, string tag) { foreach (string token in block.CustomName.Split(' ')) { if (token.StartsWith(tag)) return token; } return ""; } } } }