Пример #1
4
    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();
    }
Пример #2
0
 public EasyMessage(EasyBlock From, String Subject, String Message)
 {
     this.From      = From;
     this.Subject   = Subject;
     this.Message   = Message;
     this.Timestamp = DateTime.Now.Ticks;
 }
Пример #3
0
 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;
 }
Пример #4
0
 public EasyMessage(EasyBlock From, String Subject, String Message)
 {
     this.From = From;
     this.Subject = Subject;
     this.Message = Message;
     this.Timestamp = DateTime.Now.Ticks;
 }
    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);
    }
Пример #6
0
 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;
 }
Пример #7
0
    public EasyBlocks Minus(EasyBlock Block)
    {
        List <EasyBlock> FilteredList = new List <EasyBlock>();

        FilteredList.AddRange(this.Blocks);
        FilteredList.Remove(Block);

        return(new EasyBlocks(FilteredList));
    }
Пример #8
0
    // 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);
        }
    }
Пример #9
0
    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();
        });
    }
Пример #10
0
    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));
    }
Пример #11
0
    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");
        });
    }
Пример #12
0
    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
    }
Пример #13
0
    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();
    }
Пример #14
0
    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();
    }
Пример #15
0
    /*** 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();
    }
Пример #16
0
 // 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])));
 }
Пример #17
0
    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.
    }
Пример #18
0
    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]));
                }
            }
        }
    }
Пример #19
0
    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
    }
Пример #20
0
    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
    }
Пример #21
0
    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.
    }
Пример #22
0
    // 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])));
    }
Пример #23
0
    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);
    }
Пример #24
0
 public void AddEvent(EasyBlock block, Func<EasyBlock, bool> evnt, Func<EasyBlock, bool> action)
 {
     this.AddEvent(new EasyEvent<EasyBlock>(block, evnt, action));
 }
Пример #25
0
    public bool doorOpened(EasyBlock door)
    {
        // Do something when door is opened

        return(true);
    }
Пример #26
0
    public string doorStatus(EasyMenuItem item)
    {
        EasyBlock door = Blocks.Named(item.Text).GetBlock(0);

        return(item.Text + ": " + ((door.Open())?"Open":"Closed"));
    }
Пример #27
0
    public EasyBlocks Add(EasyBlock Block)
    {
        this.Blocks.Add(Block);

        return(this);
    }
Пример #28
0
 public void AddEvent(EasyBlock block, Func <EasyBlock, bool> evnt, Func <EasyBlock, bool> action, bool onChange = false)
 {
     this.AddEvent(new EasyEvent(block, evnt, action, onChange));
 }
Пример #29
0
    public bool doorClosed(EasyBlock door)
    {
        // Do something when door is closed

        return(true);
    }