private static void ListBlocks(IList args, IMethodContext context) { ImplLogger.LogImpl("listblocks", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); Log.Write("TypeName/SubtypeName \"Name\" [IntityId]"); Log.WriteLine(); foreach (var block in blocks) { Log.WriteFormat("{0}/{1} \"{2}\" [{3}]", new object[] { block.GetType().Name, block.BlockDefinition.SubtypeName, block.CustomName, block.EntityId }); } }
public static void Action(IList args, IMethodContext context) { ImplLogger.LogImpl("action", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; string action = (string)args[2]; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); foreach (var block in blocks) { if (block.HasAction(action)) { block.ApplyAction(action); } else { Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, "block \"{0}\" does not support action \"{1}\", ignoring", block.CustomName, action); } } }
public static void Data(IList args, IMethodContext context) { ImplLogger.LogImpl("customdata", args); var type = (MatchingType)args[0]; var filter = (string)args[1]; var append = (bool)args[2]; var permision = (DataPermision)args[3]; var value = (string)args[4]; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); foreach (var block in blocks) { if (block is IMyProgrammableBlock && permision < DataPermision.AllowPB) { Log.Write(ImplLogger.LOG_CAT, LogLevel.Error, "permition AllowPB required to overwrite programmable block's data"); Log.Write(ImplLogger.LOG_CAT, LogLevel.Error, $"skipping \"{block.CustomName}\""); continue; } if (block == Program.Current.Me && permision < DataPermision.AllowSelf) { Log.Write(ImplLogger.LOG_CAT, LogLevel.Error, "permition AllowSelf required to overwrite user script"); Log.Write(ImplLogger.LOG_CAT, LogLevel.Error, $"skipping \"{block.CustomName}\" (this is me)"); continue; } block.CustomData = append ? (block.CustomData + value) : value; } }
internal static void ListActions(IList args, IMethodContext context) { ImplLogger.LogImpl("listactions", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); List <ITerminalAction> actions = new List <ITerminalAction>(); foreach (var block in blocks) { Log.WriteFormat("block \"{0}\" of type \"{1}\" have actions:", new object[] { block.CustomName, block.GetType().Name }); actions.Clear(); block.GetActions(actions); foreach (var action in actions) { Log.WriteFormat("\"{0}\": {1}", new object[] { action.Id, action.Name }); } Log.WriteLine(); } }
internal static void Test3(IList args, IMethodContext context) { ImplLogger.LogImpl("test3", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; // string prop = (string)args[2]; var blocks = new List <IMyTerminalBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); Log.Write("TypeName/SubtypeName \"Name\" [IntityId]"); Log.WriteLine(); foreach (var block in blocks) { var propDef = block.GetProperty("FontColor"); Log.WriteFormat("name as sb {0}", propDef.As <Color>()); Log.WriteFormat("name as int {0}", propDef.As <int>()); Log.WriteFormat("existing prop {0}", block.GetProperty("FontColor")); Log.WriteFormat("unexisting prop {0}", block.GetProperty("someunexistingproperty")); } }
public static void Run(IList args, IMethodContext context) { ImplLogger.LogImpl("run", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; string argument = (string)args[2]; List <IMyProgrammableBlock> blocks = new List <IMyProgrammableBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); foreach (var block in blocks) { block.TryRun(argument); } }
// static blocks internal static void Test1(IList args, IMethodContext context) { ImplLogger.LogImpl("test1", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; List <IMyTextSurfaceProvider> blocks = new List <IMyTextSurfaceProvider>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); Log.Write("TypeName/SubtypeName \"Name\" [IntityId]"); Log.WriteLine(); foreach (var lcd in blocks) { var block = lcd as IMyTerminalBlock; Log.Write($"{block.GetType().Name}/{block.BlockDefinition.SubtypeName} \"{block.CustomName}\" [{block.EntityId}]"); Log.WriteFormat("surfaces count: {0}", lcd.SurfaceCount); } }
public static void Text(IList args, IMethodContext context) { ImplLogger.LogImpl("text", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; int index = (int)(double)args[2]; bool append = (bool)args[3]; string text = (string)args[4]; var blocks = new List <IMyTextSurfaceProvider>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); foreach (var block in blocks) { IMyTextSurface surface; if (block is IMyTextPanel && index == 0) { surface = block as IMyTextSurface; } else { surface = block.GetSurface(index); } if (surface != null) { surface?.WriteText(text, append); } else { Log.Write(ImplLogger.LOG_CAT, LogLevel.Verbose, "surface index out of range"); } } }
public static void Transmit(IList args, IMethodContext context) { ImplLogger.LogImpl("transmit", args); MatchingType matchingType = (MatchingType)args[0]; string filter = (string)args[1]; string targetString = (string)args[2]; string message = (string)args[3]; List <IMyTerminalBlock> antennas = new List <IMyTerminalBlock>(); List <IMyRadioAntenna> radioAntennas = new List <IMyRadioAntenna>(); BlockSelector.GetBlocksOfTypeWithQuery(matchingType, filter, radioAntennas); ImplLogger.LogBlocks(antennas); //get most powerful radio antenna IMyRadioAntenna mostPowerfulAntenna = null; //get radio antenna with longest radius that's enabled and broadcasting foreach (IMyRadioAntenna antenna in radioAntennas) { if (antenna.Enabled && antenna.GetValueBool("EnableBroadCast") && (mostPowerfulAntenna == null || antenna.Radius > mostPowerfulAntenna.Radius)) { mostPowerfulAntenna = antenna; } } if (mostPowerfulAntenna != null) { antennas.Add(mostPowerfulAntenna); } //--------get all laser antennas List <IMyLaserAntenna> laserAntennas = new List <IMyLaserAntenna>(); BlockSelector.GetBlocksOfTypeWithQuery(matchingType, filter, laserAntennas); Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Verbose, "{0} block(s) found", laserAntennas.Count); foreach (IMyLaserAntenna antenna in laserAntennas) { if (antenna.Status == MyLaserAntennaStatus.Connected) { antennas.Add(antenna); } } //-----check whether at least one valid antenna was found if (antennas.Count != 0) { var transmitter = new Transmitter(antennas); transmitter.Transmit(message, targetString); } else { string warning; switch (matchingType) { default: case MatchingType.Match: warning = string.Format("No antennas called \"{0}\" are currently able to transmit.", filter); break; case MatchingType.Contains: warning = string.Format("No antennas containing \"{0}\" are currently able to transmit.", filter); break; case MatchingType.Head: warning = string.Format("No antennas starting with \"{0}\" are currently able to transmit.", filter); break; case MatchingType.Group: warning = string.Format("No antennas in group \"{0}\" are currently able to transmit.", filter); break; case MatchingType.Type: warning = string.Format("No antennas of type \"{0}\" are currently able to transmit.", filter); break; } Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, warning); } }
public static void Set(IList args, IMethodContext context) { ImplLogger.LogImpl("set", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; string prop = (string)args[2]; string value = (string)args[3]; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); // Boolean // StringBuilder // Single // Int64 // Color foreach (var block in blocks) { // todo: redo var propDef = block.GetProperty(prop); PropType propType; if (propDef != null && Enum.TryParse(propDef.TypeName, out propType)) { switch (propType) { case PropType.Boolean: { bool b; if (bool.TryParse(value, out b)) { block.SetValue(prop, b); } break; } case PropType.StringBuilder: { block.SetValue(prop, new StringBuilder(value)); break; } case PropType.String: { block.SetValue(prop, value); break; } case PropType.Single: { float s; if (float.TryParse(value, System.Globalization.NumberStyles.Number, C.I, out s)) { block.SetValue(prop, s); } } break; case PropType.Int64: { long i; if (ListConverter.ResolveListProperty(prop, value, out i)) { block.SetValue(prop, i); } } break; case PropType.Color: { Color c; if (ColorConverter.TryParseColor(value, out c)) { block.SetValueColor(prop, c); } else { Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, "\"{0}\" is not a valid color", value); } } break; } } else { Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, "block \"{0}\" does not have property \"{1}\", ignoring", block.CustomName, prop); } } }
internal static void ListProps(IList args, IMethodContext context) { ImplLogger.LogImpl("listprops", args); MatchingType type = (MatchingType)args[0]; string filter = (string)args[1]; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); BlockSelector.GetBlocksOfTypeWithQuery(type, filter, blocks); ImplLogger.LogBlocks(blocks); List <ITerminalProperty> props = new List <ITerminalProperty>(); foreach (var block in blocks) { Log.WriteFormat("Block \"{0}\" of type \"{1}\" contains properties:", new object[] { block.CustomName, block.GetType().Name }); props.Clear(); block.GetProperties(props); var allProps = new HashSet <string>(); var badProps = new HashSet <string>(); // Termimal Properties can have same ids, which makes them unaccessible foreach (var prop in props) { if (allProps.Contains(prop.Id)) { badProps.Add(prop.Id); } else { allProps.Add(prop.Id); } } foreach (var prop in props) { // block.GetValue<object>(prop.Id) - Property is not of Type object <...> object value = null; try { PropType propType; if (!badProps.Contains(prop.Id) && Enum.TryParse(prop.TypeName, out propType)) { switch (propType) { case PropType.Boolean: value = block.GetValueBool(prop.Id); break; case PropType.Single: value = block.GetValueFloat(prop.Id); break; case PropType.Color: value = block.GetValueColor(prop.Id); break; case PropType.StringBuilder: value = block.GetValue <StringBuilder>(prop.Id); break; case PropType.String: value = block.GetValue <string>(prop.Id); break; case PropType.Int64: value = block.GetValue <long>(prop.Id); break; } } } catch { // Looks like some game mod is broken, which is bad. Game breaking bad. Log.WriteFormat(ImplLogger.LOG_CAT, LogLevel.Warning, $"Error reading property \"{prop.Id}\""); } Log.WriteFormat("\"{0}\" ({1}) = \"{2}\"", new object[] { prop.Id, prop.TypeName, value }); } Log.WriteLine(); } }