public EasyLCD(EasyBlocks block, double scale = 1.0) { this.block = block.GetBlock(0); if(this.block.Type() == "Wide LCD panel") this.wPanel = 72; this.screen = (IMyTextPanel)(block.GetBlock(0).Block); this.fontSize = block.GetProperty<Single>("FontSize"); this.width = (int)((double)this.wPanel / this.fontSize); this.height = (int)((double)this.hPanel / this.fontSize); this.buffer = new char[this.width * this.height]; this.clear(); this.update(); }
public EasyMessage(EasyBlock From, String Subject, String Message) { this.From = From; this.Subject = Subject; this.Message = Message; this.Timestamp = DateTime.Now.Ticks; }
public EasyEvent(EasyBlock block, Func <EasyBlock, bool> op, Func <EasyBlock, bool> callback, bool onChange = false) { this.op = op; this.callback = callback; this.block = block; this.onChange = onChange; }
protected GameObject CreateBlock(EasyBlock easyBlock, Transform parent) { var block = new GameObject(easyBlock.name); block.transform.SetParent(parent); blockDict.Add(block, new Dictionary <GameObject, List <IEntity> >()); foreach (var kvp in easyBlock.ToDictionary()) { var entity = PoolFactory.Spawn(kvp.Value.GameObject); var viewComponent = entity.GetComponent <ViewComponent>(); viewComponent.Transforms[0].SetParent(block.transform, false); viewComponent.Transforms[0].localPosition = kvp.Value.LocalPosition; viewComponent.Transforms[0].localRotation = kvp.Value.LocalRotation; viewComponent.Transforms[0].localScale = kvp.Value.LocalScale; if (!blockDict[block].ContainsKey(kvp.Value.GameObject)) { blockDict[block].Add(kvp.Value.GameObject, new List <IEntity>()); } blockDict[block][kvp.Value.GameObject].Add(entity); } return(block); }
public EasyItem(EasyBlock Block, int InventoryIndex, IMyInventory Inventory, int ItemIndex, IMyInventoryItem Item) { this.Block = Block; this.InventoryIndex = InventoryIndex; this.Inventory = Inventory; this.ItemIndex = ItemIndex; this.Item = Item; }
public EasyBlocks Minus(EasyBlock Block) { List <EasyBlock> FilteredList = new List <EasyBlock>(); FilteredList.AddRange(this.Blocks); FilteredList.Remove(Block); return(new EasyBlocks(FilteredList)); }
// Constructor with IMyTerminalBlock list public EasyBlocks(List <IMyTerminalBlock> TBlocks) { this.Blocks = new List <EasyBlock>(); for (int i = 0; i < TBlocks.Count; i++) { EasyBlock Block = new EasyBlock(TBlocks[i]); this.Blocks.Add(Block); } }
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { var children = new List <EasyMenuItem>(); children.Clear(); foreach (var title in menuItems.Keys) { children.Add(new EasyMenuItem(title, delegate(EasyMenuItem menuItem) { menuItem.children.Clear(); menuItem.children.Add(new EasyMenuItem("hidden")); this.inCAL = true; this.calCommand = menuItems[menuItem.GetText()]; return(true); })); } // Create menu this.menu = new EasyMenu(menuTitle, children.ToArray()); this.lcd = Blocks.Named(lcdBlockName).FindOrFail("Menu LCD not found!").GetBlock(0); this.cal = Blocks.Named(calBlockName).FindOrFail("CAL Programmable block not found!").GetBlock(0); lcd.WritePublicTitle(""); // Handle Arguments On("Up", delegate() { this.menu.Up(); doUpdates(); }); On("Down", delegate() { this.menu.Down(); doUpdates(); }); On("Choose", delegate() { this.menu.Choose(); doUpdates(); }); On("Back", delegate() { this.menu.Back(); this.inCAL = false; doUpdates(); }); Every(100 * EasyAPI.Milliseconds, delegate() { doUpdates(); }); }
public EasyBlocks Plus(EasyBlock Block) { List <EasyBlock> FilteredList = new List <EasyBlock>(); FilteredList.AddRange(this.Blocks); if (!FilteredList.Contains(Block)) { FilteredList.Add(Block); } return(new EasyBlocks(FilteredList)); }
public AttackDetector(StorageSetter storage, IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { ammo = VRage.MyFixedPoint.DeserializeStringSafe(storage.getStorage()); turrets = Blocks.InGroupsNamed("Turrets"); log = new EasyLCD(Blocks.Named("LCD Panel Attacks Log")); beacon = Blocks.InGroupsNamed("Beacon Attack Detector").GetBlock(0); this.storage = storage; Every(5 * EasyAPI.Seconds, doWork); On("clear", delegate() { log.SetText(""); beacon.SetName("Beacon Attack Detector"); }); }
public bool toggleDoor(EasyMenuItem item) { EasyBlock door = Blocks.Named(item.Text).FindOrFail(item.Text + " not found!").GetBlock(0); if (door.Open()) { door.ApplyAction("Open_Off"); } else { door.ApplyAction("Open_On"); } return(false); // don't go to a sub-menu if one is available }
public EasyLCD(EasyBlocks block, double scale = 1.0) { this.block = block.GetBlock(0); if (this.block.Type() == "Wide LCD panel") { this.wPanel = 72; } this.screen = (IMyTextPanel)(block.GetBlock(0).Block); this.fontSize = block.GetProperty <Single>("FontSize"); this.width = (int)((double)this.wPanel / this.fontSize); this.height = (int)((double)this.hPanel / this.fontSize); this.buffer = new char[this.width * this.height]; this.clear(); this.update(); }
private long start = 0; // Time at start of program #endregion Fields #region Constructors /*** Constructor ***/ public EasyAPI(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) { this.clock = this.start = DateTime.Now.Ticks; this.delta = 0; this.GridTerminalSystem = EasyAPI.grid = grid; this.Echo = echo; this.ElapsedTime = elapsedTime; this.ArgumentActions = new Dictionary<string,List<Action>>(); this.Events = new List<IEasyEvent>(); this.Schedule = new List<EasyInterval>(); this.Intervals = new List<EasyInterval>(); // Get the Programmable Block that is running this script (thanks to LordDevious and LukeStrike) this.Self = new EasyBlock(me); this.Reset(); }
/*** Constructor ***/ public EasyAPI(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action <string> echo, TimeSpan elapsedTime, string commandArgument = "EasyCommand") { this.clock = this.start = DateTime.Now.Ticks; this.delta = 0; this.GridTerminalSystem = EasyAPI.grid = grid; this.Echo = echo; this.ElapsedTime = elapsedTime; this.ArgumentActions = new Dictionary <string, List <Action> >(); this.CommandActions = new Dictionary <string, List <Action <int, string[]> > >(); this.Schedule = new List <EasyInterval>(); this.Intervals = new List <EasyInterval>(); this.commands = new EasyCommands(this); // Get the Programmable Block that is running this script (thanks to LordDevious and LukeStrike) this.Self = new EasyBlock(me); this.Reset(); }
// unserialize public EasyMessage(String serialized) { var parts = serialized.Split(':'); if(parts.Length < 4) { throw new Exception("Error unserializing message."); } int numberInGrid = Convert.ToInt32(System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[0]))); var blocks = new List<IMyTerminalBlock>(); EasyAPI.grid.GetBlocksOfType<IMyProgrammableBlock>(blocks, delegate(IMyTerminalBlock block) { return (block as IMyProgrammableBlock).NumberInGrid == numberInGrid; }); if(blocks.Count == 0) { throw new Exception("Message sender no longer exits!"); } this.From = new EasyBlock((IMyTerminalBlock)blocks[0]); this.Subject = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[1])); this.Message = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[2])); this.Timestamp = Convert.ToInt64(System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[3]))); }
public bool notDamaged1Percent(EasyBlock b) { // Get parameters from the name (separated by '[' and ']') var parameters = b.NameParameters('[', ']'); // Open doors specified in parameters for (int i = 0; i < parameters.Count; i++) { Blocks.Named(parameters[i]).ApplyAction("Open_On"); } // Add back the original event to close doors on damage. AddEvent( b, // add it to this block delegate(EasyBlock block) { return(block.Damage() > 1); }, damaged1Percent ); return(false); // Remove the event once it is triggered. }
public EasyInventory(List <EasyBlock> Blocks) { this.Items = new List <EasyItem>(); // Get contents of all inventories in list and add them to EasyItems list. for (int i = 0; i < Blocks.Count; i++) { EasyBlock Block = Blocks[i]; for (int j = 0; j < Block.Block.GetInventoryCount(); j++) { IMyInventory Inventory = Block.Block.GetInventory(j); List <IMyInventoryItem> Items = Inventory.GetItems(); for (int k = 0; k < Items.Count; k++) { this.Items.Add(new EasyItem(Block, j, Inventory, k, Items[k])); } } } }
public bool damaged1Percent(EasyBlock b) { // Get parameters from the name (separated by '[' and ']') var parameters = b.NameParameters('[', ']'); // Close doors specified in parameters for(int i = 0; i < parameters.Count; i++) { Blocks.Named(parameters[i]).ApplyAction("Open_Off"); } // Add event when the damage is repaired so we can reopen the doors AddEvent( b, // add it to this block delegate(EasyBlock block) { return block.Damage() < 1; }, notDamaged1Percent ); return false; // Remove the event once it is triggered }
public bool damaged1Percent(EasyBlock b) { // Get parameters from the name (separated by '[' and ']') var parameters = b.NameParameters('[', ']'); // Close doors specified in parameters for (int i = 0; i < parameters.Count; i++) { Blocks.Named(parameters[i]).ApplyAction("Open_Off"); } // Add event when the damage is repaired so we can reopen the doors AddEvent( b, // add it to this block delegate(EasyBlock block) { return(block.Damage() < 1); }, notDamaged1Percent ); return(false); // Remove the event once it is triggered }
public bool notDamaged1Percent(EasyBlock b) { // Get parameters from the name (separated by '[' and ']') var parameters = b.NameParameters('[', ']'); // Open doors specified in parameters for(int i = 0; i < parameters.Count; i++) { Blocks.Named(parameters[i]).ApplyAction("Open_On"); } // Add back the original event to close doors on damage. AddEvent( b, // add it to this block delegate(EasyBlock block) { return block.Damage() > 1; }, damaged1Percent ); return false; // Remove the event once it is triggered. }
// unserialize public EasyMessage(String serialized) { var parts = serialized.Split(':'); if (parts.Length < 4) { throw new Exception("Error unserializing message."); } int numberInGrid = Convert.ToInt32(System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[0]))); var blocks = new List <IMyTerminalBlock>(); EasyAPI.grid.GetBlocksOfType <IMyProgrammableBlock>(blocks, delegate(IMyTerminalBlock block) { return((block as IMyProgrammableBlock).NumberInGrid == numberInGrid); }); if (blocks.Count == 0) { throw new Exception("Message sender no longer exits!"); } this.From = new EasyBlock((IMyTerminalBlock)blocks[0]); this.Subject = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[1])); this.Message = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[2])); this.Timestamp = Convert.ToInt64(System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(parts[3]))); }
protected GameObject AllocBlock(EasyBlock easyBlock, Transform parent) { var block = new GameObject(easyBlock.name); block.transform.SetParent(parent); AllocedPrefabs.Add(block, new Dictionary <GameObject, List <GameObject> >()); foreach (var kvp in easyBlock.ToDictionary()) { var go = PoolSystem.Alloc(kvp.Value.GameObject, transform); go.transform.SetParent(block.transform, false); go.transform.localPosition = kvp.Value.LocalPosition; go.transform.localRotation = kvp.Value.LocalRotation; go.transform.localScale = kvp.Value.LocalScale; if (!AllocedPrefabs[block].ContainsKey(kvp.Value.GameObject)) { AllocedPrefabs[block].Add(kvp.Value.GameObject, new List <GameObject>()); } AllocedPrefabs[block][kvp.Value.GameObject].Add(go); } return(block); }
public void AddEvent(EasyBlock block, Func<EasyBlock, bool> evnt, Func<EasyBlock, bool> action) { this.AddEvent(new EasyEvent<EasyBlock>(block, evnt, action)); }
public bool doorOpened(EasyBlock door) { // Do something when door is opened return(true); }
public string doorStatus(EasyMenuItem item) { EasyBlock door = Blocks.Named(item.Text).GetBlock(0); return(item.Text + ": " + ((door.Open())?"Open":"Closed")); }
public EasyBlocks Add(EasyBlock Block) { this.Blocks.Add(Block); return(this); }
public void AddEvent(EasyBlock block, Func <EasyBlock, bool> evnt, Func <EasyBlock, bool> action, bool onChange = false) { this.AddEvent(new EasyEvent(block, evnt, action, onChange)); }
public bool doorClosed(EasyBlock door) { // Do something when door is closed return(true); }